Piles Game Demo: Recursive algorithms with Objects in a Collection¶
Instructions: Work through these steps in order.
Download the following files:¶
- Card.java
- CardCollection.java
- Deck.java
- Hand.java
- PileChecker.java
-
to an appropriate directory/folder (e.g., CS159/src/piles). In most browsers/OSs, the easiest way to do this is by right-clicking/control-clicking on each of the links above and then selecting Save as… or Save link as....
1. Background¶
Supporting classes for this lab are from the Think Java textbook by Allen Downey and Chris Mayfield.
You should read through the class descriptions and text for the Card, Hand, Deck, and CardCollection classes starting in chapter 14 of the book to familiarize yourself with these(some of the other classes are developed earlier in the book)
They implement a standard 52 playing card deck. In this deck Aces are rank 1 and other cards ascending from there in numerical order then J, Q, K with rank (11, 12, 13 respectively)
2. Instructions:¶
-
Run PilesGame.java. This game creates a hand of 5 cards from the standard 52 card deck.
-
Work through the logic of the recursive algorithm provided. This is using an Array index style recursion.
-
See if you can create a recursive algorithm using native card / deck class methods instead of the array version using operations like popCard(i) instead of the array based structures.
-
Other things to try:
A. See if you can reverse this to make it ascending instead of descending
B. Super Challenge - change this to allow for either ascending or descending fully to be a valid pile.