Write a program to allow you to play the game of Ricochet Robots. You can play a similar graphical online version here.
See this YouTube video showing what the program looks like when it is running.
Playing the game should look like the following:
Author: Dale Reed Program 4: RicoRobots in C++ TA: Billie Joe Armstrong, T 6:00 AM March 22, 2018 Welcome to Ricochet Robots ('Ricochet Robot' is a registered trademark of Hans im Glück Munich, Germany, 1999. The game was created by Alex Randolph.) The object of the game is to get the designated numbered robot to the indicated letter position. The numbered squares are all robots. They unfortunately have no brakes, and so will continue in whatever direction they are moving until they encountar an obstacle. For each move enter the robot number and the desired direction. For instance entering 1 U would move the #1 robot up as far as it can go. The first letter of input is the robot number (1 - 4), and the second letter is the direction: (L=left, U=up, R=right, D=down) Enter x to exit. Have fun! Enter 'r' for random robot and goal, 'd' for default or 's' to select: d Move robot 2 to square M ---------------------------------------------------------------- | . . . . . | . . . . . . | . . . . . | | | | . . . | . . . . . . | . . . . . . . | | --- --- --- | | . . . . . . . . . . . . . . . | . | | | | . | . . . . . . . . . . . . . . . | | --- --- | | . . . . . . | . . . . . | . . . . . | |--- --- --- | | . . . . . . . . . . . . . . . 4 | | --- --- | | . . . . . . | . . . . . . | . . . . | | --- --- | | . . . . | . . . | . . | . . . . . . . | | --- | | . . . . . . . | . . | . . . . . . . | | --- --- --- --- | | . . | . . . | . . . . . . . . . . . | | --- | | . . . . . . . . . | . . . . . . . | |--- --- --- | | . . . . . . . . . . . . . | 3 . . | | | | . . . . . . M | . . . . . . . . . | | --- | | . . . . . . . . . | . . . . . . . | | --- --- | | . . | . . . . . . . . . . . . 1 | . | | --- | | . . . . . . | . . . . . . | . . . 2 | ---------------------------------------------------------------- 1. Please enter the robot to move and the direction (e.g. 2 r): 2u Move robot 2 to square M ---------------------------------------------------------------- | . . . . . | . . . . . . | . . . . . | | | | . . . | . . . . . . | . . . . . . . | | --- --- --- | | . . . . . . . . . . . . . . . | . | | | | . | . . . . . . . . . . . . . . . | | --- --- | | . . . . . . | . . . . . | . . . . . | |--- --- --- | | . . . . . . . . . . . . . . . 4 | | --- --- | | . . . . . . | . . . . . . | . . . . | | --- --- | | . . . . | . . . | . . | . . . . . . . | | --- | | . . . . . . . | . . | . . . . . . . | | --- --- --- --- | | . . | . . . | . . . . . . . . . . . | | --- | | . . . . . . . . . | . . . . . . 2 | |--- --- --- | | . . . . . . . . . . . . . | 3 . . | | | | . . . . . . M | . . . . . . . . . | | --- | | . . . . . . . . . | . . . . . . . | | --- --- | | . . | . . . . . . . . . . . . 1 | . | | --- | | . . . . . . | . . . . . . | . . . . | ---------------------------------------------------------------- 2. Please enter the robot to move and the direction (e.g. 2 r):
I have created a sample program to get you started. It reads in the datafile and displays the board, and moves the robot #2 upwards one square. Pay careful attention to how the board is stored. Both the board display characters and the walls are stored in the same 2-dimensional array, with constants used as indexes to references the different aspects of each square. See also this pictoral description of the board representation.
For full credit (10 points of the programming style Data and Control Structures category) you will need to transform the above sample code into a version that uses C++ classes.
When selecting 'd' for the default game values, the default values should be selected to move robot 2 to square M. Selecting 'r' should give different values each time the program is run. Choosing 's' allows specifying the values to be used, and should first display the board with all the possible letter destination squares and robot positions shown, such as:
---------------------------------------------------------------- | . . . . . | . . . . . . | . . . . . | | | | . . A | . . . . . . | B . . . . . . | | --- --- --- | | . . . . . . . . . . . . . . C | . | | | | . | D . . . . . . . . . . . . . . | | --- --- | | . . . . . . | E . . . F | . . . . . | |--- --- --- | | . . . . . . . . . . . . . . . 4 | | --- --- | | . . . . . G | . . . . . . | H . . . | | --- --- | | . . . I | . . . | . . | . . . . . . . | | --- | | . . . . . . . | . . | . . . . . . . | | --- --- --- --- | | . J | . . . | K . . . . . . . . . . | | --- | | . . . . . . . . L | . . . . . . . | |--- --- --- | | . . . . . . . . . . . . . | 3 . . | | | | . . . . . . M | . . . . . . . . . | | --- | | . . . . . . . . . | N . . . . . . | | --- --- | | . . | O . . . . . . . . . . . 1 | . | | --- | | . . . . . . | . . . . . . | . . . 2 | ----------------------------------------------------------------
There is no real animation in this program. After the user enters a move, the screen is erased using system("cls") on windows or system("clear") on Mac or Linix, or simply displaying the new screen which causes the old one to scroll off the top. (Once done with everything else in the program, see here for an automatic way to check which system you are on, but you don't need to do this.)
Datafile format:
The datafile must be called board.txt The top three lines of the datafile are comments. The two lines after that describe the number of possible destination squares (15 in the below example). The second line describes the number of "special" squares on the board, that is squares that have some combination of walls and display label (29 in the below example). Note that the side squares don't count for this as "special", as they are handled separately.
After the first five lines, most of the entries give the piece index (reflecting its position on the board), a set of "wall" and 0 characters denoting what is present in each of the piece's four adjacent directions, and an optional alphabetic capital letter to be displayed in that position. The four characters after each piece board position (going from left to right) represent first the left wall, then the top, then the right, then the bottom wall, if any. For example the entry:
18 00|- A
describes the board at square 18, that has nothing to the left (0), nothing above (0), a wall to the right (|), and a line below (-).
Your program must work for any valid data file. We will test your program with a different data file than the one shown below.
# Datafile for RicoRobots program. Top numeric line is the number of special letter characters. # Second numeric line is number of special display characters define below. # The last set of lines define the placement of the numbered robots. 15 29 5 |000 11 |000 18 00|- A 25 |00- B 46 0-|0 C 49 |00- D 64 |00- 70 |-00 E 74 00|- F 95 0-|0 101 0-|0 G 108 |-00 H 115 00|- I 119 |-00 120 0-|0 135 |00- 136 00|- 145 0-|0 J 149 |-00 K 159 00|- 160 |00- 168 00|- L 189 |-00 198 00|- M 217 |00- N 226 |00- O 238 0-|0 246 |00- 252 |00- 238 red 255 green 189 blue 95 yellow
The last four lines are the four robot positions, with robot 1 at position 238, robot 2 at 255, robot 3 at 189, and robot 4 at 95. You can ignore the color information on each line. (The color names are only used if you are implementing the extra credit.)
We will once again use Blackboard for program submissions. The name of the program you will turn in should be your netid followed by Prog5 and the .cpp file extension. In other words, if your netid is reed then your program would be called reedProg5.cpp
You must zip up the code you turn in, as done in previous assignments. For instance zipping up reedProg5.cpp would result in reedProg5.zip which is the file you would turn in. Only turn in this single file, turning it in on Blackboard into the assignment Program 5: Robots
Failing to follow these naming conventions or failing to turn in a zip file will result in a 5 point deduction. (Note that I am not requesting some compression, but specifically zip compression). You may turn in multiple versions, but only the latest version will be graded.
Inside your program itself you must include the following grading rubric, just below your header documentation, as shown below. We will use this when grading your program as a place to annotate and list any deductions taken off within each category. Note that this is in your code but is within a comment block so should not appear on the screen when you run your program.
/* ------------------------------------------------ reedProg5.cpp Program #5: Ricochet Robots: Allow solving the sliding robots puzzle Class: CS 141 Author: Dale Reed Lab: Tues 5am System: C++ Mac Xcode Grading Rubric: 55 Execution points 2 Displays header info and instructions on screen when run 3 Displays the board (Since I'm giving you all the code for this...) 5 Allows selecting default values (robot 2 to square M), random values, or user-selected values. 15 Allows making moves, displaying move numbers. Input can be upper or lower case, and can have spaces or not. 20 Robots stop at walls and don't run over each other 5 Game stops and message is given when goal robot makes it to the goal square. 5 If some robot besides robot 2 goes to the destination square (square M in this case), the destination square should change to show the robot there. When this robot moves away, the square should go back to displaying the letter that was there previously (M in our case.) 45 Programming Style (Given only if program runs substantially correctly) 5 Program naming convention is followed 5 Meaningful identifier names 5 Comments: Has header and this rubric. Has comments on each block of code 20 Appropriate data and control structures. Is implemented using classes. 10 Code Layout: Appropriate indentation and blank lines ------------------------------------------------ */
Up to 5 points of extra credit will be given if you implement a graphical version of the program, with lines around the outside of the board, squares representing each board position, lines surrounding each original lettered square, and colored squares for the robots. (Note that ASCII graphics will not count for this.) Up to 5 additional points of extra credit will be given if your program is implemented using mouse input.
You may not submit a program into both the regular submission as well as the extra credit submission. If you do, you will not be eligible for any extra credit points. Submit your extra credit program using the same naming conventions shown below, into the Blackboard assignment Program 5 Extra Credit.