Rock Paper Scissors!
Last updated
Was this helpful?
Last updated
Was this helpful?
rock < paper < scissors < rock
when p1(player 1) rock
paper - p1 lose
scissors - p1 win
when p1 paper
scissors - p1 lose
rock - p1 win
when p1 rock
paper - p1 lose
scissors - p1 win
in this infinite pattern
when meet n+1 element lose
when meet n-1 element win
prepare array ['rock', 'paper', scissors'] (pattern)
find index input x's index in pattern array and
find index input y's index in pattern array
if (x index plus 1) % 3 is same with y index = p2 win
if (x index plus 2) % 3 is same with y index = p1 win
if x,y index same = draw