Build a Player Interface - Build a Player Interface

Tell us what’s happening:

tests 11,12 and 13 fail even though i tested with an object and it returns position and path correctly

Your code so far

from abc import ABC,abstractmethod
class Player(ABC):
    def __init__(self):
        self.moves=[]
        self.position=(0, 0)
        self.path=[self.position]

    @abstractmethod
    def level_up(self):
        pass

    def make_move(self):
        import random
        random_move=random.choice(self.moves)
        self.position=(self.position[0]+random_move[0],self.position[1]+random_move[1])
        
        self.path.append(self.position)
        return self.position

    

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)])

p=Pawn()
print(p.position)
p.make_move()
print(p.position)
print(p.path)



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build a Player Interface - Build a Player Interface

even if you have imported random inside make_move, I see in the extra output from the tests
NameError: name 'choice' is not defined

maybe you need to have that moved to be a global import

damn it actually worked thanks a lot

how come it fails if random is not global though

I am not sure, it can be some quirk in the testing enviroment

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.