import java.util.Collection; import java.util.*; /** A board is a collection of piles in Bulgarian Solitaire. * @author jdalbey * @version 2014.5.8 */ public final class Board { /** The Board is a collection of piles (integers) */ private Collection board; /** Generate a random initial configuration. */ public Board() { /* randomly divide up the deck into piles */ // create board as ArrayList // set numCards to 45 // WHILE numCards greater than zero LOOP // select a random number between 1 and numCards // add number to board // decrement numCards by number // END LOOP } } /** Accessor to a copy of the board. * @return copy of board */ List getBoard() { // return new ArrayList(board); return null; } /** Setup a desired preset initial configuration. * @param initialConfig the desired initial collection of piles * to start the game. A String of blank-delimited numbers * representing the piles, e.,g "2 2 4 5 6 7 8 9" * (Precondition: the numbers must total 45.) * (Precondition: the numbers are all positive.) * (Postcondition: the board is set with the given piles) */ public void setBoard(String initialConfig) { // Create an array of strings from initialConfig // clear the current board // FOR each number in array of Strings LOOP // Convert string to integer // Add integer to board // END LOOP } /** Perform the "solitaire step" to determine the next configuration. * Apply the rules of the game to transform the current board * into the next configuration. Specifically, take one card from each pile, * forming a new pile with these cards. */ public void playRound() { // Declare next as ArrayList to hold the next board // numPiles = size of board // FOR each item in board LOOP // remove item from board // decrement item by one // IF item > 0 THEN // add it to next // END IF // END LOOP // make board refer to next // add numPiles to board } /** Report if the board is in the winning configuration or not. * @return true if the board has piles of size 1, 2, 3, 4, 5, 6, 7, 8, and 9, * in some order; false, otherwise. */ public boolean isWin() { // SET result = true // IF there's not 9 piles on the board THEN // result = false // ELSE // FOR count=1 to 9 LOOP // IF board doesn't contains a pile with count items THEN // result = false; // END IF // END LOOP // END IF // RETURN result return false; } /** Return a printable representation of this board. * @return a printable representation of this board. */ @Override public String toString() { // SET result = board.toString() // Remove brackets and replace commas with blanks in result // RETURN result return ""; } } /** Game is a game of Bulgarian Solitaire. * @author jdalbey * @version 2014.5.9 */ public final class Game { /** The board used by this game */ private Board board; /** The number of rounds played so far */ private int rounds; /** Construct a game with a random board. */ public Game() { // Construct a random board // set rounds to zero } /** Construct a game and initialize the board. * @param initialConfig the desired initial collection of piles * to start the game. A String of blank-delimited numbers * representing the piles, e.,g "2 2 4 5 6 7 8 9" * (Precondition: the numbers must total 45.) * (Precondition: the numbers are all positive.) * (Postcondition: board is built with initial config if provided) */ public Game(String initialConfig) { // Construct a board from initialConfig // set rounds to zero } /** Performs rounds until the game is over. */ public void run() { // WHILE board is not a win LOOP // play a round, increment number of rounds // print the board // END LOOP // PRINT end game message with number of rounds } /** Accessor to number of rounds */ public int getRounds() { return rounds; } } /** * Bulgarian Solitaire Simulation, from Horstmann's Big Java. * * @author jdalbey * @version 2014.5.9 */ public class Solitaire { /** * Entry point for the application. * * @param args the desired initial collection of piles * to start the game. An array of numbers * representing the piles, e.,g "2 2 4 5 6 7 8 9" * For correct results, the numbers must total 45, * the numbers are all positive. */ public static void main(String[] args) { // IF there are no args THEN // Construct a game // ELSE // Construct a game from args // END IF // Run the game } }