In plain language, write out the steps you'll need to take in order to achieve your goal. It isn't necessary to document each tiny programming step, but you will want to map out the important things you'll need to do in order to accomplish your goal.
When you're finished writing the pseudo code, you'll fill in the blanks with programming statements, and you'll have documented code. Each line of pseudo code will become a comment line.
Problem Statement - given:
Eight Off is a solitaire game played with a standard deck of 52 cards:
13 values (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King) for
each of the 4 suits (Clubs, Diamonds, Hearts, Spades).
There are three different kinds of places where cards can be:
8 Columns
8 Reserves
4 Foundations
Eric's Ultimate Solitaire Sampler tersely explains the game thusly:
Object: Build the Foundations up and in suit, from Ace to King.
Build Columns down and in suit. You can play the top card in any
Column or the Reserve to a Foundation, Column, or Reserve. Empty
Columns may be filled with any card.
You can have up to 8 cards in the Reserve.
----------------
Below is pseudo-code for this game program. This pseudo-code is
rather
detailed - more detailed than needed in many situations.
----------------
play the game (main method):
set up the game
while game has not been won
print the game state then prompt user for a move
read int src, read int dst, and prepare for and move a card
from src to dst
print an announcement that the game was won
set up the game:
create Deck arrays foundation[0..3], reserve[1..8], and
column[1..8]
(reserve[], column[] start at 0, but ignore that position)
loop over every element of arrays foundation[], reserve[], and
column[]
set array-element to new Deck(false) - ie. create an empty
Deck
create a new, full 52-card deck d and scramble the cards in d
repeat 6 times: for each column c, deal top card from d to c
for each of the first 4 reserves r, deal top card from d to r
test if the game has been won:
initialize count to 0
for each foundation f, add f.size to count
test count == 52
print the game status (foundations, reserves, columns) horizontally:
print "Foundations (0) "
for each foundation f
if f is empty then print "---- "
otherwise print top card of f and two spaces
println two blank lines, then println "Reserves | Columns:"
for each i from 1 to 8
println "(-i): ", reserve[i], " | (i): ", column[i]
(hint: use method Deck.toString())
prepare for the move from src to dst:
declare s and d to be Decks, initially set to null
verify src, dst are in the range -8..8 and that src is non-zero
if src > 0 then set s to Deck column[src]
if src < 0 then set s to Deck reserve[-src]
set d according to dst similarly (and if d is reserve, verify it
is empty)
move 1 card from Deck s to Deck d
move 1 card from Deck src to Deck dst:
verify that src.size > 0
set Card c to top card of src
if dst is null, then
set dst to foundation[c.suit]
verify that c.value == dst.size+1 (foundations build up)
otherwise
if dst.size > 0 then
set card d to top card of dst
verify that c, d have the same suit
verify that the value of c is one less than value
of d
deal top card from src to dst