By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,490 Members | 1,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,490 IT Pros & Developers. It's quick & easy.

Dice game

P: 8
Hi, Iím creating a game where the user challenges the computer in a dice game. I was wondering what the algorithm is for coding a game where the user plays against the computer? Each player, the user and computer get to throw two dices each round. The person with the highest dice score wins the round. The person that wins the most out of 3 rounds wins the game however if someone wins the 2 first rounds, a third one isnít needed to be played.
Jul 13 '19 #1
Share this Question
Share on Google+
1 Reply


100+
P: 103
- Can be done with graphics or just text based as well.

For the algorithm:

- Random() function can used to generate random numbers 1, 2, 3, 4, 5 or 6. You need to set the range accordingly to obtain these numbers.

- Rest of the logic depends on the implementation of loop, ifs, functions etc.

- Throwing dice logic can be coded in a function since it's common for both. While calling the function, their dice scores can be stored in separate variables and then condition checks can be made to see who won the round.

- Use separate variables to count the wins for each player and increment the respective values on wins. Then use the condition check: if wins > (no_of_rounds/2), if so, break statement can be used to jump out of everything and declare the winner.
Jul 13 '19 #2

Post your reply

Sign in to post your reply or Sign up for a free account.