Peg Solitaire in Prolog


This is a simple program to solve the "peg solitaire" problem.
The best explanation of the rules is left to a Google search.
The program comes in 2 parts:
(a)
A "general" problem solver. Basically, search for a combination of user-defined "moves" that go from a given start state to any of a user-defined set of goal states. User can define some search heuristics.
(b)
The "solitaire" problem. Define enough of the user_xxx from (a) to solve the problem.
I've used SWI-Prolog to run the example. Given the problem starts off in random positions (one of the rules), most solutions take less than 1 sec on my under-powered laptop.

To use, in SWI-Prolog define a .plrc file containing:

:-
[solver].
:-
[solitaire].
:-
main.
where "solver.pl" is the file containing the solver, "solitaire.pl" contains the problem, and "main" is just an entry point to the solver that will run and print the first solution found. Re-running solves the problem again -- from different starting positions.

You can re-define num_peg(N) in "solitaire.pl" to try bigger or smaller problems, or play with the rules.

Have fun!

"General" problem solver
Peg Solitaire using GPS

Kym Horsell /
Kym@KymHorsell.COM

Modest donations gladly accepted via PayPal.

ADVISORY: Email to these sites is filtered.