
It also includes different representations of Peg Solitaire other than the "Cracker Barrel" design. This source offers background information on several different techniques in solving Peg Solitaire.
#Peg solitaire solving java how to
The Board can be represented as a tree in order to implement how to traverse it.ĭepth First Search Algorithm DepthFirstSearch(Board b, Peg start)

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. Peg Board The simplest peg solitaire design is the triangular peg board, often referred to as the “Cracker Barrel” design.

#Peg solitaire solving java code
If you wish - use it, with mouse-only, keyboard-only or a combination thereof, as is, no warranties, source code available upon request.

(full disclosure: a C programmer, I have put together (and used) a Java program that does not search for a possible solution computationally but, rather, emulates a physical game and automatically records the moves made by a human: Ītomic jumps may be strung together into contiguous chains (which, imho, should not reduce the number of moves). Further, if a peg in cell 10 is chosen as a jumping peg then it must jump over a peg in cell 17 and it must land in cell 24 - it can not land in cell 29 despite the fact that that cell is empty. If '29 to 17' move was made then the peg in cell 24 is removed from the board and cells 29 and 24 become empty. Sample: initially, possible moves are: 5 to 17, 19 to 17, 29 to 17, 15 to 17. R4) a game terminates when no more legal moves are left - there does not exist a single triplet of cells with the properties described in r2 a peg that was jumped over, in cell B, is removed from the board be carried over a middle peg, in B, and in either case, only a peg in a peripheral cell, A or C, may jump and it must: R2) a jump is possible iff A, B and C are three adjacent cells in a column or row with either empty C and occupied A and B or empty A and occupied B and C (depicted): R1) one atomic move must be one legal jump The classical objective of this game is to leave exactly one peg on the board in dead center in the smallest number of moves each of which must follow these 'rectilinear checkers'-like rules: In a classical scenario, each cell but exactly one - in dead center - (cell 17), initially, has one peg (coin/marble/pebble/etc) in it: The board of this game, favored by Gottfried Leibniz (the co-inventor of D&I Calculus), consists of 33 cells.

RIDDLES SITE WRITE MATH! Home Help Search Members Login RegisterĮasy (Moderators: towr, Grimbal, Icarus, ThudnBlunder, william wu, SMQ, Eigenray)
