APCS: Elevens Project, Activity 11

8 points 

We'll skip Activity 10, which is on modifying our game to play the related game Thirteens.

Activity 11, on pages 37 - 40, is "Simulation of Elevens".
Begin by reading the information on simulation on pages 37 to 39. In this Activity we simulate the playing of many games of Elevens in order to study how often the player wins. Once your code is working, for example, you could have the computer play 1000 games of Elevens in a few seconds, and see how many games the player won.

You will need to create a new folder for this final Activity. Copy all of your .java files for Elevens into the new folder. You'll be making basic changes to the file ElevensBoard.java in order to run simulations. You don't want to overwrite the existing ElevensBoard.java and lose the ability you finalized in Activity 9 to play Elevens interactively. Then create a new project that uses the newly-copied files.

Carry out Exercises 1 - 8, beginning on p. 39.

You'll want to copy these 5 new method signatures into the 'new' ElevensBoard.java:

/* Looks for a legal play on the board. If one is found, it plays it.
* @return true if a legal play was found (and made); false othewise.
*/
public boolean playIfPossible() {
return false; // REPLACE !
}

Note: The method playIfPossible() is discussed in Exercise 6 on p. 40.


/* Looks for a pair of non-face cards whose values sum to 11.
* If found, replace them with the next two cards in the deck.
* The simulation of this game uses this method.
* @return true if an 11-pair play was found (and made); false othewise.
*/
private boolean playPairSum11IfPossible() {
return false; // REPLACE !
}

Note: The method playPairSum11IfPossible() is mentioned in Exercise 7. This method will call cardIndexes() and findPairSum11(). If findPairSum11() returns a non-empty list, playPairSum11IfPossible() needs to call replaceSelectedCards() to update the game board. This is new; in the GUI version of Elevens the class CardGameGUI called replaceSelectedCards().


/* Looks for a group of three face cards JQK.
* If found, replace them with the next three cards in the deck.
* The simulation of this game uses this method.
* @return true if a JQK play was found (and made); false othewise.
*/
private boolean playJQKIfPossible() {
return false; // REPLACE !
}

 

/**
* Look for an 11-pair in the selected cards.
* @param selectedCards selects a subset of this board. It is list
* of indexes into this board that are searched
* to find an 11-pair.
* @return a list of the indexes of an 11-pair, if an 11-pair was found;
* an empty list, if an 11-pair was not found.
*/
private List findPairSum11(List selectedCards)
{ }

 

/**
* Look for a JQK in the selected cards.
* @param selectedCards selects a subset of this board. It is list
* of indexes into this board that are searched
* to find a JQK group.
* @return a list of the indexes of a JQK, if a JQK was found;
* an empty list, if a JQK was not found.
*/
private List findJQK(List selectedCards)
{ }

Note: The method playJQKIfPossible() is mentioned in Exercise 7. This method will call cardIndexes() and findJQK(). If findJQK() returns a non-empty list, playJQKIfPossible() needs to call replaceSelectedCards() to update the game board.

I didn't see a need to use isLegal() or anotherPlayIsPossible() to get the simulations to work. Different methods in Activity 11 do the work that these methods did in the GUI version. 

 

Resources:
ElevensSimulation.java
Student Guide

 

Links:
Elevens Project
AP Computer Science