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.




REM Yabasic 2.763 version
 
WINNER = 1 : ACTION = 2 : LOSSER = 3
dim word$(10, 3)
 
for n = 0 to 9
    read word$(n, WINNER), word$(n, ACTION), word$(n, LOSSER)
next n
 
repeat
    clear screen
    computerChoice$ = word$(ran(10), WINNER)
    print "'Rock, Paper, Scissors, Lizard, Spock!' rules are:\n"
    for n = 0 to 9
        SimonSay(n)
    next n
    print "\nType your choice letter:"
    print "(R)ock, (P)aper, (S)cissors, (L)izard, Spoc(K), (Q)uit\n"
    k$ = upper$(inkey$)
    if k$ = "Q" break
    switch k$
        case "R": humanChoice$ = "Rock" : break
        case "P": humanChoice$ = "Paper" : break
        case "S": humanChoice$ = "Scissors" : break
        case "L": humanChoice$ = "Lizard" : break
        case "K": humanChoice$ = "Spock" : break    
    end switch
    print "Player chose ", humanChoice$, " and Computer chose ", computerChoice$
    for n = 0 to 9
        if word$(n, WINNER) = humanChoice$ and word$(n, LOSSER) = computerChoice$ then
            SimonSay(n)
            print "Winner was Player"
            wp = wp + 1
            break
        elseif word$(n, WINNER) = computerChoice$ and word$(n, LOSSER) = humanChoice$ then
            SimonSay(n)
            print "Winner was Computer"
            wc = wc + 1
            break
        end if    
    next n
    if n = 10 then
        print "Ouch!"
    end if
    punctuation()
    print "\nPress any key to continue"
    inkey$
until(k$ = "Q")
 
punctuation()
if wp > wc then
    print "Player win"
elseif wc > wp then
    print "Computer win"
else
    print "Tie"
end if
 
end
 
sub SimonSay(n)
    print word$(n, WINNER), " ", word$(n, ACTION), " ", word$(n, LOSSER)
end sub
 
sub punctuation()
    print "\nPlayer = ", wp, "\tComputer = ", wc, "\n"
end sub
 
data "Scissors","cuts","Paper"
data "Paper","covers","Rock"
data "Rock","crushes","Lizard"
data "Lizard","poisons","Spock"
data "Spock","smashes","Scissors"
data "Scissors","decapites","Lizard"
data "Lizard","eats","Paper"
data "Paper","disproves","Spock"
data "Spock","vaporizes","Rock"
data "Rock","blunts","Scissors"