Tell us what’s happening:
I have tried several different ways but none of them work, if someone can figure out what this test wants, please help.
- The Player’s make_move method should update the position attribute by adding to it the coordinates of the randomly selected move.
Waiting:12. The Player’s make_move method should append the new position tuple to the path attribute.
Waiting:13. The Player’s make_move method should return the updated position attribute.
Your code so far
from abc import ABC, abstractmethod
class Player(ABC):
"""abstract class defining the player"""
def __init__(self) -> None:
self.moves = []
self.position = (0, 0)
self.path = [self.position]
def make_move(self) -> tuple:
move = random.choice(self.moves)
#new_position = tuple(sum(x) for x in zip(self.position, move))
#self.position = new_position
new_position = (self.position[0] + move[0], self.position[1] + move[1])
"""new_x = self.position[0] + move[0]
new_y = self.position[1] + move[1]
self.position = (new_x, new_y)"""
self.position = new_position
self.path.append(self.position)
return self.position
@abstractmethod
def level_up(self) -> None:
pass
class Pawn(Player):
def __init__(self):
super().__init__()
self.moves = [(0, 1), (0, -1), (-1, 0), (1, 0)]
def level_up(self):
self.moves += [(1, 1), (1, -1), (-1, -1), (-1, 1)]
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Challenge Information:
Build a Player Interface - Build a Player Interface