This was a Rock scissors paper game code ,its a humanplayer
versus a reflectplayer
. Reflectplayer
who copy the last time humanplayer
move and show the move. I tried to access the move2
from the play_round
to ReflectPlayer
. But How? Isn't game1.play_round.move2
work?
import random
moves = ['rock', 'paper', 'scissors']
class Player:
def move(self):
return 'rock'
def learn(self, my_move, their_move):
pass
class RandomPlayer:
def move(self):
all = ["rock","scissors","paper"]
ranint = random.randint(0,2)
return all[ranint]
def learn(self, my_move, their_move):
pass
class HumanPlayer:
def move(self):
ans = input("Rock Paper or Scissors?").lower()
return ans
def learn(self,my_move,their_move):
pass
class ReflectPlayer:
def move(self):
i = 1
RSP = ["rock","paper","scissors"]
print(self.move2)
if i == 1:
i += 1
return RSP[random.randint(0,2)]
elif game1.play_round.move2 == RSP[0]:
return RSP[0]
elif game1.play_round.move2 == RSP[1]:
return RSP[1]
elif game1.play_round.move2 == RSP[2]:
return RSP[2]
else:
print("Wrong input !")
pass
def learn(self,my_move,their_move):
pass
def beats(one, two):
return ((one == 'rock' and two == 'scissors') or
(one == 'scissors' and two == 'paper') or
(one == 'paper' and two == 'rock'))
class Game:
def __init__(self, p1, p2):
self.p1 = p1
self.p2 = p2
def play_round(self):
move1 = self.p1.move()
move2 = self.p2.move()
print(f"Player 1: {move1} Player 2: {move2}")
if beats(move1 , move2) == True:
print(f"This Round : Player 1 WIN")
elif beats(move2 , move1) == True:
print(f"This Round : Player 2 WIN")
elif move1 == move2:
print("This Round : TIE")
else:
print("Wrong Input !")
self.p1.learn(move1, move2)
self.p2.learn(move2, move1)
def play_game(self):
print("Game start!")
for round in range(3):
print(f"Round {round}:")
self.play_round()
print("Game over!")
if __name__ == '__main__':
game1 = Game(ReflectPlayer(),HumanPlayer())
game1.play_game()