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.




include ..\Utilitys.pmt
 
    0 var wh
    0 var wc
 
( "Scissors cuts Paper"
  "Paper covers Rock"
  "Rock crushes Lizard"
  "Lizard poisons Spock"
  "Spock smashes Scissors"
  "Scissors decapites Lizard"
  "Lizard eats Paper"
  "Paper disproves Spock"
  "Spock vaporizes Rock"
  "Rock blunts Scissors" )
 
  "'Rock, Paper, Scissors, Lizard, Spock!' rules are: " ? nl
  len for
    get ?
  endfor
  nl
 
  ( ( "S" "Scissors" ) ( "P" "Paper" ) ( "R" "Rock" ) ( "L" "Lizard" ) ( "K" "Spock" ) )
 
    true while
        "Choose (S)cissors, (P)paper, (R)ock, (L)izard, Spoc(K) or (Q)uit: " input nl upper
        dup "Q" == if
            nl drop false
        else
            getd if
                dup "You choose " print ? var he
                rand 5 * int 1 + 2 2 tolist sget 
                dup "I choose " print ? var ce
                he ce == if
                    "Draw" ?
                else
                    swap len for
                        get dup
                        split 2 del
                        he ce 2 tolist
                        over over == rot rot reverse == or if exitfor else drop endif
                    endfor
                    dup ?
                    he find 1 == if wh 1 + var wh "You win!" else wc 1 + var wc "I win!" endif ? drop
                    swap
                endif
            else
                print " is a invalid input!" ?
            endif
            true
        endif
    endwhile
    drop drop
    "Your punctuation: " print wh ?
    "Mi punctuation: " print wc ? 
    wh wc > if "You win!" else wh wc < if "I win!" else "Draw!" endif endif ?