2003 Canadian Computing Competition, Stage 1
Problem J3/S1: Snakes and Ladders
Here (see illustration) is a game board for the game Snakes and Ladders. Each player throws a pair of dice to determine how many squares his/her game piece will advance. If the piece lands on the bottom of a ladder, the piece moves up to the square at the top of the ladder. If the piece lands on the top of a snake, the piece "slides" down to the square at the bottom of the snake. If the piece lands on the last square. The player wins. If the piece cannot advance the number of squares indicated by the dice, the piece is not moved at all.
In order to help you play this game via a cell phone while travelling, you will write a program that simulates your moves on the board shown and, of course, runs on your handheld computer. You will repeatedly throw the dice and enter the result into the program. After each throw the program will report the number of the square where your piece lands.
When the program starts it should assume the piece is on square 1. It should repeatedly read input from the user (a number between 2 and 12) and report the number of the square where the piece lands. In addition, if the piece moves to the last square, the program should print "You Win!" and terminate. If the user enters 0 instead of a number between 2 and 12, the program should print "You Quit!" and terminate.
For clarity, you are to use the board pictured above and you should note that the board has 3 snakes (from 54 to 19, from 90 to 48 and from 99 to 77) and 3 ladders (from 9 to 34, from 40 to 64 and from 67 to 86).
Sample Input
9 11 12 7 3 5 10 9
Sample Output
You are now on square 10 You are now on square 21 You are now on square 33 You are now on square 64 You are now on square 86 You are now on square 91 You are now on square 91 You are now on square 100 You Win!
All Submissions
Best Solutions
Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 27, 2008
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)
On my machine, the code runs perfectly. I have verified that all the ladders/snakes work as expected, and all the conditions are met. Could anyone have a look?
Thanks.
I will personally not respond to any future help requests if I determine you haven't done sufficient testing on your own. (This doesn't mean to just run it on the sample; it also means to write your own test cases with input and expected output, and check that your code works properly.)
Sorry for the trouble jargon.
Will be more careful.
Thanks.
"If the piece cannot advance the number of squares indicated by the dice, the piece is not moved at all."