Build a Player Interface - Build a Player Interface

Tell us what’s happening:

I’m stuck on tests 11-13 for this one, but all the other tests seemed to clear. I feel like I’ve tried everything and then some. Any help is appreciated. Thank you!

Tests 11-13:
11. The Player’s make_move method should update the position attribute by adding to it the coordinates of the randomly selected move.
12. The Player’s make_move method should append the new position tuple to the path attribute.
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):
        move = random.choice(self.moves)
        new_x = self.position[0] + move[0]
        new_y = self.position[1] + move[1]
        self.position = (new_x, new_y)
        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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36

Challenge Information:

Build a Player Interface - Build a Player Interface

pawn = Pawn()
pawn.make_move()

Test your function like this. What do you see in the console?

Traceback (most recent call last):
File “main.py”, line 32, in
File “main.py”, line 11, in make_move
NameError: name ‘random’ is not defined

That’s what the console gave me. Did I put it in the wrong spot? I put it all the way at the bottom of the code

You did it correctly. Those lines are instantiating your class and calling a method.

This shows that there’s an error in your code. Look at line 11 and think how the error message is related

line 11
 ‘random’ is not defined

random does not exist, so you need to add something to your code. Maybe review a previous lesson that talks about random or a previous lab or workshop where you used random

Thanks! Took me some time to figure it out but I finally got it! :grinning_face:

it gives me a lot of sweat to figure it out.