Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online
Course Modul… Final Pr… Snakes…
Snakes and Ladders Part 2
WARNING: For the purposes of Academic Integrity, the Õnal project is treated like a Õnal exam. This means penalties are increased for any academic oàences (including, but not limited to receiving 0 in the entire course!) You have been warned.

Part 2: Playing Snakes and Ladders

In this question, you will implement a working version of a two-person game of Snakes and Ladders, using a provided (correct) implementation of Gameboard class and load_gameboard function from Part 1, rather than your own version.
To use the load_gameboard function from Gameboard , use Gameboard.load_gameboard .
Players alternate turns, in their attempt to move from position 1 to the END position. The value of END depends on the size of the board (if each row has has squares, then END is ).

Debugging Mode

Players will have the option of playing the game on debugging mode, which allows for die rolls to be provided, rather than being random. Choose this option when testing your code, so that you can more easily check what happens in special situations. You'll be able to provide the roll values instead
of hoping a useful roll happens.

Turns

On each turn, a player chooses between three possible actions:

1. Roll a die

  
2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online
https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c77069… 2/21

2. Print the board to the screen

3. Suspend the game and write the Õle to the board

More details about the various game components are included below.
1. (r) Roll a die

A player rolls a six-sided die (which gives an integer between 1 and 6, inclusive). Player moves the number of places on the board (for example, if the player is on position 40, and rolls 4, they move 4 positions to land on position 44). After landing on the new position:

If the player lands on the head of a snake, the player moves to the tail of the snake, a lower numbered position. A message will be printed showing all squares on the snake.
If the player lands on the bottom of a ladder, the player moves to the top of the ladder, a higher numbered position. A message will be printed showing all squares on the ladder.
Note that only the head of a snake or bottom of a ladder require the snake and ladder processing. It is not done for any other snake or ladder square.
If the player had rolled a 6, they must roll again, and the same rules apply (including another roll if they roll 6 a third time, etc. ) Before rolling again, call update_player_position to update the location before the player is given the option to roll, print, or suspend.

Note: If player rolls a 6, move the 6 places Õrst, account for a snake or ladder, call update_player_position before rolling the die again.

Once the player position has been Õnalized, call the update_player_position function from Gameboard .

2. (p) Print the board to the screen

Use the output_to_screen function from Gameboard class to print the current board to the screen

3. (s) Suspend the game and write the Õle to the board

The player is asked for the name of the Õle to save the current board to (for example game2598.txt ), and the output_to_file function from the Gameboard class is called. Recall the current player will also be printed by that function.

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c77069… 3/21

Ending the game

The game ends when one player Õnishes on position END after a processing a full roll of a die. The player's roll must bring them exactly to the END position.
If the roll is more than needed to land exactly on position END, then all steps must still be used: move to the END position and then move backwards from the end.
For example, if END=100, and the player is on 97, and they roll 5, then they must move 5 spots total: 98, 99, 100, 99, 98. So, they end at 98, and the board should be updated appropriately.
If a player lands on END exactly with a roll of 6, the player does not roll again, and the game ends. This is an exception to the “roll 6” rule.

Required functions

play_game consumes and returns None
Start by asking the player if they want to play in debugging mode, which allows for easier testing. Then, ask for the name of the Õle containing the Snakes and Ladders board, and open that Õle using load_gameboard from Gameboard . Assume that the Õle exists and has a valid format.
Player take turns. They should be prompted by a menu for the game, and the player's choice of action is processed:
rolling a die printing the board or suspending the game.
If a player lands on the start of a snake or ladder, a message is printed about the changing positions. If a player chooses to print the board, it is still their turn until they roll a die.
The game ends when one of the players lands on END, following the end of game rules, or when the game is suspended. A closing message is printed, depending on how it was ended.
Be sure to use the provided string constants when printing messages or prompts. Review to the sample game plays to see the print statements for each part of the game.

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c77069… 4/21

Note: To assist with completing the function play_game , you must implement the functions that follow (which will each be tested independently) before completing play_game :

