# Tenzi Dice Game

Tenzi Party

Tenziis a frenetic dice game that is a fun party activity. The game uses sets of ten (10) 6-sided

dice to play. Each player holds 10 dice in hands. When the game starts, everyone rolls at the

same time. Each player looks at the first roll and decides which number to roll all 10 dice to

become. For example, if the first roll shows more 3’s than any other number, it’s logical to go

for all 3s. Put all the dice with the number aside and quickly roll the remaining dice. Keep

rolling until all 10 dice show the same number. The goal of the game is to roll fast and be the

first player to get all 10 of the dice to show the same number. The first player that shouts

“TENZI” wins the game.

Write a MATLAB program to simulate the Tenzi party game automatically that can:**
**1. Play Tenzi for multiple players simultaneously and automatically.

**2. Ask the game host to input how many players will play.**

**3. Use ten (10) 6-sided dice to automatically play the Tenzi game for each player. For**

**example, 4 players will use a total of forty (40) dice.**

**4. Generate ten (10) random integers between 1 and 6 to represent the face value of**

**rolling ten dice for each player to simulate all players roll at the same time. For**

**example, a 6-player game will generate 60 random integers.**

**5. Print all the dice values on screen and clearly indicate which player (i.e. player 1,**

**player 2, and so on…) rolls what values.**

**6. Based on the first roll results, the program should automatically decide the best**

**numbers to keep for all the players. The program should be able to automatically**

**keep different dice values best for each player. The program must be able to make**

**the best decisions without bias for all the players.**

**7. Set aside the dice rolled with the number by counting and printing “the number of**

**dice on the side” for all the players in the command window.**

**8. Print the face values of the dice that are set aside on screen for all the players.**

**9. Roll the remaining dice by generating as many random integers between 1 and 6**

**as needed for all the players.**

**10. Print the remaining dice values on screen for all the players and clearly indicate**

**which player (i.e. player 1, player 2, and so on…) rolls what values.**

**11. Set aside the dice with the desired value (determined in step 6) and print “the**

**total number of dice on the side” for every player in the command window.**

**12. Print the face values of the dice that are set aside on screen for all the players.**

**13. Keep rolling the remaining dice until one of the players gets ten (10) dice of the**

**same number.**

**14. Track the number of rounds the players roll dice and print the round number in the**

**command window.**

**15. Print which player shouts out “TENZI” on screen.**

The finished program can look like the following example. Extra components are always welcome.

How many players will play together? 2

**Round 1:**

Player 1 rolls: 6 6 2 6 2 3 4 3 3 3

Player 2 rolls: 6 1 1 6 6 6 6 2 2 1

Player 1 moves value 3 to the side

Player 2 moves value 6 to the side

Player 1 has 4 dice on the side

Player 2 has 5 dice on the side

Player 1 side: 3 3 3 3

Player 2 side: 6 6 6 6 6

Round 2:

Player 1 rolls: 2 1 6 4 2 5

Player 2 rolls: 2 5 2 4 3

Player 1 has 4 dice on the side

Player 2 has 5 dice on the side

Player 1 side: 3 3 3 3

Player 2 side: 6 6 6 6 6

Round 3:

Player 1 rolls: 3 5 4 6 6 4

Player 2 rolls: 1 2 2 3 3

Player 1 has 5 dice on the side

Player 2 has 5 dice on the side

Player 1 side: 3 3 3 3 3

Player 2 side: 6 6 6 6 6

Round 4:

Player 1 rolls: 4 4 1 5 1

Player 2 rolls: 5 6 1 1 5

Player 1 has 5 dice on the side

Player 2 has 6 dice on the side

Player 1 side: 3 3 3 3 3

Player 2 side: 6 6 6 6 6 6

Round 5:

Player 1 rolls: 1 6 6 1 2

Player 2 rolls: 6 4 4 1

Player 1 has 5 dice on the side

Player 2 has 7 dice on the side

Player 1 side: 3 3 3 3 3

Player 2 side: 6 6 6 6 6 6 6

Round 6:

Player 1 rolls: 2 6 6 2 2

Player 2 rolls: 6 5 5

Player 1 has 5 dice on the side

Player 2 has 8 dice on the side

Player 1 side: 3 3 3 3 3

Player 2 side: 6 6 6 6 6 6 6 6

Round 7:

Player 1 rolls: 6 3 1 2 1

Player 2 rolls: 4 1

Player 1 has 6 dice on the side

Player 2 has 8 dice on the side

Player 1 side: 3 3 3 3 3 3

Player 2 side: 6 6 6 6 6 6 6 6

Round 8:

Player 1 rolls: 6 4 4 5

Player 2 rolls: 3 4

Player 1 has 6 dice on the side

Player 2 has 8 dice on the side

