Я разрабатываю ножницы для бумаги из камня на питоне, и я застрял.Я сделал урок, который циклично (камень, бумага и ножницы), я хочу, чтобы компьютер знал, что это предыдущая игра.например (в первом раунде компьютер играл в рок, в следующем раунде он должен играть на бумаге)
, но я не знаю, как вызвать функцию обучения, чтобы она заработала
class Player:
def __init__(self):
self.score = 0
def move(self):
return 'rock'
def learn(self, my_move, their_move):
self.my_move = my_move
self.their_move = their_move
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 = input("Pick something!\n")
move2 = self.p2.move()
print(f"Player 1: {move1} Player 2: {move2}")
self.p1.learn(move1, move2)
self.p2.learn(move2, move1)
if beats(move1, move2):
self.p1.score += 1
print ("You win")
print ("Human score = " + str(self.p1.score) + " " + "Computer score = " + str(self.p2.score) )
elif beats(move2,move1):
self.p2.score += 1
print ("Computer wins")
print ("Human score = " + str(self.p1.score) + " " + "Computer score = " + str(self.p2.score) )
else:
print ("Draw")
print ("Human score = " + str(self.p1.score) + " " + "Computer score = " + str(self.p2.score) )
def play_game(self):
print("Game start!")
for round in range(3):
print(f"Round {round}:")
self.play_round()
print("Game over!")
class human_player(Player):
def move(self):
return input("Pick something!\n")
class randomplayer(Player):
def move(self):
return random.choice(moves)
class repeat(Player):
def move(self):
return 'rock'
class cycleplayer(Player):
def move(self):
# calling my_move from the Player class
if self.learn.my_move == "rock" or "paper" or "scissors" :
return 'rock'
elif self.their_move == 'rock':
return "paper"
elif self.their_move == 'paper':
return "scissors"
elif self.their_move == 'scissors':
return "rock"
if HumanPlayer_choice == "cycle" :
game = Game(Player(), cycleplayer())
game.play_game()
Это ошибкаЯ получаю.
Возникло исключение: у объекта 'function' AttributeError нет атрибута 'my_move'
Я знаю, что мне нужно использовать функцию init с функцией learnфункция, чтобы заставить это работать, но я не уверен, как.