Main Content

Model Dice Game Rules Using a Requirements Table Block

Since R2022a

This example shows how to model some of the rules associated with the craps dice game by using a Requirements Table block. Typically, craps involves a player, an audience, and casino staff. In the game, the player rolls two six-sided dice. The player and audience members bet based on the sum of the dice, and the staff enforce the rules and manage the bets.

On the first role, the player must follow these rules:

  • If the player rolls and the sum of the dice is 7 or 11, the game starts over. This is called rolling a natural.

  • If the player rolls and the sum of the dice is 2, 3, or 12, the game starts over. This is called rolling craps.

  • Otherwise, the sum is assigned to a value known as the point, and the game continues.

If the player establishes the point, they continue to roll the dice. On the next rolls, they must follow these rules:

  • If the player rolls and the sum of the dice is 7, the game starts over. This is called rolling seven-out.

  • If the player rolls and the sum of the dice is the value of the point, the game starts over. This is called rolling the point.

  • Otherwise, the player rolls the dice again.

In this example, the model determines the outcomes of the rolls and stops the simulation when the game must start over. The Requirements Table block represents these rules and their outcomes as requirements.

View the Model

Open the ReqTableDiceGame model. The model generates two random integers with values that range from 1 to 6 to represent the value of the dice. Based on the roll, the simulation continues or stops.

Open the Requirements Table block, Dice Game Rules. The requirements model the dice game rules by using a combination of temporal operators and requirement hierarchies. See Control Requirement Execution by Using Temporal Logic and Establish Hierarchy in Requirements Table Blocks.

The block also includes two assumptions that constrain the possible value of each die. See Add Assumptions to Requirements.

The requirements are complete and consistent. See Identify Inconsistent and Incomplete Formal Requirement Sets.

Exit the block and run the simulation. You can view the outcomes of the game in the Floating Scope block. Run the simulation multiple times to generate different game results. The model runs for a maximum 10 rolls. Extend the simulation time to allow for more total rolls.

See Also

Related Topics