Player 1 side: 3 3 3 3 3 3

Player 2 side: 6 6 6 6 6 6 6 6

Round 9:

Player 1 rolls: 6 6 6 2

Player 2 rolls: 1 4

Player 1 has 6 dice on the side

Player 2 has 8 dice on the side

Player 1 side: 3 3 3 3 3 3

Player 2 side: 6 6 6 6 6 6 6 6

Round 10:

Player 1 rolls: 3 5 2 3

Player 2 rolls: 2 2

Player 1 has 8 dice on the side

Player 2 has 8 dice on the side

Player 1 side: 3 3 3 3 3 3 3 3

Player 2 side: 6 6 6 6 6 6 6 6

Round 11:

Player 1 rolls: 1 4

Player 2 rolls: 6 1

Player 1 has 8 dice on the side

Player 2 has 9 dice on the side

Player 1 side: 3 3 3 3 3 3 3 3

Player 2 side: 6 6 6 6 6 6 6 6 6

Round 12:

Player 1 rolls: 3 4

Player 2 rolls: 6

Player 1 has 9 dice on the side

Player 2 has 10 dice on the side

Player 1 side: 3 3 3 3 3 3 3 3 3

Player 2 side: 6 6 6 6 6 6 6 6 6 6

Round 13:

Player 1 rolls: 1

Player 2 rolls:

*** Player 2 yells TENZI!!! ***

Here is another example.

How many players will play together? 4

**Round 1:**

Player 1 rolls: 1 2 5 2 2 3 2 2 2 6

Player 2 rolls: 3 1 1 1 3 6 1 6 1 1

Player 3 rolls: 5 3 5 4 3 4 2 4 2 2

Player 4 rolls: 5 2 3 5 2 2 4 3 2 2

Player 1 moves value 2 to the side

Player 2 moves value 1 to the side

Player 3 moves value 2 to the side

Player 4 moves value 2 to the side

Player 1 has 6 dice on the side

Player 2 has 6 dice on the side

Player 3 has 3 dice on the side

Player 4 has 5 dice on the side

Player 1 side: 2 2 2 2 2 2

Player 2 side: 1 1 1 1 1 1

Player 3 side: 2 2 2

Player 4 side: 2 2 2 2 2

Round 2:

Player 1 rolls: 4 5 4 2

Player 2 rolls: 2 1 2 2

Player 3 rolls: 3 3 2 1 1 4 4

Player 4 rolls: 5 5 2 4 6

Player 1 has 7 dice on the side

Player 2 has 7 dice on the side

Player 3 has 4 dice on the side

Player 4 has 6 dice on the side

Player 1 side: 2 2 2 2 2 2 2

Player 2 side: 1 1 1 1 1 1 1

Player 3 side: 2 2 2 2

Player 4 side: 2 2 2 2 2 2

Round 3:

Player 1 rolls: 5 6 4

Player 2 rolls: 1 6 1

Player 3 rolls: 6 1 3 1 1 5

Player 4 rolls: 4 4 2 6

Player 1 has 7 dice on the side

Player 2 has 9 dice on the side

Player 3 has 4 dice on the side

Player 4 has 7 dice on the side

Player 1 side: 2 2 2 2 2 2 2

Player 2 side: 1 1 1 1 1 1 1 1 1

Player 3 side: 2 2 2 2

Player 4 side: 2 2 2 2 2 2 2

Round 4:

Player 1 rolls: 6 3 2

Player 2 rolls: 5

Player 3 rolls: 6 1 5 4 2 3

Player 4 rolls: 5 5 3

Player 1 has 8 dice on the side

Player 2 has 9 dice on the side

Player 3 has 5 dice on the side

Player 4 has 7 dice on the side

Player 1 side: 2 2 2 2 2 2 2 2

Player 2 side: 1 1 1 1 1 1 1 1 1

Player 3 side: 2 2 2 2 2

Player 4 side: 2 2 2 2 2 2 2

Round 5:

Player 1 rolls: 5 1

Player 2 rolls: 4

Player 3 rolls: 4 6 6 4 5

Player 4 rolls: 5 5 2

Player 1 has 8 dice on the side

Player 2 has 9 dice on the side

Player 3 has 5 dice on the side

Player 4 has 8 dice on the side

Player 1 side: 2 2 2 2 2 2 2 2

Player 2 side: 1 1 1 1 1 1 1 1 1

Player 3 side: 2 2 2 2 2

Player 4 side: 2 2 2 2 2 2 2 2

Round 6:

Player 1 rolls: 6 6

Player 2 rolls: 4

Player 3 rolls: 1 3 2 2 4

Player 4 rolls: 3 2

Player 1 has 8 dice on the side

Player 2 has 9 dice on the side

Player 3 has 7 dice on the side

