My home page
Back to my software experience page
Back to my portfolio

This solitaire code was my first substantial effort in Lisp. It is perhaps immature in several ways. The main flaw I see in it now is a lack of a package. I used it in CL-USER.

Rules of Play

To use this, load solitaire.lisp. (start-spider) will deal out a game of Spider solitaire, presenting a text printout of the tableau.

Play by calling (mv pile-from pile-to &optional (num-cards 1)). This attempts to move num-cards cards from the one pile to another. (Piles are referred to by number, starting at 1.)

A legal move in Spider consists of a single card or series of cards in sequence, all of the same suit. The card or cards may only be moved onto an empty tableau or onto a card one higher in rank than the top moved card. Kings are high.

Example moves

When all face-up cards have been moved from a tableau, one face-down card will be turned up.

Call (pr) if you wish to see the current state.

When you build a full straight of a single suit Ace to King, call (clr pile) to clear it from the board. The goal is to clear all the cards in this way.

When you decide further moves are not advantageous, call (dl) to deal ten cards from the reserve deck, one onto each tableau. Cards may not be dealt if any of the tableaux are empty.

Comments

This code works by mutating solitaire-state objects; the utility functions work with one in a convenient global variable *game*.

I had started to work on extending the code to support another game, called Demon. Generally, I get frustrated in what I sense is weak random number generation in solitaire implementations. CMUCL has a pretty good generator. A more interesting next step would be to implement something like general undo and/or a search algorithm to allow the computer to determine if an arrangement of cards can be solved or not. That would allow me to stop using the replay feature on conventional implementations and give up with a clean conscience.