The following built-in MATLAB functions and commands are permitted for this assignment.
Vector/Matrix
Flow Control
Strings and Character Arrays
Other
Points will be deducted from any programs using functions outside this list.
AI for any part of this problem.function_name.m, where each function_name is listed below.init_game
glyphs and maxRounds fields will remain static throughout the game, while the others may change as the game is played.
Inputs:
|
|
Outputs:
|
game (1x1) struct with fields:
|
Note:
|
The values in parentheses are default values for each field.
|
Details:
|
βΈ Except for possibly maxRounds, the values in the output structure should match the default values.
|
βΈ The dice icons (i.e., glyphs) we will use to visualize the dice are display_game_area helper.
|
g = init_game(3)
%
% struct with fields:
% round: 1
% maxRounds: 3
% glyphs: ["β" "β" "β" "β" "β" "β
"]
% dWins: 0
% pWins: 0
% dHand: [1Γ1 struct]
% pHand: [1Γ1 struct]
g.dHand
%
% struct with no fields.
init_hand
Inputs:
|
None
|
Outputs:
|
hand (1x1) struct with fields:
|
Note:
|
The values in parentheses are the default values for each field. These values will be updated later by your set_hand_struct helper.
|
Details:
|
βΈ This function sets up a clean Dice Poker hand with the default values listed above.
|
aHand = init_hand()
% struct with fields:
%
% roll1: []
% roll2: []
% counts: []
% rid: 0
% rank1: ""
% rank2: ""
aHand.rid
% returns: 0
get_rank
Inputs:
|
roll (1 x 5) integer vector β dealerβs initial roll sorted by rank order.
|
Outputs:
|
id (1x1) integer β rank ID.
|
name (1x1) string β rank name.
|
|
Details:
|
βΈ To get full-credit on the test cases, you must spell each rank name exactly as it reads in the Dice Rank Table.
|
Helpers:
|
% Example 1
roll = [3 3 3 4 1];
counts = [1 0 3 1 0 0];
[id,name] = get_rank(roll, counts)
% returns
% id = 5
% name = "three-of-a-kind"
% Example 2
roll = [4 4 4 6 6];
counts = [0 0 0 3 0 2];
[id,name] = get_rank(roll, counts)
% returns
% id = 3
% name = "full-house"
set_hand_struct
Inputs:
|
hand (1x1) struct containing the fields:
roll (1 x 5) integer vector β new set of dice values (faces 1-6).
|
Note:
|
hand is a generic input name. In practice, this will be either the dHand or pHand structures initialized in init_game.
|
Outputs:
|
new_hand (1x1) struct β updated roll with new roll, rank ID, rank name, and face counts.
|
Details:
|
βΈ The input roll will represent the initial roll or reroll from either the dealer or player (depending on whose hand was sent in as the input).
|
βΈ Also update either:
|
|
Helpers:
|
% Example 1: Before and After initial roll
d = init_hand()
% d before:
% d =
% struct with fields:
% roll1: []
% roll2: []
% rank1: ''
% rank2: ''
% counts: []
% rid: 0
d = set_hand_struct(d, [5 2 4 1 5])
% d after:
% d =
% struct with fields:
% roll1: [5 5 4 2 1]
% roll2: []
% rank1: 'one-pair'
% rank2: ''
% counts: [1 1 0 1 2 0]
% rid: 7
% Example 2: After reroll
d = set_hand_struct(d, [3 3 5 5 5])
% returns:
% d =
% struct with fields:
% roll1: [5 5 4 2 1]
% roll2: [5 5 5 3 3]
% rank1: 'one-pair'
% rank2: 'full-house'
% counts: [0 0 2 0 3 0]
% rid: 3
display_game_area
Inputs:
|
|
phaseMsg (1x1) string β describes the current phase of the game.
|
|
actionMsg (1x1) string β describes actions or results of a phase.
|
|
Outputs:
|
None
|
Details:
|
βΈ Create a template for the game area. For example:
|
|
|
βΈ The goal is to replace all the generic labels, below, with the current values from the game inside
g.
|
|
βΈ You can use MATLABβs replace function to find & replace the generic labels in gameArea with their corresponding game values.
|
|
βΈ Any game value that is a string in g can replace its generic label directly. Numeric values should be converted to a string with num2str.
|
|
βΈ Converting a roll (1x5 integer vector) requires a two step process:
|
|
βΈ Once the gameArea has the correct values, clear the Command Window with clc & display the game area with disp(char(gameArea)). Displaying the game area as a character array with char removes the " " characters from the sides of the game area.
|
% Example 1
g = init_game(3);
g.dHand = init_hand();
g.pHand = init_hand();
g.dHand.roll1 = [6 6 5 3 2];
g.dHand.rank1 = 'one-pair';
display_game_area(g, ":: Dealer's Initial Roll ::", "");
% The commands above should clear the command window and display:
DICE POKER (Best of 3) ROUND: 1
===============================================
DEALER: 0
ROLL: β
β
β β β one-pair
REROLL:
===============================================
PLAYER: 0
ROLL:
REROLL:
===============================================
:: Dealer's Initial Roll ::
% There should be a blank line above since actionMsg = ""
% Example 2
g = init_game(3);
g.round = 2;
g.dWins = 1;
g.dHand = init_hand();
g.pHand = init_hand();
g.dHand.roll1 = [6 6 5 3 2];
g.dHand.rank1 = 'one-pair';
g.dHand.roll2 = [6 6 2 2 5];
g.dHand.rank2 = 'two-pair';
g.pHand.roll1 = [6 5 4 3 2];
g.pHand.rank1 = 'straight';
phase_msg = ":: Player's Selection ::";
action_msg = "Player keeps all Dice.";
display_game_area(g, phase_msg, action_msg);
% The commands above should clear the command window and display:
DICE POKER (Best of 3) ROUND: 2
===============================================
DEALER: 1
ROLL: β
β
β β β one-pair
REROLL: β
β
β β β two-pair
===============================================
PLAYER: 0
ROLL: β
β β β β straight
REROLL:
===============================================
:: Player's Selection ::
Player keeps all Dice.
play_one_round
Inputs:
|
|
Outputs:
|
game (1x1) struct β updated game state structure.
|
Details:
|
βΈ Before starting a round, reset the player and dealerβs hand structures to the default values.
|
βΈ Each phase should update a field of the game structure followed by a call your display_game_area helper.
|
|
βΈ Conclude each phase with a prompt for the player to press enter: |
|
βΈ You can see a full round in action by downloading this play_one_round demo and running it in MATLAB.
|
|
Helpers:
|
init_hand, roll_dice, set_hand_struct, get_dealer_reroll, get_player_reroll, display_game_area, get_winner
|
game = init_game(); % One-round game initialization
game = play_one_round(game);
% Does it play without error?
% Does it mimic the provided demo?
% The input game struct enters as a blank slate. Are the fields of the
% output game struct filled-in with the results of the game?
dice_poker
Inputs:
|
None.
|
Outputs:
|
None.
|
Details:
|
βΈ This is the entry point and main driver for your Dice Poker game.
|
βΈ It can be broken down into three main sections:
|
|
βΈ To see a full βBest-of-3β Dice Poker Game, download this dice_poker demo and run it in MATLAB.
|
|
βΈ This should be a self-contained game, meaning all helper functions that it depends on must be included below the dice_poker function within your dice_poker.m file.
|
|
βΈ Before turning this in, move your dice_poker.m file to a completely isolated folder on your computer and run it in MATLAB. If it runs without error and as you expect, then you should be good to go.
|
|
Helpers:
|
% Start a game.
dice_poker()
% Does it play without error? Does it mimic the provided demo?