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.
Dice game
Collapse
X
-
- 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.
Comment