The above should give you some hints that will help you get started. You can't jump from "just anywhere" to anywhere, over any peg you wish - the three holes have to be next to each other and in line. And to make valid moves.įor this "game," you may want to search the whole space of possible moves, so you'll probably want to either have each move produce a new board, or to have a way to "undo" moves.Ī valid move is where one peg jumps over another peg, into an empty hole. The quickest solution of Solitaire was found by Ernest Bergholt in 1912 and. Once you have a representation, you need a way to find valid moves. Peg solitaire is a game that, in its commonest form, is played with 32 pegs. That is each "hole" instance could contain pointers to the two or three holes next to it. You might actually want "2D" links, instead of the usual "1D" links. Also consider vertical and diagonal jumps. One can change "OXX" to "XOO" by jumping the 3rd X over the middle one, into the hole. Here's another way to look at it, and possibly consider representing it in memory like this: OXXXXĮach "X" is a peg. Failing that, at least having a picture of the thing will help: The game is known as solitaire in Britain and as peg solitaire in the US where 'solitaire' is now the common name for patience. Some sets use marbles in a board with indentations. To be successful as a programmer, you need to develop the skill of examining a problem, figuring out how it can be solved, and come up with a reasonable in-program representation that enables you to solve it.įor problems like this, I find it helpful to have the puzzle in front of me, so I can try it out by hand. Peg solitaire, Solo Noble or simply Solitaire is a board game for one player involving movement of pegs on a board with holes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |