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.




Dim Shared As Byte ganador = 1, accion = 2, perdedor = 3, wp, wc
Dim Shared As String word(10, 3)
For n As Byte = 0 To 9
    Read word(n, ganador), word(n, accion), word(n, perdedor)
Next n
 
Sub SimonSay(n As Byte)
    Print Using "\       \  \        \  "; word(n, ganador); word(n, accion); word(n, perdedor)
End Sub
 
Sub Puntuacion()
    Print !"\nPlayer = "; wp; !"\tComputer = "; wc; !"\n"
End Sub
 
Dim As Byte n
Dim As String*1 k
Dim As String eleccionCPU, eleccionJUG
Randomize Timer
Do
    Cls
    eleccionCPU = word(Rnd *10, ganador)
 
    Print !"'Rock, Paper, Scissors, Lizard, Spock!' rules are:\n"
    For n = 0 To 9
        SimonSay(n)
    Next n
 
    Print !"\nType your choice letter:"
    Input !"(R)ock, (P)aper, (S)cissors, (L)izard, Spoc(K), (Q)uit  ", k
 
    k = Ucase(k)
    Select Case k
    Case "Q" 
        Exit Do
    Case "R"
        eleccionJUG = "Rock"
    Case "P"
        eleccionJUG = "Paper"
    Case "S"
        eleccionJUG = "Scissors"
    Case "L"
        eleccionJUG = "Lizard"
    Case "K"
        eleccionJUG = "Spock"    
    End Select
 
    Print !"\nPlayer chose "; eleccionJUG; " and Computer chose "; eleccionCPU
    For n = 0 To 9
        If word(n, ganador) = eleccionJUG And word(n, perdedor) = eleccionCPU Then
            SimonSay(n)
            Print !"\nWinner was Player"
            wp += 1
            Exit For
        Elseif word(n, ganador) = eleccionCPU And word(n, perdedor) = eleccionJUG Then
            SimonSay(n)
            Print !"\nWinner was Computer"
            wc += 1
            Exit For
        End If    
    Next n
    If n = 10 Then Print !"\nOuch!"
 
    Puntuacion()
    Print "Press <SPACE> to continue"
    Sleep
Loop Until(k = "Q")
 
Cls
Puntuacion()
If wp > wc Then
    Print "Player win"
Elseif wc > wp Then
    Print "Computer win"
Else
    Print "Tie"
End If
Sleep 
End
 
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"