Design

There are a number of design elements: the superclass for the states, plus the individual state classes, and the actual subclass of Player that uses these states.

This version of the design will use a simpler design that constructs individual state objects on every state change. Once this is working, it can be replaced with a proper Singleton design to see how much that improves performance.

Player1326 State

Player1326State is the superclass for all of the states in the 1-3-2-6 betting system.

Fields

  • Player1326 player ;

    The player who is currently in this state. This player will be used to provide the Outcome on which we will bet.

Constructors

  • Player1326State(Player1326 player);

    The constructor for this class saves the Player1326 which will be used to provide the Outcome on which we will bet.

Methods

  • abstract Bet currentBet();

    Constructs a new Bet from the player's outcome information. Each subclass has a different multiplier used when creating this bet.

    In Java, this method can be declared as abstract. Each subclass will provide a unique implementation for this method.

    In Python, this method should raise the NotImplementedException. This is a big debugging aid, it helps us locate subclasses which did not provide a method body. This raise statement is the functional equivalent of the Java abstract declaration.

  • abstract Player1326State nextWon();

    Constructs the new Player1326State instance to be used when the bet was a winner.

    In Java, this method can be declared as abstract. Each subclass will provide a unique implementation for this method.

    In Python, this method should raise the NotImplementedException.

  • Player1326State nextLost();

    Constructs the new Player1326State instance to be used when the bet was a loser. This method is the same for each subclass: it creates a new instance of Player1326NoWins. It is not abstract, but actually defined in the superclass to assure that it is available for each subclass.

Player1326 No Wins

Player1326NoWins defines the bet and state transition rules in the 1-3-2-6 betting system. When there are no wins, the base bet value of 1 is used.

Methods

  • Bet currentBet();

    Constructs a new Bet from the player's outcome information. The bet multiplier is 1.

  • Player1326State nextWon();

    Constructs the new Player1326OneWin instance to be used when the bet was a winner.

Player1326 One Win

Player1326NoWins defines the bet and state transition rules in the 1-3-2-6 betting system. When there is one wins, the base bet value of 3 is used.

Methods

  • Bet currentBet();

    Constructs a new Bet from the player's outcome information. The bet multiplier is 3.

  • Player1326State nextWon();

    Constructs the new Player1326TwoWins instance to be used when the bet was a winner.

Player1326 Two Wins

Player1326NoWins defines the bet and state transition rules in the 1-3-2-6 betting system. When there are two wins, the base bet value of 2 is used.

Methods

  • Bet currentBet();

    Constructs a new Bet from the player's outcome information. The bet multiplier is 2.

  • Player1326State nextWon();

    Constructs the new Player1326ThreeWins instance to be used when the bet was a winner.

Player1326 No Wins

Player1326NoWins defines the bet and state transition rules in the 1-3-2-6 betting system. When there are three wins, the base bet value of 6 is used.

Methods

  • Bet currentBet();

    Constructs a new Bet from the player's outcome information. The bet multiplier is 6.

  • Player1326State nextWon();

    Constructs the new Player1326NoWins instance to be used when the bet was a winner.

Player1326

Player1326 follows the 1-3-2-6 betting system. The player has a preferred Outcome, an even money bet like red, black, even, odd, high or low. The player also has a current betting state that determines the current bet to place, and what next state applies when the bet has won or lost.

Fields

  • Outcome outcome ;

    This is the player's preferred outcome.

  • Player1326State myState ;

    This is the current state of the 1-3-2-6 betting system. It will be an instance of one of the four states: No Wins, One Win, Two Wins or Three Wins.

Constructors

  • Player1326();

    Initializes the state and the outcome. The myState is set to the initial state of an instance o0f Player1326NoWins. The outcome is set to some even money proposition, for example "Black".

Methods

  • void placeBets();

    Updates the Table with a bet created by the current state. This method delegates the bet creation to myState currentBet.

  • void win(Bet bet);

    Uses the superclass method to update the stake with an amount won. Uses the current state to determine what the next state will be by calling myState's nextWon method and saving the new state in myState

  • void lose(Bet bet);

    Uses the current state to determine what the next state will be. This method delegates the next state decision to myState's nextLost, method saving the result in myState.