Chapter 14. Player SevenReds

Table of Contents

Overview
Design
Fields
Methods
Deliverables

This section introduces an additional specialization of the Martingale strategy. Additionally, we'll also address some issues in how an overall application is composed of individual class instances. Adding this new subclass should be a small change to the main application class.

Overview

The SevenReds player waits for seven red wins in a row before betting black. This is a subclass of Player. We can create a subclass of our main Simulator to use this new SevenReds class.

We note that our previous players (Passenger57 and Martingale) are stateless: they place the same bets over and over until they are cleaned out or their playing session ends. This SevenReds player has two states: waiting and betting. In the waiting state, they are simply counting the number of reds. In the betting state, they have seen seven reds and are now playing the Martingale system on black. We will defer serious analysis of this stateful betting until some of the more sophisticated subclasses of Player. For now, we will simply use an integer to count the number of reds.

Currently, the player is not informed of the final outcome unless they place a bet. We designed the Game to evaluate the Bet instances and notify the Player of just their Bets that were wins or losses. We will need to add a method to Player to be given the overall list of winning Outcomes even when the Player has not placed a bet.

Once we have updated the design of Game to notify Player, we can add the new SevenReds class. Note that we are can intoduce each new betting strategy via creation of new subclasses. A relatively straightforward update to our simulation main program allows us to use these new subclasses. The previously working subclasses are left in place, allowing graceful evolution by adding features with minimal rework of existing classes.

In addition to waiting for the wheel to spin seven reds, we will also follow the Martingale betting system to track our wins and losses, assuring that a single win will recoup all of our losses. This makes SevenReds a further specialization of Martingale. We will be using the basic features of Martingale, but doing additional processing to determine if we should place a bet or not.

Introducing a new subclass should be done by upgrading the main program. See Soapbox on Composition for comments on the ideal structure for a main program. Additionally, see our Why does the Game class run the sequence of steps? Isn't that the responsibility of some “main program? FAQ entry and Why are we making the random number generator more visible? Isn't object design about encapsulation? FAQ entry for more discussion.