import random
input("Welcome to Rock, Paper, Scissors! Press Enter to start.")
print()
user_wins = 0
computer_wins = 0
user_data = []
com_data = []
choices = ["rock", "paper", "scissors"]
while True:
user_choice = input("Rock, Paper, or Scissors? ").lower()
while user_choice not in choices:
user_choice = input("That is not a valid choice. Please try again: ").lower()
if len(user_data) > 0:
fr = user_data.count('rock')/len(user_data)
fp = user_data.count('paper')/len(user_data)
fs = user_data.count('scissors')/len(user_data)
temp = []
back = 0
sigma = [fr,fp,fs]
if user_data[-1:] == 'rock':
temp.append(1)
temp.append(0)
temp.append(0)
elif user_data[-1:] == 'paper':
temp.append(0)
temp.append(1)
temp.append(0)
else:
temp.append(0)
temp.append(0)
temp.append(1)
for f in range(len(sigma)):
temp += sigma[f]*temp[f]
if temp < 0.5:
pilnya = max(fr, fp, fs)
else:
if com_data[-1:] == 'rock':
pilnya = max((fr-temp), fp, fs)
elif com_data[-1:] == 'paper':
pilnya = max(fr, (fp-temp), fs)
else :
pilnya = max(fr, fp, (fs-temp))
if pilnya == fr:
cpu_choice = 'rock'
elif pilnya == fp:
cpu_choice = 'paper'
else:
cpu_choice = 'scissors'
else:
cpu_choice = random.choice(choices)
print()
print("Your choice:", user_choice)
print("Computer's choice:", cpu_choice)
print()
if user_choice == 'rock':
if cpu_choice == 'rock':
print("It's a tie!")
elif cpu_choice == 'scissors':
print("You win!")
user_wins+=1
user_data.append('rock')
elif cpu_choice == 'paper':
print("You lose!")
computer_wins+=1
com_data.append('paper')
elif user_choice == 'paper':
if cpu_choice == 'paper':
print("It's a tie!")
elif cpu_choice == 'rock':
print("You win!")
user_wins+=1
user_data.append('paper')
elif cpu_choice == 'scissors':
print("You lose!")
computer_wins+=1
com_data.append('scissors')
elif user_choice == 'scissors':
if cpu_choice == 'scissors':
print("It's a tie!")
elif cpu_choice == 'paper':
print("You win!")
user_wins+=1
user_data.append('scissors')
elif cpu_choice == 'rock':
print("You lose!")
computer_wins+=1
com_data.append('rock')
print()
print("You have "+str(user_wins)+" wins")
print("The computer has "+str(computer_wins)+" wins")
print()
repeat = input("Play again? (Y/N) ").lower()
while repeat not in ['y', 'n']:
repeat = input("That is not a valid choice. Please try again: ").lower()
if repeat == 'n':
print("Bye bye")
break
print("\n----------------------------\n")