Rock Paper Scissor AI written in python and PyQt5
This is a true AI in the sense that it does not read your input and use that against you, but it will use your past inputs to learn how to beat you :)
- PyQt5
- Python (3.x)
Download the files
git clone https://github.com/Eroc123/RPS-Bot.git
Put them in the same folder
Run python3 main.py
in terminal (linux)
Else run py main.py
in the terimal (windows)
You need to install PyQt5 is not already installed
Some important functions
-
predict() get the AI choice
-
log(the ai choice, the player choice, the result)
make sure to use
from cog import Ai
0 : 'rock'
1 : 'paper'
-1 : 'scissor'
for examplefrom cogs import Ai #the cogs.py does not provide functions to find if its a win or a loss win = [[1,0],[0,-1],[-1,1]] lose = [[0,1],[-1,0],[1,-1]] tie = [[1,1],[-1,-1],[0,0]] score = 0 def check(rt): if rt in win: return 1 elif rt in lose: return -1 elif rt in tie: return 0 c = Ai() userchoice = input() #here the user input 1, 0, -1 AIchoice = c.predict() score += check([userchoice, AIchoice]) #remember its user choice first, then ai choice print(score)