Build a Player Interface - Build a Player Interface

Tell us what’s happening:

I have tried to cross reference from others having the same issue but cannot get tests 11, 12, or 13 to pass can I get some help understanding what is going on cause I am running out of ideas of what to do

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]
    def make_move(self) -> tuple:
        move = random.choice(self.moves)
        new_position = (self.position[0] + move[0], self.position[1] + move[1])
        self.position = new_position
        self.path.append(self.position)
        return 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

Here are some debugging steps you can follow. Focus on one test at a time:

  1. Are there any errors or messages in the console?
  2. What is the requirement of the failing test?
  3. Check the related User Story and ensure it’s followed precisely.
  4. What line of code implements this?
  5. What is the result of the code and does it match the requirement? (Write the value of a variable to the console at that point in the code if needed.)

If this does not help you solve the problem, please reply with answers to these questions.

there are no errors in the console, path and position attributes are not being updated, the story is being followed to a tee, lines 11, 12, and 13 are what is affecting it, and the code will not update correctly so i dont know what i am missing I went through all of those steps earlier

What is the requirement of the failing test? (The first one, Test 11)

Ok, but answering these questions is a nice way to tee up the problem when you are asking for help

this is 11 The Player’s make_move method should update the position attribute by adding to it the coordinates of the randomly selected move.

Ok, here is the related User Story

  1. The Player class should have a method named make_move that:
  • Uses random.choice to get a random move from the moves attribute (defined in the concrete class).
  • Adds the values from the selected move to the current position and updates the position attribute.
  • Appends the new position tuple to the path attribute.
  • Returns the new position.

Can you share which lines of code implement this? You can paste them in to a new comment here?

I’ll do it, it’s this?

def make_move(self) -> tuple:
        move = random.choice(self.moves)
        new_position = (self.position[0] + move[0], self.position[1] + move[1])
        self.position = new_position
        self.path.append(self.position)
        return position

yes thats it and i think that that is the source of the rest of the issues as well im just not sure whats wrong with it. move = random.choice(self.moves) is what accomplishes part one the math on new_position is what accomplishes part 2 and append and return are the last two lines right in there

Sorry, still trying to comprehend what this project is all about.

I spotted something else though:

  1. The Pawn class should implement a concrete level_up method by adding more moves to the moves attribute.

moves is a list?

How do you add an item to the end of a list?
How do you add a list of items to the end of a list?

extend and append but that is already implemented in the code and is specifically requested so im unsure of what the next step would be

Where?

Regarding the new_position your code looks ok to me, maybe try testing it and printing out your values to make sure everything is happening correctly?

p = Pawn()
p.make_move()

print move and self.position and new_position to see if it all makes sense?

when i add the print calls it causes an error before post proccessing

You’re making me ask an obvious question but here goes… What error?

im not sure because no matter where i check the error code wont show ive had this issue for a couple of levels

i can say without a doubt that i have never had a print kill my whole code though

ok it says something like “Your code generated an error before it could be run” ?

i just reloaded the whole app and the error codes are back it is saying that they are undefined

Ok please share your updated code?

<p>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) -> tuple:
        move = random.choice(self.moves)
        new_position = (self.position[0] + move[0], self.position[1] + move[1])
        self.position = new_position
        self.path.append(self.position)
        return 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)]
print(self.position)<p>

Ok, test it. Add this after your code

p = Pawn()
p.make_move()

Do you get an error?

yeah it gives me a name error claiming that position is not defined

1 Like