How to resolve the algorithm Rock-paper-scissors step by step in the FreeBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Rock-paper-scissors step by step in the FreeBASIC programming language
Table of Contents
Problem Statement
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:
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.
Support additional choices additional weapons.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Rock-paper-scissors step by step in the FreeBASIC programming language
Source code in the freebasic programming language
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 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"
You may also check:How to resolve the algorithm Palindrome detection step by step in the MATLAB programming language
You may also check:How to resolve the algorithm Function frequency step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Rot-13 step by step in the AArch64 Assembly programming language
You may also check:How to resolve the algorithm Substitution cipher step by step in the 11l programming language
You may also check:How to resolve the algorithm Maze generation step by step in the Erlang programming language