find_ladder – consumes a Gameboard b , and a position, pos , and returns the label of the ladder with its bottom at pos , if one exists, and returns False otherwise.
find_snake – consumes a Gameboard b , and a position, pos , and returns the label of the snake with its head at pos , if one exists, and returns False otherwise.
choose_action – prints out the possible actions for the player, and reads and returns one of ‘r’, ‘p’, ‘s’ for player action. If an invalid choice is entered, the player is prompted to enter the choice again until an acceptable value is entered.
A few simple helper functions and constants are provided for your assistance. See details in the provided code.
player_status - prints a message with each player's location on the board.
roll returns a number between 1 and 6 corresponding to the roll of a die. If the game is in debugging mode, the player will provide the value of the die roll. Otherwise, a random die roll is simulated. The function parameter is a Boolean value: True if in debugging mode, and False if in playing mode.
Sample game runs are provided below the following assignment block

Testing Data

The following boards can be used to help with testing (these are the boards used in the examples below). Add a Õle as you did in module 10. You should create other boards for testing as well, to ensure each situation is tested suÞciently. While you do not need to provide evidence of testing, it is deÕnitely needed to meet the requirements of the game.

Sample 1:

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c77069… 5/21

|||||||||||||||||||||||||||||||
|| 16 | 15 | 14 | 13 ||
|| | s1 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 9 | 10 | 11 | 12 ||
|| | s2 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 8 | 7 | 6 | 5 ||
|| s2 | | l1 | ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 1 | 2 | 3 | 4 ||
|| | l1 | l2 | l2 ||
!! p1p2 | | | !!
|||||||||||||||||||||||||||||||
p1
Sample 2:
|||||||||||||||||||||||||||||||
|| 16 | 15 | 14 | 13 ||
|| | s1 | s1 | l1 ||
!! | | | p1 !!
|||||||||||||||||||||||||||||||
|| 9 | 10 | 11 | 12 ||
|| | s2 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 8 | 7 | 6 | 5 ||
|| s2 | | l1 | ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 1 | 2 | 3 | 4 ||
|| | l1 | l2 | l2 ||
!! p2 | | | !!
|||||||||||||||||||||||||||||||
p1

Sample 3:

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c77069… 6/21

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||
|| 100 | 99 | 98 | 97 | 96 | 95 | 94 | 93 |
92 | 91 ||
|| l6 | | s7 | | | | s6 | s6 |
s6 | l7 ||
!! | | | | | | | |
| !!
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||
|| 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 |
89 | 90 ||
|| l6 | l3 | s7 | s7 | | l5 | | s2 |
s6 | l7 ||
!! | | | | | | | |
| !!
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||
|| 80 | 79 | 78 | 77 | 76 | 75 | 74 | 73 |
72 | 71 ||
|| l6 | s7 | l3 | | | l5 | | s2 |
| s6 ||
!! | | | | | | | |
| !!
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||
|| 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |
69 | 70 ||
|| | s3 | | l3 | | | s2 | |
l4 | s6 ||
!! | | | | | | | |
| !!
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||
|| 60 | 59 | 58 | 57 | 56 | 55 | 54 | 53 |
52 | 51 ||
|| | s3 | | s5 | l3 | | s2 | l4 |
s4 | ||
!! | | | | | | | |
| !!
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||
|| 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
49 | 50 ||
|| | s3 | s5 | | s2 | l3 | l4 | |

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c77069… 7/21

s4 | ||
!! | | | | | | | |
| !!
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||
|| 40 | 39 | 38 | 37 | 36 | 35 | 34 | 33 |
32 | 31 ||
|| s5 | s3 | s5 | | s2 | | l3 | |
s4 | s4 ||
!! | | | | | | | |
| !!
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||
|| 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 ||
|| l1 | s3 | | s2 | | | | l3 |
s4 | l2 ||
!! | | | | | | | |
| !!
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||
|| 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 |
12 | 11 ||
|| | l1 | s2 | s1 | s1 | s1 | s1 | s1 |
l2 | ||
!! | | | | | | | |
| !!
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||
|| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 ||
|| | | l1 | | | | | l2 |
| ||
!! p1p2 | | | | | | | |
| !!
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||
p1
main.py - Add File
No submissions found
import random
import Gameboard
1 2 3 4

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c77069… 8/21

