[Tutor] Rock, Paper, Scissors game

eryksun eryksun at gmail.com
Fri Jul 26 19:38:44 CEST 2013


On Fri, Jul 26, 2013 at 9:06 AM, Peter Otten <__peter__ at web.de> wrote:
> You could anecdotally test the above outline by adding more weapons. For
> four weapons you should get ties between distinct weapons:
>
> +-->rock-->paper-->scissors-->banana--+
> |                                     |
> +---------------<---------------------+
>
> rock vs scissors:
> rock-->paper-->scissors: 2 steps
> scissors-->banana-->rock: 2 steps
> tie
>
> You can modify the script to work with an arbitrary number of weapons by
> replacing 3 with length(weapons) if you like.

Nice analysis.

I propose a rule to minimize the occurrence of ties and preserve the
classic pairwise results when extending "rock, paper, scissors" using
modulo (I'm sure this has been analyzed to death in academia, but I
haven't research it). Extending to N items should require N to be odd,
and rock, paper, and scissors should be at indexes 0, N//2, and N-1,
respectively. The loser is the closer of the pair in the clockwise
direction:

+-->rock-->X-->paper-->Y-->scissors--+
|                                    |
+----------------<-------------------+

If it isn't a tie, the test for whether "player" wins is simply

    (other - player) % N > N // 2

For N == 3, this test is (other - player) % 3 > 1. Looking at it the
other way around, it's (player - other) % 3 <= 1, i.e. (player -
other) % 3 == 1, as Dave pointed out.

The trick is to add items that make sense for all possible pairings.
Each item has to beat the preceding N//2 items and lose to the
subsequent N//2 items. So for N==5, we have

         Wins              Loses
    X    Scissors, Rock    Paper, Y
    Y    X, Paper          Scissors, Rock

I'll just plagiarize a certain TV show. X is Spock and Y is Lizard:

    Spock smashes scissors
    Spock vaporizes rock
    paper disproves Spock
    lizard poisons Spock
    lizard eats paper
    scissors decapitates lizard
    rock crushes lizard


More information about the Tutor mailing list