For all solvable problems, we give an explicit solution algorithm. ![]() We develop necessary and sufficient conditions for this game to be solvable. The basic game begins from a full board with one peg missing and finishes with one peg at a specified board location. In this article we consider peg solitaire on a triangular board with nholes on each side. The algorithm worked well before I added seenBoards, but I added this because it was visiting way too many nodes. We consider the one-person game of peg solitaire on a triangular board of arbitrary size. Starting Files: TrianglePegSolitaire.zip PegState.java Pegs.java PegFirstClickState.java PegSecondClickState.java Lab: Interfaces Dynamic Changeability Two-Way Has-A State Design Pattern Part I: Peg State Triangle Peg Solitaire has three distinct states. Game Over: There are no more legal jumps (the game is over). Second Click: A clicked on peg has two possible jumps, so two mouse clicks are required to execute the jump. First Click: A clicked on peg has only one possible jump, so take that jump. Grid is a class variable which is the game grid in its current state. Triangle Peg Solitaire has three distinct states. UndoJump undoes the move on grid directly. Right now, it looks like my algorithm is quitting too fast when it hasn't found a solution yet.Ī solution is found if there is only 1 peg left on the board.īelow is my function findSolution() which is a recursive function.ĭirection contains all the coordinates to move up, down, left and right on the board.ĭoJump makes the move on the board that is in the parameters. Many 'magic numbers' were changed to constants for better readability of the code. ![]() The Board can be represented as a tree in order to implement how to tr. This design is similar to an equilateral triangle where each edge has the same number of pegs, and each row has one more peg than the row above it. There is one location that does not have a peg. Peg Board The simplest peg solitaire design is the triangular peg board, often referred to as the Cracker Barrel design. I am trying to add a Depth First Search in my algorithm to find a solution to the Peg Solitaire game. Many of the changes are related to indices and directions inconsistency across the code: where x represents horizontal index and y represents vertical index: array index should be board y x (and not board x y). Triangle Peg Solitaire is a game where you start with several pegs at fixed locations on a triangular board.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |