Example: War

Today's lecture will actually be an extended example: How to implement the card-game "war". We'll go through the whole thing in lecture, starting from "how do we represent the data", and for various functions we'll need to ask, "Do we use the template? An accumulator? Is generative recursion needed?", etc.

No new concepts per se, so you won't need to take notes; you can just concentrate on the tasks in-class. a set of skeleton notes will be helpful, just containing function headers, and blank space for you to write in. You can also print a copy of the entire solution beforehand, but no need to study it closely -- the point of the lecture is, the thought process needed to reach the code.

Finally, there is a solution which is set up to stop a game after 10,000 battles.
Note to prof: In 50min, I got through data representation, nums-upthrough, shuffling [introduce random], and battle. I had to race through the main function itself.

The Rules War is a simple two-player card game with no strategy or decisions involved at all. Start by dealing half the deck to each player, face down. A turn is simple: each player turns over their top card; the player with the higher card wins both cards (putting them back at the bottom of their own stack of cards). In case of a tie, we will flip a coin to determine the winner. (That's our simplification -- see actual rules). A player loses if they have no cards left.

How easy is to to change our code, to some of the alternate rules? (i.e. only use 6-through-Ace, low-rank-beats-Ace(only), settling a tie through another round, etc)