Build a Player Interface - Failing test 11 to 13

Tell us what’s happening:

My code fails to pass test 11 to 13. I’m defining make_move method, calculating the new position, updating the path and returning the position.

Do you have any ideas why it is failing?

Your code so far

from abc import ABC, abstractmethod
from random import choice

class Player(ABC):
    def __init__(self):
        self.moves = []
        self.position = (0, 0)
        self.path = [self.position]
    
    def make_move(self) -> tuple:
        move = random.choice(self.moves)
        new = (self.position[0] + move[0],
               self.position[1] + move[1])
        self.position = new  #  (new_x, new_y)
        self.path.append(self.position)
        return self.position

    @abstractmethod
    def level_up(self):
        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.extend([
            (1, 1),
            (1, -1),
            (-1, 1),
            (-1, -1)
        ])


#player = Player()
#print(player.moves)
pawn = Pawn()
print(pawn.moves)
pawn.level_up()
print(pawn.moves)

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36

Challenge Information:

Build a Player Interface - Build a Player Interface

Welcome to the forum @OCFelisola !

Try just importing random.

Happy coding!

1 Like

Thank you @dhess. You were right!