This assignment deals with a game called Dark Gray Box. It is a puzzle game where the player tries to figure out the contents of a box by sending rays of light into the box and observing if and where they emerge. Various objects inside the box the bend light in different ways.
gameboar.h
and gameboar.cpp
. The turnin form
will include the specification of your
partner, if any. This should implement Step 5 as described below. The
intermediate turnin will be worth roughly 2 points out of the 25 points
alloted for the assignment. Use the intermediate
turnin form when you are ready to turn in this part of the assignment.
Here is a sample run of the game (the linux executable, so trying the same random seed on Windows may produce a different game), annotated with explanatory comments. When the game is begun, it looks like this:
DarkGrayBox is a puzzle game. The board consists of an N x M rectangle in which are hidden a number of objects. Your task is to figure out which objects are where by sending rays of light into one of the slots around the edge of the board, and seeing where they come out. Rays going in are marked with a capital letter, and rays coming out are marked with the matching lowercase letter. If the ray does not emerge from the box, only the capital letter will appear, and if it emerges from the same slot into which it was sent, only the lowercase letter is printed. Each object b affects the ray of light in a different way. The objects available in the current game are: / A mirror slanted bottom-left to top-right \ A mirror slanted top-left to bottom-right @ A block which absorbs any ray that hits it. There will be at most 2 blocks in the game. You specify the values of N and M, as well as the number of objects in the box, the number of tries you get (26 is the maximum you should provide for this), and a random seed. A good set of values is 7 7 26 7I type in the line, where is some integer seed. Enter: rows cols tries gizmos seed
5 5 20 5 1and see the following:
Type 'h' for a list of available commands 0 1 2 3 4 ----------- 0| |0 1| |1 2| |2 3| |3 4| |4 ----------- 0 1 2 3 4 Enter command:I enter the commmand
h
to get the list of available
commands:
Available commands are: h: display this message s <dir> <slot>: shoot a ray in direction <dir> in slot <slot> g <row> <col> <symbol>: guess the symbol <symbol> at location <row>,<col> g <row> <col>: erase a guess at location <row>,<col> G: see if your guesses are correct q: quit the program 0 1 2 3 4 ----------- 0| |0 1| |1 2| |2 3| |3 4| |4 ----------- 0 1 2 3 4 Enter command:Now I want to start finding objects in the box, so I pick a slot to fire a ray. Let's say I choose to fire a ray down slot 1. I enter the command
s d 1
and see the following:
Shot 'A' disappeared! A 0 1 2 3 4 ----------- 0| |0 1| |1 2| |2 3| |3 4| |4 ----------- 0 1 2 3 4 Enter command:Notice that I am told that the shot disappeared, and this is represented visually by the letter 'A' above slot 1 in the top, with no corresponding 'a'. I try a few more shots like so:
Enter command: s u 1 Shot 'B' disappeared! A 0 1 2 3 4 ----------- 0| |0 1| |1 2| |2 3| |3 4| |4 ----------- 0 1 2 3 4 B Enter command: s l 0 A 0 1 2 3 4 ----------- c 0| |0 C 1| |1 2| |2 3| |3 4| |4 ----------- 0 1 2 3 4 B Enter command: s l 1 A 0 1 2 3 4 ----------- c 0| |0 C 1| |1 D 2| |2 3| |3 4| |4 ----------- 0 1 2 3 4 B d Enter command:Shot 'B' also disappeared, so I suspect that there is a '@' in column 1, but I don't know where. Shot 'C', which was sent to the left on row 0 goes straight across row 0, which is shown visually by the 'c' character to the left of the row. Shot 'D' went in going left on row 1 and came out slot 3 at the bottom! This leads me to suspect a mirror '/' at position (1,3), which i specify like so:
Enter command: g 1 3 / A 0 1 2 3 4 ----------- c 0| |0 C 1| / |1 D 2| |2 3| |3 4| |4 ----------- 0 1 2 3 4 B d Enter command:Now I continue to send in rays and make guesses:
Enter command: s l 2 A e 0 1 2 3 4 ----------- c 0| |0 C 1| / |1 D 2| |2 E 3| |3 4| |4 ----------- 0 1 2 3 4 B d Enter command: g 2 4 \ A e 0 1 2 3 4 ----------- c 0| |0 C 1| / |1 D 2| \ |2 E 3| |3 4| |4 ----------- 0 1 2 3 4 B d Enter command: s l 3 A e 0 1 2 3 4 ----------- c 0| |0 C 1| / |1 D 2| \ |2 E f 3| |3 F 4| |4 ----------- 0 1 2 3 4 B d Enter command: s l 4 A e 0 1 2 3 4 ----------- c 0| |0 C 1| / |1 D 2| \ |2 E f 3| |3 F 4| |4 G ----------- 0 1 2 3 4 g B d Enter command: g 4 0 / A e 0 1 2 3 4 ----------- c 0| |0 C 1| / |1 D 2| \ |2 E f 3| |3 F 4| / |4 G ----------- 0 1 2 3 4 g B d Enter command: s r 2 A e 0 1 2 3 4 ----------- c 0| |0 C 1| / |1 D H 2| \ |2 E f 3| |3 F 4| / |4 G ----------- 0 1 2 3 4 g B d h Enter command: s r 1 Shot 'I' disappeared! A e 0 1 2 3 4 ----------- c 0| |0 C I 1| / |1 D H 2| \ |2 E f 3| |3 F 4| / |4 G ----------- 0 1 2 3 4 g B d h Enter command: g 1 1 @ A e 0 1 2 3 4 ----------- c 0| |0 C I 1| @ / |1 D H 2| \ |2 E f 3| |3 F 4| / |4 G ----------- 0 1 2 3 4 g B d h Enter command: s u 2 Shot 'J' disappeared! A e 0 1 2 3 4 ----------- c 0| |0 C I 1| @ / |1 D H 2| \ |2 E f 3| |3 F 4| / |4 G ----------- 0 1 2 3 4 g B J d hShot 'J' disappeared, and there are two reasonable explanations for this. The first is that there is a '@' somewhere in column 2, and the only location in that column that is consistent with our previous guesses is location (1,2). The second is that there is a '\' mirror at location (1,2), which would bend the light ray into the '@' at location (1,1). We can test which is correct by firing one more ray down column 2.
Enter command: s d 2 A K k e 0 1 2 3 4 ----------- c 0| |0 C I 1| @ / |1 D H 2| \ |2 E f 3| |3 F 4| / |4 G ----------- 0 1 2 3 4 g B J d hThis makes me think that the correct guess was a '\' at (1,2), so i guess this, and see if my guesses are correct:
Enter command: g 1 2 \ A K k e 0 1 2 3 4 ----------- c 0| |0 C I 1| @ \ / |1 D H 2| \ |2 E f 3| |3 F 4| / |4 G ----------- 0 1 2 3 4 g B J d h Enter command: G Correct!I have solved the puzzle! Yay!
If you need help with the lab environment or the online resources, go talk to a consultant in the IPL.
If you can't make progress in the actual assignment, please talk to the instructor or a TA. They are available during posted office hours, and sometimes by appointment. They will also occasionally help you out over email. You are invited to seek help from any available TA, not just your own.
You can discuss the assignment in general terms with other students. You
can ask general questions on the student discussion list for this course,
cse143@cs
. But any code you write must be your
own (i.e. that of you or your partner).
For more details about what is and is not allowed, see the
Software hygiene page.