Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Dungeon Game - Extra Credit

Extra Credit Change your player to a dictionary with a key that holds onto where the player has been. Then, when drawing the map, show . for every cell they've been in.

Could someone point me in the right direction for correctly unloading the dictionary and looping over it. I may just be doing it in the wrong place.

Thanks

https://w.trhou.se/khp046c7jf

3 Answers

Alright buddy, I figured out your problem. Your draw maps was the only thing wrong. You had two for loops that as the program went on, the map was just getting exponentially bigger. Loops are tricky to debug. What was happening was you were going through the previous moves list for the 9 indices of the cell list. So it was looping 9 times on the first go, then 18, then 27, then 36, etc. I changed it to one loop for you. I noticed the only reason for the second loop was to clear the previous 'X' where the player was. I switched your variable to hold one value and just compared to that one value every step. You are in action now.

Here is my workspace file

Thanks for your help. However, the link you posted is broken.

I thought I needed the second for loop in order to unpack the dictionary (PREVIOUS_MOVES)?

Here is my link. http://w.trhou.se/nhh57eqoyq

Sorry about that. I am still trying to figure out how to work this website. Anyways though, The solution I came up with isn't the only solution possible. That is just how my thoughts work. I haven't done any python on Treehouse, so I'm not sure what is required or not. Based on your program, the two for loops was your problem. The only thing you need the previous move for was to remove the X from the map were the player was previously. So you don't need a list. You just need the last move. Although, if you want to use a list, don't loop through it. Just get the last element in the list.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Hey Hunter Kiely. What you have is really close. I like the idea of recording when the player was in a spot previously. Only problem there would be if they backtrack, you'd lose the first time they went to that spot.

Anyway, you're doing this loop through PREVIOUS_MOVES.items() when you really don't need to. When you're drawing the map, if they player isn't in the spot, then check to see if the spot is in PREVIOUS_MOVES. Like this:

for idx, cell in enumerate(CELLS):
      if idx in [0, 1, 3, 4, 6, 7]:
        if cell == player:
          print(tile.format('X'), end='')     # cell isnt going to go to a new line
        elif cell in PREVIOUS_MOVES.values():
          print(tile.format('.'), end='')
        else:
          print(tile.format('_'), end='')     # cell isnt going to go to a new line
      else:
        if cell == player:                    
          print(tile.format('X|'))            #rightmost cell, going to a new line
        elif cell in PREVIOUS_MOVES.values():
          print(tile.format('.'), end='')
        else:
          print(tile.format('_|'))            #eightmost cell, going to a new line

Thanks for your help. Looping over the values is much simpler.

Hey Kenneth. I haven't watched your python tracks. I just knew the python language. I was trying to help Hunter get his code working. I am still curious why you put a dot for the previous move. Can you explain the use of that for me? I didn't see the reason for having it.

Trevor, I just pasted the instructions to the extra credit assignment at the top of the page where my original question was.

Oh ok. That makes sense now.