Problem F
Snakes and Ladders

Write a program that plays the legendary board game, Snakes and Ladders.
The game is played on a board with exactly
The rules of the game are as follows:
-
In each turn, a player rolls a die and moves forward by the same number of squares as indicated by the die.
-
After having moved, if the player is located at the bottom of a ladder, the player moves up the ladder. If a player is instead located at the head of a snake, the player moves down to the tail of the snake.
-
If a player rolls
, then that player gets to roll the die again. It doesn’t matter if the player just moved up a ladder or down a snake, they are still entitled to another roll. -
The player who is first to reach the last square wins.
-
If a player is close to the last square and overshoots by rolling a number higher than required, then the player still moves to square
and wins the game.
The starter code includes a main()
function and a function named roll_die() that shall be used to simulate the
rolling of a single
Input
First the program should prompt the user for
The second part of the input contains
If
Lastly the program should prompt the user for two names,
In the tests
Output
For each turn of the game the program should output the rolls and locations of the players as such:
-
“{
} rolled { } and is now at { }.”
where
-
“Darn! A snake brought {
} down to square { }.” -
“Splendid! {
} climbed a ladder up to square { }.”
where
-
“{
} won the game.”
Sample Input 1 | Sample Output 1 |
---|---|
9 21 75 30 60 7 18 67 30 85 94 89 60 50 75 11 26 52 16 Joseph Donald |
Joseph rolled 5 and is now at square 5. Donald rolled 5 and is now at square 5. Joseph rolled 6 and is now at square 11. Splendid! Joseph climbed a ladder up to square 26. Joseph rolled 3 and is now at square 29. Donald rolled 5 and is now at square 10. Joseph rolled 5 and is now at square 34. Donald rolled 6 and is now at square 16. Donald rolled 2 and is now at square 18. Joseph rolled 3 and is now at square 37. Donald rolled 4 and is now at square 22. Joseph rolled 6 and is now at square 43. Joseph rolled 3 and is now at square 46. Donald rolled 3 and is now at square 25. Joseph rolled 4 and is now at square 50. Splendid! Joseph climbed a ladder up to square 75. Donald rolled 6 and is now at square 31. Donald rolled 2 and is now at square 33. Joseph rolled 6 and is now at square 81. Joseph rolled 3 and is now at square 84. Donald rolled 1 and is now at square 34. Joseph rolled 4 and is now at square 88. Donald rolled 6 and is now at square 40. Donald rolled 4 and is now at square 44. Joseph rolled 1 and is now at square 89. Darn! A snake brought Joseph down to square 60. Donald rolled 5 and is now at square 49. Joseph rolled 6 and is now at square 66. Joseph rolled 6 and is now at square 72. Joseph rolled 3 and is now at square 75. Donald rolled 4 and is now at square 53. Joseph rolled 4 and is now at square 79. Donald rolled 6 and is now at square 59. Donald rolled 3 and is now at square 62. Joseph rolled 6 and is now at square 85. Splendid! Joseph climbed a ladder up to square 94. Joseph rolled 1 and is now at square 95. Donald rolled 3 and is now at square 65. Joseph rolled 5 and is now at square 100. Joseph won the game. |