Tell us what’s happening:
Hi guys,
I don’t understand what is wrong with the code. I fails the test 11, 12, 13, 23, 25. Basically, like the methods make_move and level_up (from class Pawn) don’t work.
If I try to declare an instance of Player or Pawn, nothing works because abstract class Player/Pawn can’t be initialized with abstract method level_up
Your code so far
from abc import ABC, abstractmethod
import random
class Player(ABC):
def __init__(self):
self.moves = []
self.position = 0,0
self.path = [self.position]
def make_move(self):
move = random.choice(self.moves)
self.position=(self.position[0] + move[0], self.position[1] + move[1])
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)]
@abstractmethod
def level_up(self):
self.moves += [(1, 1), (1, -1), (-1, -1), (-1, 1)]
#player = Player()
#player.make_move()
#pawn = Pawn()
#pawn.make_move()
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 Edg/146.0.0.0
Challenge Information:
Build a Player Interface - Build a Player Interface