Chapter 16. Player Random

Table of Contents

Overview
Design
Fields
Constructors
Methods
Deliverables

This section will introduce a simple subclass of Player who bets at random.

Overview

One possible betting strategy is to bet completely randomly. This serves as an interesting benchmark for other betting strategies.

We'll write a subclass of Player which steps through all of the bets available on the Wheel, selecting one or more of the available outcomes at random. This Player, like others, will have a fixed initial stake and a limited amount of time to play.

The Wheel class can provide an Iterator over the collection of Bin instances. We could revise Wheel to provide a binIterator method that we can use to return all of the Bins. From each Bin, we will need an iterator we can use to return all of the Outcomes.

To collect a list of all possible Outcomes, we would use the following algorithm:

Procedure 16.1. Locating all Outcomes

  1. Empty List of Outcomes. Create an empty list of all Outcomes, allOC.

  2. Get Bin Iterator. Get the Iterator from the Wheel that lists all Bins.

    1. For Each Bin

      1. Get Outcome Iterator. Get the Iterator that lists all Outcomes.

      2. For Each Outcome

        1. Save Outcome. Save a reference to each Outcome in the list of all known outcomes, allOC.

To place a random bet, we would use the following algorithm:

Procedure 16.2. Placing a Random Bet

  1. Get the size of the pool of all possible Outcomes, s.

  2. Get a random number, u, from zero to the total size-1. That is, 0 <= u <= s-1.

  3. Return element u from the pool of Outcomes.