Build a Player Interface - Build a Player Interface

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.

  1. 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

If you open browser’s console (not the console on page) there’s some details available regarding the failing tests.

You can also create instance of the class and try using method in question, ie:

p = Pawn()
p.make_move()

Oooh god that was such a simple fix, I guess I should start being careful and not assume everything loads in automatically from now on.
In any case I got it to pass, thank you!

1 Like

Maybe I’m using it wrong but most of the time it just says “Assertion failed” without any other helpful details. How do you figure out what the expected and actual values are for the failing tests?

Hey @hnngaf,

if you need help with this challenge, for convenience, please new thread. Preferably via clicking Get Help and Ask for Help in the challenge.

Thank you @sanity but I managed to pass the challenge in the end. I did check this thread when some of the tests were failing (since this is the only one for this challenge). All in all I am left wondering how exactly you use the browser’s console to figure out what is wrong when all it seems to say most of the time is that yes, something is indeed wrong :slight_smile: . Is there a way to see what a test actually asserts?

Please start new thread for your questions.