##########################################################################
## String constants
## Messages for testing mode
debugging_question = "Do you want to play the game in debugging mode? Ente
debugging_msg = "Enter a die value between 1 and 6: "
## Messages involving files
request_load = "Enter name of file to load board: "
request_write = "Enter name of file to save board: "
## Messages regarding menu options
## Note: Use these as prompts for input - do not use print for these strin
menu_prompt = "Enter r, p, s for your choice: "
menu_prompt_again = "Invalid response. Enter r, p, s for your choice: "
## Use format to add player number
## Note: use print to display the menu
menu = "Player {0}: You may (r) roll a die, or (p) print the current board
valid_actions = 'rps'
## Use format to indicate player, die roll, spaces past END, END, and new_
end_back_msg = "Player {0} rolls {1} and moves {2} spaces past {3} and goe
## Use format to indicate player, die roll, and new position
basic_roll = 'Player {0} rolls {1}, and moves to position {2}'
## Use format to indicate player and snake/ladder final position
stop_msg = "Player {0} stops at position {1}"
## Use format to indicate player and start of ladder or snake
ladder_start_msg1 = "Hurray! Player {0} landed on ladder {1} starting at p
snake_start_msg1 = "Uh oh! Player {0} landed on snake {1} starting at posi
## Message for processing snakes/ladders
ladder_start_msg2 = "Climbing..."
snake_start_msg2 = "Falling..."
## Use format to indicate snake/ladder interior positions
continue_msg = "through {0}, "
4 5 6 7 8 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c77069… 9/21

Run Code Save Code Reset Code Show History
Visualize
Submit Code View Submissions
In all the examples below, user input is denoted in bold . Explanations of the
code are written in
text boxes
and should not be printed.
Note the following when reviewing the examples.
There are no blank lines printed when playing the game. In the
examples, it may look like there are blank lines before and
after the board when it is printed to the screen, but there are
not.
Example #1: Game play with no rolls of 6, no landing on snakes or ladders
Code Output
## Use format to indicate player gets to roll after moving to new position
six_msg = "Player {0} gets to roll again"
## Use format to indicate player suspending the game
choose_suspend = "Player {0} has suspended the game"
45
46
47
48
49
50

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c7706… 10/21

