Question
Question 4 (15 points): Purpose: To reuse and adapt code for another purpose. Degree of Diculty: Moderate. You really need to understand the code from
Question 4 (15 points):
Purpose: To reuse and adapt code for another purpose.
Degree of Diculty: Moderate. You really need to understand the code from Q3 to do this. Only a few
functions need to be changed, but you could go far o track.
Textbook: Chapter 2, 3
The replay les were generated at random by a simple Python script. In other words, there was no one
playing the game, trying to get the prize (G) and escape without dying. As you may have noticed, some
of the replays end before the whole movement string is processed. Thats a dead give-away!
In this question, you will adapt and reuse code in the original replay script to create an interactive version
of the game, which will allow players to play, rather than to watch a replay.
The game has to start with a dungeon, so we have provided a few examples. The dungeon data les are
simply replay les with the movement string deleted. For example:
4
G 2 0
P 3 0
P 1 1
W 2 1
Task
Implement an interactive version of the script, as follows:
1. Make a copy of your well-documented version of previous question, and modify it so that it reads a
dungeon le, and interacts with the user to play the game. A dungeon le is simply a replay le without
any movement information. Your program will keep track of where the player is, provide descriptions
of the rooms, as appropriate, and ask the user for a direction to move (in contrast, the replay script
used the moves recorded in the replay le).
You may have to modify the doc-strings of any functions you modied, and provide doc-strings for
any functions you added. Use the CMPT 145 standards!
2. So maybe youre not a fan of Star Wars. Make a copy of the starwars.py script (which contains all
dialogue used in the game), and modify the strings to make your version of the game.
3. Change the score returned at the end of the game, as follows:
If the player dies, the score is -1000.
If the player collects the prize and returns to the start, the players score is 1000n where n is the
number of steps taken in total. In other words, a short path to the prize and back is best!
If the player returns to the start without dying, but without collecting the prize, the players score
is (T2 n)n, where n is the number of steps taken in total, and T is the size of the dungeon. This
formula rewards longish paths, but penalizes very short paths (encouraging the player to explore)
and penalizes very long paths (discouraging the player from getting a high score moving back
and forth). For example, in a 4 4 dungeon (T = 4) a player returns to the start after 10 moves
(n = 10), the score will be 10 (42 10) = 60.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started