Rock-paper-scissors: Difference between revisions

Line 267:
 
=={{header|Icon}} and {{header|Unicon}}==
The key to this comes down to two structures and two lines of code. The player history ''historyP'' is just an ordered list of every player turn and provides the weight for the random selection. The ''beats'' list is used to rank moves and to choose the move that would beat the randomly selected move.
<lang Icon>link printf
 
Line 289 ⟶ 290:
}
 
turnC := beats[(?historyP == beats[i := 2 to *beats],i-1)] # choose move
put(historyP,turnP) # record history
Anonymous user