Before you tackle the homework, remind yourself of our General Advice, Advice on Homeworks, and Grading Guidelines. Above all, keep your work neat and honest.
Due Date: December 8, 1999
Background Solitaire is a board game for individuals. The board comes in various shapes. Here is the simplest one:
o o o o x o o o o o
The red x represents an unoccupied
os are little pegs sticking
in holes; and
= stands for the
The goal of the game is to eliminate the pegs one by one until only one peg is left. A player can eliminate a peg if it one of the neighboring holes is unoccupied and if there is a peg in the hole in the opposite direction. In that case, the second peg can jump over the first one and the first one is eliminated.
For example, on the above board, no peg can be eliminated. But, if the initial hole is on the side like this:
o o o o o x o o o othen the blue and the cyan peg could jump. If the player decides to move the blue one, the next configuration is
x o x o o o o o o o
Problem: Develop a program that solves a Solitaire problem for different sizes of the equilateral triangle. You may choose to specify the input as the number of rows, e.g., 4, or as a list of lists of symbols, e.g.,
'((o = = =) = <=> WOOD (o x = =) o <=> PEG (o o o =) x <=> HOLE (o o o o))You must specify your choice.
The hole should always be placed at the right-most position in the second row. (If you care, you may wish to modify this choice for your own curiosity.)
solitaire should return false, if the given
problem is not solvable. Otherwise, it should produce a list of moves that
specifies in what order the pegs must be moved to solve the given
Solitaire problem. Again, you must choose a representation for moves.
Structures are a good choice.
Design Review: Your team must have a design review with a labby by Sunday, December 5. For the design review, you must turn in
Product: You must turn in the following:
Sample Solution: One sample solution (something that resembles what you should turn in) is around 240 lines long. With an additional 70 lines, the developer of this assignment produced a graphical user interface that allows the user to pick the initial hole and shows the solution on-screen (based on draw-lib.ss):
There is a clever solution that is just under 190l lines.
Challenge: Modify the program so that it solves Solitaire for a different shape, e.g.,
= = o o o = = = = o o o = = o o o o o o o o o o x o o o o o o o o o o = = o o o = = = = o o o = =This problem is also well-known and more difficult than the triangle version.
You should modify your program so it computes two variants of the solution. In the first, pegs can jump in all possible directions: vertical, horizontal, and diagonal. In the second, pegs can jump only in the vertical and horizontal direction. The difference consists of five lines of code.
Warning: A straightforward adaptation of the triangle-shape program requires around four hours on a 166Mz, Linux laptop for the first problem, and an overnight run for the second one.
The challenge carries no credit.
|Matthias Felleisen, modified by Kathi Fisler||Last modified at|