Just went through a variant of the game : Rock-Paper-Scissor-Lizard-Spock
I have written a Java code for traditional R-P-S problem, but when I tried extending my code
In, Rock-Paper-Scissor games, it is easy to decide if move a wins against move b using their index at a cycle. So you don't have to manually decide in your code the result of every combination as other answers here suggest.
For the Rock-Paper-Scissor-Spock-Lizard version:
Let's assign a number to each move (0, 1, 2, 3, 4).
Notice that every move beats two moves:
So let d = (5 + a - b) % 5. Then:
For the Rock-Paper-Scissor version:
let d = (3 + a - b) % 3. Then:
Generalization For n >= 3 and n odd:
Let d = (n + a - b) % n. Then:
