In this assignment you will write a program to let you play the Black Box "game." Although called a game, Black Box is actually a kind of puzzle, where the computer sets up the puzzle, and you try to solve it, by figuring out where things are inside the "box".
Wikipedia has a good description of the game.
The basic idea is this: The computer "hides" four atoms somewhere on an 8x8 grid. You, the player, try to figure out where the balls are by shooting in "rays" from any of the 32 positions along the sides of the grid (8 on each side, including the top and the bottom), and seeing where the ray comes out, or if it comes out at all. For each ray you send in, there are three cases:
H.)R.)a and a
for the first time it occurs, b and b for
the second time, c and c for the third time,
etc. There is no need to mark which is the entry and which the exit. If the game board looks like this*:![]() |
You could represent it like this:Or like this: [(2, 1), (2, 6), (5, 3), (7, 6)]Or like this: {(2, 1), (2, 6), (5, 3), (7, 6)} |
| This is how the board prints out initially: | This is what it might look like after shooting in a few rays: |
1 2 3 4 5 6 7 8
|
1 2 3 4 5 6 7
8 |
1 to 8,
followed by a letter L for left, R for
right, T for top, and B for bottom. (Also
allow lowercase letters l, r, t,
b.) In the second picture above, rays have been shot in
from 1L (or lR), 4T, 4R,
5L (or 3B), and 6B.5L (b) and 4T
(H). To mark a location, the user should enter a row number
followed by a column number, such as 44 (or 4 4)
in the above example. Do not limit the user to four marks. 4 4 in
the above example is correct, that will be 30 points for the three
atoms that haven't been marked. The game board should be printed out after each user input, showing the effects of shooting rays, and the markers that the user has placed. After scoring the game, the program should tell the user where the atoms are actually hidden, preferably with a similar kind of output.
Normal people don't start counting with zero. Only programmers do that.
So when you print the board, you should add 1 to all the row numbers and
all the column numbers, and when you get row or column numbers from the
user, you should immediately subtract 1 from them. Inside the program
we'll use 0 to 7, not 1 to 8.
After each game, the program should ask the user whether he/she wants to
play again.
new_game(location1, location2, location3,
location4)(row, column)
tuple. Row and column numbers are 0 to 7.
Clears any leftover data from any previous game. Returns None.
shoot(entry)entry is
a string using the same syntax that a user would type in ('1L',
etc.). Returns the exit point of the ray in the same syntax, or None
in the case of a "hit."toggle(row, column)0 to 7. Returns None.
toggle marks where the user thinks the
atoms may be; it does not affect where they actually are.score()At the end of your Python program (after all your function definitions), insert the following lines:
if __name__ == "__main__":
main() # or whatever your starting method is
Turn in your one zip file to Canvas by 6am Wednesday, September 30.
Notes on submitting your work:
* "BlackBoxSample1" by Life of Riley - Own work. Licensed
under GFDL 1.2 via Commons
-https://commons.wikimedia.org/wiki/File:BlackBoxSample1.svg#/media/File:BlackBoxSample1.svg