Task

Implement the classic children's game Rock-paper-scissors, as well as a simple predictive   AI   (artificial intelligence)   player.

Rock Paper Scissors is a two player game.

Each player chooses one of rock, paper or scissors, without knowing the other player's choice.

The winner is decided by a set of rules:

   Rock beats scissors
   Scissors beat paper
   Paper beats rock


If both players choose the same thing, there is no winner for that round.

For this task, the computer will be one of the players.

The operator will select Rock, Paper or Scissors and the computer will keep a record of the choice frequency, and use that information to make a weighted random choice in an attempt to defeat its opponent.



Extra credit

Support additional choices   additional weapons.




if var.end=0 then
var.end=0
var.computerchoice=random(3) // 1 is rock, 2 is paper, and 3 is scissors.
debug="Press the R key for rock, the P key for paper, or the S key for scissors:"
endif
if pressed(Key.R)and var.end=0 then
   var.end=1
   if var.computerchoice=1 then
      debug="You chose rock, which the computer also chose, so it's a tie!"
   else
      if var.computerchoice=2 then
         debug="The computer chose paper, covering your choice of rock, so you lose!"
      else
         debug="You chose rock, smashing the computer's choice of scissors, so you win!"
      endif
   endif
endif
if pressed(Key.P)and var.end=0 then
   var.end=1
   if var.computerchoice=1 then
      debug="You chose paper, covering the computer's choice of rock, so you win!"
   else
      if var.computerchoice=2 then
         debug="You chose paper, which the computer also chose, so it's a tie!"
      else
         debug="The computer chose scissors, cutting your choice of paper, so you lose!"
      endif
   endif
endif
if pressed(Key.S)and var.end=0 then
   var.end=1
   if var.computerchoice=1 then
      debug="The computer chose rock, smashing your choice of scissors, so you lose!"
   else
      if var.computerchoice=2 then
         debug="You chose scissors, cutting the computer's choice of paper, so you win!"
      else
         debug="You chose scissors, which the computer also chose, so it's a tie!"
      endif
   endif
endif