We'll design the base class of Player and
a specific subclass, Martingale. This will give
us a working player that we can test with.
Player places bets in Roulette. This an
abstract class, with no actual body for the
placeBets method. However, this class does
implement the basic win method used by all
subclasses.
int stake ;The player's current stake. Initialized to the player's starting budget.
int roundsToGo ;The number of rounds left to play. Initialized by the overall simulation control to the maximum number of rounds to play. In Roulette, this is spins. In Craps, this is the number of throws of the dice, which may be a large number of quick games or a small number of long-running games. In Craps, this is the number of cards played, which may be large number of hands or small number of multi-card hands.
Table table ;Used to place individual
Bets.
boolean playing();Returns true while the player is
still active.
void placeBets();Updates the Table with the
various Bets.
When designing the Table, we
decided that we needed to deduct the amount of a bet from the
stake when the bet is created. See the Table Overview for
more information.
void win(Bet theBet);Notification from the Game that
the Bet was a winner. The amount of
money won is available via theBet
winAmount.
void lose(Bet theBet);Notification from the Game that
the Bet was a loser. Note that the
amount was already deducted from the stake when the bet was
created.
Martingale is a
Player who places bets in Roulette. This
player doubles their bet on every loss and resets their bet to a
base amount on each win.
int lossCount ;The number of losses. This is the number of times to double the bet.
int betMultiple ;The the bet multiplier, based on the number of losses. This starts at 1, and is reset to 1 on each win. It is doubled in each loss. This is always equal to 2lossCount.
void placeBets();Updates the Table with a bet on
black. The amount bet is
2lossCount,
which is the value of betMultiple.
void win(Bet theBet);Uses the superclass win method
to update the stake with an amount won. This method then
resets lossCount to zero, and resets
betMultiple to 1.
void lose(Bet theBet);Increments lossCount by
1 and doubles
betMultiple.