The source point should have a peg ( i.e. The source should be exactly two hops away from the destination.(Eg: (3,3) to (5,3) is valid but (4,4) to (7,4) isnt). The source and destination points should lie on a line (Eg: source: (3,3) & destination (3,5) lie on the same line but source: (4,4) & destination: (5,5) dont). The element specified by the X-Y coordinates should not contain a 'Z'. Both the X coordinate and the Y coordinate should be between 0 and 8.Ģ. The source and destination points should lie on the ACTUAL Solitaire board. In this project, you need to do the following error checking each time the user input's the coordinates: Exiting the game." and then end the game. If no further moves are possible, you should print "User loses the game. If you have reached the winning combination, you should print "User wins the game. The latter case occurs when you have no two pegs adjacent to each other or when there is no hole for a peg to jump to).
Peg solitaire java code code#
Now the user enters the coordinates again and this goes on till you reach the winning configuration or when your code detects that no further moves are possible. After this is done, you should print exactly 5 blank lines and then re-display the board after making the changes caused by the user's last move. However, what you should display on the console as the initial setup should resemble the figure shown on the left :Īnd when the board reaches the combination displayed on the right, the player wins and the game ends.ĭon't worry, the aim of this project is not to find a set of moves that wins you the game !! What is required is that after you display the initial board setup, the user should enter the X and Y coordinates (which are equivalent to their indices in the 2D array) of the peg which he/she wants to move and also the coordinates of the position where the user wants to move the peg to. The array should be initialized to look like this.
Enter the cd cs177 command to go to your.In your console or terminal window enter theĬd command to ensure that you are in your home.Course Materialīefore you start this project, you must understand: To get a feel of the game before you begin coding for this project, you are welcome to play the game online using the following link. Thus valid moves in each of the four orthogonal directions are: A green ¤ is the hole the current peg moved from a red * is the final position of that peg and a red o is the hole of the peg that was jumped and removed. In the diagrams which follow, a green * indicates the peg that is chosen to be moved and a green * indicates any other peg in a hole and a green o indicates an empty hole. In this project, we would be focussing on an updated implementation of the English version of this game, which is displayed in the right hand side figure above.Ī valid move is to jump a peg horizontally or vertically over an adjacent peg into a hole two positions away and then to remove the jumped peg. There are two traditional boards, graphically depicted as follows ('.' as an initial peg, 'o' as an initial hole): The objective is, making valid moves, to empty the entire board except for a solitary peg in the central hole. The standard game fills the entire board with pegs except for the central hole. It is also referred to as Brainvita (especially in India), while one popular commercial version is also used generically, Hi-Q. The game is known simply as Solitaire in the United Kingdom where the card games are called Patience. Peg Solitaire is a board game for one player involving movement of pegs on a board with holes.Some sets use marbles in a board with indentations. Final Project Implementation and Turnin.Divide and Conquer - Turning in a MileStone.Brainvita) This is a team project to be done in groups of 3-4 Milestone Due Thursday, March 4th, 9:00 pm Final Project Due Thursday, March 11th, 9:00 pm TA: Mohammad Kaziįor this project you will develop a simplified version of the Peg Solitaire game using your knowledge of arrays, loops and conditional statements. Project 3 - Peg Solitaire Project 3: Peg Solitaire (a.k.a.