Hi everyone!
I need develop the algorithm of popular game.
Tournament "rock, paper, scissors"
Develop a program in any language, simulating the tournament playoffs, "rock, paper, scissors" among 2 players ^ K where K - the number of rounds set by the user.
● Before the tournament, each player is assigned a number from 1 to 2 ^ K and random tactics with equal probability, "scissors", "stone" or "paper", where the player with the tactics, such as "scissors" shows scissors with probability - 0.5 stone - 0.25, paper - 0.25. In other tactics similar to the probability distribution.
● In each round matches take place between the players before the two victories.
● The winner of the match is determined by the following rules:
○ Stone defeats scissors ("stone blunts or breaks scissors")
○ Scissors defeat Paper (the "scissors cut paper")
○ Paper beats rock ("Paper covers rock")
● If the players show the same sign, then the game is replayed.
● Results rounds are displayed.
Example:
Input data:
3
Output:
Player1: scissors
Player2: paper
Player3: paper
Player4 stone
Player5: scissors
Player6: paper
Player7: paper
Player8 stone
Round 1:
Player1 vs Player2 - Player1 won!
Player3 vs Player4 - won Player4!
Player5 vs Player6 - won Player5!
Player7 vs Player8 - won Player8!
Round 2:
Player1 vs Player4 - Player1 won!
Player5 vs Player8 - won Player5!
I decided to make three classes: Player, Game and GameTest.
In Player class I describe such fields as "name", "tactics" and method "showSign" to determine what sign player will show.
In Game class I describe two methods "wonInRound"(here determines winning player of two) and method "go" (here the main algorith of game, here is rounds until appers winner of game)
GameTest is the main class.
My issue: I can't solve draw problem when both players have the same signs. My program is hovering in the cycle
Alex Chun wrote:
My issue: I can't solve draw problem when both players have the same signs. My program is hovering in the cycle
Without trying to run the code...Can't you just in a test for both being equal (a draw)? It might be easiest to add the test at the top so you don't need to change the original code that follows. You have three possible outcomes instead of your current two -- player 1 wins, 2 wins, or equal and nobody wins.
That code snippet would look nicer written with "do-while" loop, something like this, because you wouldn't need to repeat lines 2 and 3 before loop starts:
Alex Chun wrote:My issue: I can't solve draw problem when both players have the same signs. My program is hovering in the cycle
But this is what your code it says to do: repeat, until signs are equal.
And how do you want it to be?
Campbell Ritchie wrote:Repeat until signs are equal? That is not how you play rock paper and scissors.
I am not that familiar with it, but if it is similar to the way is done in my country, you need to replay if signs are equal and keep doing it until while they are equal.
Agh, I expressed myself wrongly, you're right, sorry for my english.
Alex Chun wrote:Liutauras, running is hovering in the cycle.
Here
You keep the loop going as long as there's a tie, and you exit it when there's no tie. That makes sense and is ok.
If I read what you're saying, your code stays in that loop. That means sign1 and sign2 are never equal. Breakpoint the code there or print their values and see what they actually are when they should be equal, and take it from there.
You haven't included the showSign() function which assigns the values to those two, so we can't see if it's broken. If that's not your problem it's at least A problem.
Alex Chun wrote:My issue: I can't solve draw problem when both players have the same signs. My program is hovering in the cycle
Ok, once again, your problem is, that this bit of code loops forever, when both players has the same sign:
But this is whats suppose to be. You didn't answer, how do you want it to behave?
Entire loop looks good, and should exit when signs becomes different. Please clarify if you want someone to help you.
You can enlarge it into rock, paper, scissors, lizard, Spock...
Ok. I'll try it.
My problem was class Player. I mistaken in method "showSign()". There were 2 mistakes.
That is a challenge like offline exams to the university.
Alex Chun wrote:
That is a challenge like offline exams to the university.
I took a class where we did the lizard, Spock version but in Python. There's a less obvious algorithm to find the winner besides the obvious way, but I can't remember what it is. Maybe you can look it up if you're interested.