I am using the following method which works but wondering if there is a better algorithm to perform the test. Is there a better way to do it? Doing this in C# but putting syntax
Observation: The user wins if userInput
is only one ahead of computerInput
(case of (1,2), (2,3)) or lag two (case of (3,1)).
Conversely, if userInput
lags one behind computerInput
or two ahead, the user loses.
In the modulo 3, the lag one is the same as the advance two. (-1 mod 3 == 2 mod 3 == 2)
int decision = (userInput - computerInput + 3) % 3;
String[] answer = {"Draw", "Win", "Lose"};
return answer[decision];