Player 4 has 9 dice on the side

Player 1 side: 2 2 2 2 2 2 2 2

Player 2 side: 1 1 1 1 1 1 1 1 1

Player 3 side: 2 2 2 2 2 2 2

Player 4 side: 2 2 2 2 2 2 2 2 2

Round 7:

Player 1 rolls: 3 6

Player 2 rolls: 5

Player 3 rolls: 1 5 5

Player 4 rolls: 3

Player 1 has 8 dice on the side

Player 2 has 9 dice on the side

Player 3 has 7 dice on the side

Player 4 has 9 dice on the side

Player 1 side: 2 2 2 2 2 2 2 2

Player 2 side: 1 1 1 1 1 1 1 1 1

Player 3 side: 2 2 2 2 2 2 2

Player 4 side: 2 2 2 2 2 2 2 2 2

Round 8:

Player 1 rolls: 3 5

Player 2 rolls: 2

Player 3 rolls: 5 1 4

Player 4 rolls: 3

Player 1 has 8 dice on the side

Player 2 has 9 dice on the side

Player 3 has 7 dice on the side

Player 4 has 9 dice on the side

Player 1 side: 2 2 2 2 2 2 2 2

Player 2 side: 1 1 1 1 1 1 1 1 1

Player 3 side: 2 2 2 2 2 2 2

Player 4 side: 2 2 2 2 2 2 2 2 2

Round 9:

Player 1 rolls: 1 5

Player 2 rolls: 4

Player 3 rolls: 1 2 3

Player 4 rolls: 1

Player 1 has 8 dice on the side

Player 2 has 9 dice on the side

Player 3 has 8 dice on the side

Player 4 has 9 dice on the side

Player 1 side: 2 2 2 2 2 2 2 2

Player 2 side: 1 1 1 1 1 1 1 1 1

Player 3 side: 2 2 2 2 2 2 2 2

Player 4 side: 2 2 2 2 2 2 2 2 2

Round 10:

Player 1 rolls: 3 4

Player 2 rolls: 1

Player 3 rolls: 4 1

Player 4 rolls: 6

Player 1 has 8 dice on the side

Player 2 has 10 dice on the side

Player 3 has 8 dice on the side

Player 4 has 9 dice on the side

Player 1 side: 2 2 2 2 2 2 2 2

Player 2 side: 1 1 1 1 1 1 1 1 1 1

Player 3 side: 2 2 2 2 2 2 2 2

Player 4 side: 2 2 2 2 2 2 2 2 2

Round 11:

Player 1 rolls: 1 3

Player 2 rolls:

Player 3 rolls: 5 2

Player 4 rolls: 1

*** Player 2 yells TENZI!!! ***

Here is another example.

How many players will play together? 0

**Round 1:**

*** Player yells TENZI!!! ***

**Solution**** **

%TENZI simulates a game of TENZI wich involves 2-4 players each with 10

% dice and the winner is the first to get the same number on the faces of

% all the 10 dice

% number of players

p = input(‘How many players will play together? ‘);

% check input

assert(p>=2 && p<=4 && round(p) == p, ‘Valid inputs: 2, 3 or 4’)

% prepare variables for holding results

n_dice = 10;

n_faces = 6;

p_dice = ones(p, 1)*n_dice;

p_face = zeros(size(p_dice));

% play the game

index = 0;

while 1

index = index + 1;

disp([‘Round ‘ num2str(index) ‘:’])

% roll die for each

for k = 1:p

temp = randi([1 n_faces], 1, p_dice(k));

disp([‘Player ‘ num2str(k) ‘ rolls: ‘ num2str(temp)])

if index == 1

face = mode(temp);

p_face(k) = face;

else

face = p_face(k);

end

ifisempty(temp)

p_dice(k) = NaN;

else

p_dice(k) = p_dice(k)-sum(temp==face);

end

end

% test if there is a winner

if any(isnan(p_dice))

fprintf(‘\n\n’)

temp = 1:p;

ind = temp(isnan(p_dice));

fornn = ind

disp([‘*** Player ‘ num2str(nn) ‘ yells TENZI!!! ***’])

end

break

end

if index == 1

% display value moved to the side

for k = 1:p

disp([‘Player ‘ num2str(k) ‘ moves value ‘ …

num2str(p_face(k)) ‘ to the side’])

end

end

% obtained numbers

num = n_dice-p_dice;

% display dice on the side

for k = 1:p

disp([‘Player ‘ num2str(k) ‘ has ‘ …

num2str(num(k)) ‘ dice on the side’])

end

% List die on the side

for k = 1:p

disp([‘Player ‘ num2str(k) ‘ side: ‘ …

num2str(ones(1,num(k))*p_face(k))])

end

fprintf(‘\n\n’)

end