Assignment two further hints

Not too many issues have come up, so I don't have as much to say on this page as I was expecting.

You'll want to look at the questions and answers page, and also there is a correction to the shuffling algorithm (which at this late date you're permitted to take or to leave; that is, the algorithm on the handout is acceptable for this assignment, but you'll find it doesn't do a good shuffle, the probabilities are wrong).


One topic for further algorithmic hints is the issue of repeated "wars". If the two players turn up a matching card and then put down their three hidden cards and then turn up another matching card, this is again a "war". The winner will take all of the cards on the table so far.

This can repeat any number of times, so the logic is a bit complex.

To some this has suggested a recursive algorithm, given the last lecture. This is possible, but might not be the easiest way for you to write it.

A basic loop is just as good. One way to do it is to declare a third array, also of size 52, which holds all the cards on the table. As successive wars occur, add the cards to this array of cards on the table. Then when someone finally wins, transfer all the cards from that array into the winner's hand.

But it should also be possible to do this all in place in the players' hands, since the cards are all stored there. You just have to keep track of what portion of the player's hand's array constitutes cards really still in their hand and which portion constitutes cards on the table.


[main course page]