Fall 2005, David Matuszek
Each player (the human and the computer) is given a hand of N cards, numbered 1 through N. (N is a fairly small number, say 10 or 13.) At each turn, each player chooses and plays one card from their hand. The player who plays the higher-numbered card takes both cards and adds them to their "captured" pile. In the event of a tie, each player retrieves their own card and places it in their captured pile. Play continues for N turns, that is, until all cards have been used.
At the end of the game, each player totals the cards that have been captured. The player with the higher point count wins. (As a betting game, the winning player collects the difference in their totals from the loser.)
You should keep two arrays for the computer, and two for the human. One array, the "hand," contains all the unplayed cards; the other, the "captured pile," contains the cards won during play.
Initially, each player's hand contains N cards, numbered 1 through N. Unlike
some card games, there is no randomness involved; players always start with
the same hand. If, for example,
1 2 3 4 5 6 7 8 9 10
There is no way to win a turn with the
1 card; at best, it will
be a tie. Similarly, there is no way to lose when playing the highest card (
in this example).
At each turn, the two players play "simultaneously," so that neither know what card the other will play. In practice, of course, the human has to choose a card, and trust the computer to be honest and choose a card without "peeking." Your program should play honestly.
The computer player can play randomly, or you can try to give it some more sophisticated strategy.
Since the game is part of an HTML page, you can easily include some instructions on how to play the game. This might include some hints on how to use your GUI, but remember that no amount of explanation makes up for a confusing design.
At the end of each game, display some simple statistics, such as: The number of games played, the number of games won or lost, the total number of points won or lost.