Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I wrote a matlab program to play a dice game called pig in the command window. Im now being asked to modify it and be

I wrote a matlab program to play a dice game called pig in the command window. Im now being asked to modify it and be able to enter multiple players and even a computer player to play against and at the end be able to tell which player won the game. Any help with this would be appreciated. Here is my program so far

clc; turn=1; score=0; turnScore = 0; fprintf(' Whats up Dude! Welcome to the mystical game known as "Pig". I will ask you if you want to pass or roll.'); fprintf(' If you pass then your score will be added to your total if you select to roll , then the die value is added to the turn score simple so far right? '); fprintf(' except when the value rolled is 1, in which case your turn score will be set to 0 and you have to stop rolling Lets have some fun :).'); while score<100 fprintf(' Turn : %d',turn); rollDie = input(' Do you want to roll or pass the turn ?(1 for roll, 2 for pass) '); if rollDie == 1 die = randi(6,1); fprintf(' Dice value : %d',die); if die == 1 score = score + 0; turnScore = 0; fprintf(' Current turn is over with 0 score. Advanced to next turn '); turn = turn + 1; else turnScore = turnScore + die; fprintf(' Turn score : %d',turnScore); end fprintf(' Total game score : %d',score); else score = score + turnScore; fprintf(' Turn score : %d',turnScore); fprintf(' Total game score : %d',score); if score < 100 turn = turn + 1; end turnScore=0; end end fprintf(' Good job dude. It only took you %d turns ',turn);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions

Question

What is linear transformation? Define with example

Answered: 1 week ago