>>> play_game()
First, prompt for gameboard file to load, and
print player positions and the current board.
Do you want to play the game in debugging mode? Enter y
(yes) or n (no).
n
Enter name of file to load board: game4x4.txt
Player 1 at position: 1. Player 2 at position: 1
|||||||||||||||||||||||||||||||
|| 16 | 15 | 14 | 13 ||
|| | s1 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 9 | 10 | 11 | 12 ||
|| | s2 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 8 | 7 | 6 | 5 ||
|| s2 | | l1 | ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 1 | 2 | 3 | 4 ||
|| | l1 | l2 | l2 ||
!! p1p2 | | | !!
|||||||||||||||||||||||||||||||
Player 1 rolls 5 to move to position 6, then
Player 2 rolls 3 to move to position 4.
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p1 rolls 5, and moves to position 6
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p2 rolls 3, and moves to position 4
Player p1: You may(r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
p

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c7706… 11/21

|||||||||||||||||||||||||||||||
|| 16 | 15 | 14 | 13 ||
|| | s1 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 9 | 10 | 11 | 12 ||
|| | s2 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 8 | 7 | 6 | 5 ||
|| s2 | | l1 | ||
!! | | p1 | !!
|||||||||||||||||||||||||||||||
|| 1 | 2 | 3 | 4 ||
|| | l1 | l2 | l2 ||
!! | | | p2 !!
|||||||||||||||||||||||||||||||
Players take turns rolling the die until one
lands exactly on position 16.
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p1 rolls 1, and moves to position 7
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p2 rolls 1, and moves to position 5
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p1 rolls 2, and moves to position 9
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p2 rolls 2, and moves to position 7
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p1 rolls 3, and moves to position 12
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p2 rolls 4, and moves to position 11

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c7706… 12/21

Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p1 rolls 4, and moves to position 16
Game over. Player lands on END.
Game over!
Player 1 wins!
Example #2: Gameplay with some special actions

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c7706… 13/21

>>> play_game()
Do you want to play the game in debugging mode? Enter y
(yes) or n (no).
n
Enter name of file to load board: gb4x4.txt
Player 1 at position: 1. Player 2 at position: 1
|||||||||||||||||||||||||||||||
|| 16 | 15 | 14 | 13 ||
|| | s1 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 9 | 10 | 11 | 12 ||
|| | s2 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 8 | 7 | 6 | 5 ||
|| s2 | | l1 | ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 1 | 2 | 3 | 4 ||
|| | l1 | l2 | l2 ||
!! p1p2 | | | !!
|||||||||||||||||||||||||||||||
When a player rolls 6, they move, and roll again
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p1 rolls 6, and moves to position 7
Player p1 gets to roll again
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p1 rolls 2, and moves to position 9
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p2 rolls 6, and moves to position 7
Player p2 gets to roll again
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p2 rolls 2, and moves to position 9

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c7706… 14/21

Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p1 rolls 3, and moves to position 12
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p2 rolls 3, and moves to position 12
Player landed on a snake!
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p1 rolls 3, and moves to position 15
Uh oh! Player p1 landed on snake s1 starting at position 15
Falling...through 15, through 14, through 11, Player p1
stops at position 11
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
p
|||||||||||||||||||||||||||||||
|| 16 | 15 | 14 | 13 ||
|| | s1 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 9 | 10 | 11 | 12 ||
|| | s2 | s1 | l1 ||
!! | | p1 | p2 !!
|||||||||||||||||||||||||||||||
|| 8 | 7 | 6 | 5 ||
|| s2 | | l1 | ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 1 | 2 | 3 | 4 ||
|| | l1 | l2 | l2 ||
!! | | | !!
|||||||||||||||||||||||||||||||
Player moved past END
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c7706… 15/21

Enter r, p, s for your choice: r
Player p2 rolls 6 and moves 2 spaces past 16 and goes back
to 14
Player p2 gets to roll again
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p2 rolls 1, and moves to position 15
Uh oh! Player p2 landed on snake s1 starting at position 15
Falling...through 15, through 14, through 11, Player p2
stops at position 11
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
p
|||||||||||||||||||||||||||||||
|| 16 | 15 | 14 | 13 ||
|| | s1 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 9 | 10 | 11 | 12 ||
|| | s2 | s1 | l1 ||
!! | | p1p2 | !!
|||||||||||||||||||||||||||||||
|| 8 | 7 | 6 | 5 ||
|| s2 | | l1 | ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 1 | 2 | 3 | 4 ||
|| | l1 | l2 | l2 ||
!! | | | !!
|||||||||||||||||||||||||||||||
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p1 rolls 4, and moves to position 15
Uh oh! Player p1 landed on snake s1 starting at position 15
Falling...through 15, through 14, through 11, Player p1
stops at position 11
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p2 rolls 6 and moves 1 spaces past 16 and goes back
to 15
Uh oh! Player p2 landed on snake s1 starting at position 15

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c7706… 16/21

Falling...through 15, through 14, through 11, Player p2
stops at position 11
Player p2 gets to roll again
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p2 rolls 5, and moves to position 16
Game over!
Player 2 wins!
Example #3: Gameplay with suspend and ladder

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c7706… 17/21

>>> play_game()
Do you want to play the game in debugging mode? Enter y
(yes) or n (no).
n
Enter name of file to load board: gb4x4.txt
Player 1 at position: 1. Player 2 at position: 1
|||||||||||||||||||||||||||||||
|| 16 | 15 | 14 | 13 ||
|| | s1 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 9 | 10 | 11 | 12 ||
|| | s2 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 8 | 7 | 6 | 5 ||
|| s2 | | l1 | ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 1 | 2 | 3 | 4 ||
|| | l1 | l2 | l2 ||
!! p1p2 | | | !!
|||||||||||||||||||||||||||||||
Player landed on a ladder!
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Player p1 rolls 1, and moves to position 2
Hurray! Player p1 landed on ladder l1 starting at position 2
Climbing...through 2, through 6, through 12, through 13,
Player p1 stops at position 13
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
p
|||||||||||||||||||||||||||||||
|| 16 | 15 | 14 | 13 ||
|| | s1 | s1 | l1 ||
!! | | | p1 !!
|||||||||||||||||||||||||||||||
|| 9 | 10 | 11 | 12 ||
|| | s2 | s1 | l1 ||

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c7706… 18/21

!! | | | !!
|||||||||||||||||||||||||||||||
|| 8 | 7 | 6 | 5 ||
|| s2 | | l1 | ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 1 | 2 | 3 | 4 ||
|| | l1 | l2 | l2 ||
!! p2 | | | !!
|||||||||||||||||||||||||||||||
Game suspended.
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
s
Player p2 has suspended the game
Enter name of file to save board:
gb2598-paused.txt
Game suspended
Example #4: Gameplay with re-loading a suspended game, and with invalid
player input

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c7706… 19/21

>>> play_game()
Suspended game re-loaded to continue play from
player 2. Note that player 1 is not at position
1 to start.
Do you want to play the game in debugging mode? Enter y
(yes) or n (no).
n
Enter name of file to load board: gb2598-paused.txt
Player 1 at position: 13. Player 2 at position: 1
|||||||||||||||||||||||||||||||
|| 16 | 15 | 14 | 13 ||
|| | s1 | s1 | l1 ||
!! | | | p1 !!
|||||||||||||||||||||||||||||||
|| 9 | 10 | 11 | 12 ||
|| | s2 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 8 | 7 | 6 | 5 ||
|| s2 | | l1 | ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 1 | 2 | 3 | 4 ||
|| | l1 | l2 | l2 ||
!! p2 | | | !!
|||||||||||||||||||||||||||||||
Player does not enter a valid menu option below.
Player p2: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
don't know what to do
Invalid response. Enter r, p, s for your choice: s
Player p2 has suspended the game
Enter name of file to save board:
gb2598-again.txt
Game suspended
Example #5: Gameplay in debugging mode

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c7706… 20/21

>>> play_game()
Player chooses debugging mode to specify the
rolls of the die.
Do you want to play the game in debugging mode? Enter y
(yes) or n (no).
y
Enter name of file to load board: gb4x4.txt
Player 1 at position: 1. Player 2 at position: 1
|||||||||||||||||||||||||||||||
|| 16 | 15 | 14 | 13 ||
|| | s1 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 9 | 10 | 11 | 12 ||
|| | s2 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 8 | 7 | 6 | 5 ||
|| s2 | | l1 | ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 1 | 2 | 3 | 4 ||
|| | l1 | l2 | l2 ||
!! p1p2 | | | !!
|||||||||||||||||||||||||||||||
Enter a roll of 5 for each player, and print, to
verify same position displays correctly.
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Enter a die value between 1 and 6: 5
Player p1 rolls 5, and moves to position 6
Enter r, p, s for your choice:
r
Enter a die value between 1 and 6: 5
Player p2 rolls 5, and moves to position 6
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
p

2020/12/10 Snakes and Ladders Part 2 | Final Project | CS 116 Courseware | UW Online

https://online.cs.uwaterloo.ca/courses/course-v1:UW+CS116+2020_09/courseware/915a123ba4b34c57977702e1ce75784b/00d262e936994cfbbf63dc97c7706… 21/21

|||||||||||||||||||||||||||||||
|| 16 | 15 | 14 | 13 ||
|| | s1 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 9 | 10 | 11 | 12 ||
|| | s2 | s1 | l1 ||
!! | | | !!
|||||||||||||||||||||||||||||||
|| 8 | 7 | 6 | 5 ||
|| s2 | | l1 | ||
!! | | p1p2 | !!
|||||||||||||||||||||||||||||||
|| 1 | 2 | 3 | 4 ||
|| | l1 | l2 | l2 ||
!! | | | !!
|||||||||||||||||||||||||||||||
Enter a roll of 6 for player 1, twice, then 4 to
finish the game in one more turn.
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Enter a die value between 1 and 6: 6
Player p1 rolls 6, and moves to position 12
Player p1 gets to roll again
Player p1: You may (r) roll a die, or (p) print the current
board, or (s) suspend the game
Enter r, p, s for your choice:
r
Enter a die value between 1 and 6: 4
Player p1 rolls 4, and moves to position 16
Game over!
Player 1 wins