Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
fahad lashari6,771 Points
Question regarding get_locations()
I haven't finished watching the video yet however I cant seem to wrap my head around a small part of the code in the get_locations() function.
Kenneth mentioned that all variables; 'monster', 'start' and 'door' equalling the same can be an issue therefore we need to start again. I understand if monster == start or monster == door then we should restart. However, why must we restart if door == start?
Isn't the logic of the game to not get caught by the monster, and if you are caught then it's game over. It is a possibility that you may be caught right away. This could seem unfair and therefore the first two conditions in the if statement eliminate that possibility. The question remains, why do we need to start again if door == start?
door == start represents winning immediately. It's the opposite of
monster == start which represents losing immediately.
monster == door means it's impossible to win.
All of these conditions are unfair in some way.
Steven Parker217,577 Points
You need to make sure the player has a chance to move.
If the player's position is at the door, then the player wins. So you make sure that start and door are not the same, since otherwise the game is over before the player gets a turn.