Black Box
- Type
- Game
- Category
- Deduction puzzle
- Author
- Ken Arromdee
- Published in
- Antic, August 1988 (Vol. 7, No. 4), Game of the Month
- Year
- 1988
- Language
- Atari BASIC
- Requirements
- Any Atari 8-bit, any memory size, Atari BASIC, joystick in port 1
About the program
Antic introduced Black Box as a computer version of a board game that no longer seemed to be made. Somewhere inside an 8×8 or 10×10 box the computer hides up to eight "particles". You can't look inside. You can only fire rays in from the edges and see where, or whether, they come out. From those clues you have to deduce where every particle is, using as few probes as possible. It's a pure logic game, and a good one for two people to argue over. Ken Arromdee was an electrical engineer from New Jersey.
Typing it in
Line 1090 is the only difficult line. It's a machine-language routine in a string, used to copy the ROM character set into RAM. In the magazine a second listing wrote it to LINES.LST for you to ENTER over the main program, and the disk version printed here already includes it. Elsewhere, {inv}…{/inv} means type with the Atari (inverse) key on. In lines 50 and 92, INPUT #16 is deliberate, not a misprint. It reads from the screen editor without printing a question mark, which is a handy trick for neater prompts.
How to play
Say how many particles (1–8) and whether you want an 8×8 or 10×10 box, then press the button at the title. The green cursor runs round the outside of the grid. Move it with the joystick to an edge square and press the button to fire a ray inwards:
- Hit: the ray meets a particle head-on and is absorbed. You get a red square at the entry point (one turn).
- Reflection: the ray comes straight back, either because particles sit diagonally on both sides of its path, or because one sits diagonally beside the entry point. You get a purple circle (one turn).
- Deflection: a single particle diagonally ahead turns the ray 90° away from it. A ray that comes out somewhere, even after several bounces, gets the same letter at its entry and exit points (two turns).
Press SELECT to switch to guessing. The cursor turns yellow and moves inside the box, and the button marks or unmarks a guess. SELECT goes back to probing. Press the space bar to reveal the particles, then press the button to play again.
How it works
The box is a GRAPHICS 2 screen (full screen, mode 18) with a redefined character set: grid lines, corners, the circle and the hit square. The neat trick is how the particles are hidden. Empty cells are character 171 and particles are character 172. In the new character set, characters 11 and 12 (which those codes display) have identical shapes, both an empty square. So the particles are on the screen all the time, and the ray tracer can find them with LOCATE, but you can't tell them apart. To reveal them, line 1250 simply redefines character 12 as a solid ball. Line 1300 copies character 11's shape back over it for the next game.
The ray tracer (lines 610–1060) steps the ray one cell at a time in direction 1–4. At each step it LOCATEs the cell in front and the two cells diagonally ahead, then lets the subroutine at 930 decide whether to absorb, reflect or turn left or right. Guess marks are made by adding or subtracting 32 from a cell's character code, which changes its colour register in GRAPHICS 2 without changing its shape.
Variations to try
- Allow more particles by raising the limit of 8 in line 60. On a 10×10 board, 10 or 12 makes a fiendish game.
- Keep a best score for each board size and number of particles.
Changes from the published listing
One change, so the program also runs under Altirra BASIC, the free replacement BASIC built into many emulators. Altirra BASIC adds commands called DIR, MOVE, so it rejected the published lines that use those words as the start of a variable name. The variable is renamed everywhere in the program. The new name is the same length, so the memory layout is unchanged and the program behaves exactly as published on genuine Atari BASIC. If you type it in from the magazine, the original names work fine on a real Atari.
| Published | Now | Lines |
|---|---|---|
DIR |
DRN |
15 lines (330–1040) |
MOVE |
MOVX |
550, 940, 960, 10000 |
Listing
5 REM BLACK BOX
10 REM BY KEN ARROMDEE
15 REM (c)1988, ANTIC PUBLISHING
20 DIM Q$(1):Q$=CHR$(34)
30 GOSUB 1470
40 GRAPHICS 0:POKE 709,0:POKE 710,10:POKE 712,10
50 TRAP 80:? "How many particles? (8 maximum) ";:INPUT #16;P
60 IF P>8 THEN ? "The maximum is 8.":GOTO 50
70 IF P>0 AND P=INT(P) THEN TRAP 65535:GOTO 90
80 ? "Please type an integer.":GOTO 50
90 TRAP 110:? :? "Do you want the black box to be":? " 8 by 8 or 10 by 10?":? :? " (Type 8 or 10) ";
92 INPUT #16;SIZE
95 IF SIZE<>8 AND SIZE<>10 THEN 110
100 TRAP 40000:GOTO 120
110 ? "Type an 8 or 10.":GOTO 90
120 GOSUB 1080
130 OLDX=1:OLDY=-1:OLDDIR=4:X1=1:Y1=1:TURNS=0:IF SIZE=10 THEN OLDX=0:X1=0:Y1=0
140 IF SIZE=10 THEN COLOR 171:FOR I=1 TO 10:FOR J=1 TO 10:PLOT I,J:NEXT J:NEXT I:GOTO 180
150 COLOR 3:PLOT 1,1:COLOR 4:PLOT 2,1:DRAWTO 9,1:PLOT 2,10:DRAWTO 9,10
160 COLOR 5:PLOT 10,1:COLOR 7:PLOT 1,10:COLOR 8:PLOT 10,10:COLOR 6:PLOT 1,2:DRAWTO 1,9:PLOT 10,2:DRAWTO 10,9
170 COLOR 171:FOR I=2 TO 9:FOR J=2 TO 9:PLOT I,J:NEXT J:NEXT I
180 POKE 623,4:POKE 53256,3:POKE 53261,255:POKE 704,128:POKE 53248,144
190 POKE 53257,3:POKE 705,128:POKE 53262,255:POKE 53249,176
200 POKE 53258,3:POKE 706,128:POKE 53263,255:POKE 53250,208
210 POSITION 14,2:? #6;"black":POSITION 15,3:? #6;"box"
220 POSITION 13,5:? #6;"{inv}turns{/inv} ";TURNS
230 POSITION 14,7:? #6;"{inv}PRESS{/inv}"
240 POSITION 13,8:? #6;"{inv}SELECT{/inv}"
250 POSITION 15,9:? #6;"{inv}TO{/inv} "
260 POSITION 14,10:? #6;"{inv}GUESS{/inv}"
270 FOR I=1 TO P
280 X=INT(RND(0)*SIZE)+2-(SIZE=10):Y=INT(RND(0)*SIZE)+2-(SIZE=10)
290 LOCATE X,Y,D:IF D<>171 THEN 280
300 COLOR 172:PLOT X,Y
310 NEXT I
320 LET LETTER=ASC("A")
330 X=OLDX:Y=OLDY:DRN=OLDDIR
340 LOCATE X+1,Y+1,UNDER:POSITION X+1,Y+1:? #6;"{inv}!{/inv}"
350 FOR DELAY=1 TO 30:NEXT DELAY
360 IF STRIG(0)=0 AND UNDER=32 THEN 550
370 S=STICK(0)
380 POSITION X+1,Y+1:? #6;CHR$(UNDER)
390 IF PEEK(764)=33 THEN 1250
400 IF PEEK(53279)=5 THEN FOR I=1 TO 40:NEXT I:GOSUB 1330
410 IF S=15 THEN 340
420 ON DRN GOTO 430,460,490,520
430 Y=Y+(S=13)-(S=14):IF Y=(SIZE=8)-1 THEN Y=-1:X=(SIZE=8):DRN=4
440 IF Y=9+(SIZE=10) THEN Y=10:X=(SIZE=8):DRN=2
450 GOTO 340
460 X=X+(S=7)-(S=11):IF X=(SIZE=8)-1 THEN X=-1:Y=8+(SIZE=10):DRN=1
470 IF X=9+(SIZE=10) THEN X=10:Y=8+(SIZE=10):DRN=3
480 GOTO 340
490 Y=Y+(S=13)-(S=14):IF Y=(SIZE=8)-1 THEN Y=-1:X=8+(SIZE=10):DRN=4
500 IF Y=9+(SIZE=10) THEN Y=10:X=8+(SIZE=10):DRN=2
510 GOTO 340
520 X=X+(S=7)-(S=11):IF X=(SIZE=8)-1 THEN X=-1:Y=(SIZE=8):DRN=1
530 IF X=9+(SIZE=10) THEN X=10:Y=(SIZE=8):DRN=3
540 GOTO 340
550 POSITION X+1,Y+1:? #6;" ":MOVX=1
560 OLDX=X:OLDY=Y:OLDDIR=DRN:IF SIZE=10 THEN 610
570 IF X=10 THEN X=9
580 IF Y=10 THEN Y=9
590 IF X=-1 THEN X=0
600 IF Y=-1 THEN Y=0
610 ON DRN GOTO 630,670,710,750
620 REM DIR 1=MOVING RIGHT
630 LOCATE X+2,Y+1,FRONT:LOCATE X+2,Y,LEFT:LOCATE X+2,Y+2,RIGHT
640 GOSUB 930
650 X=X+1:GOTO 780
660 REM 2=MOVING UP
670 LOCATE X+1,Y,FRONT:LOCATE X,Y,LEFT:LOCATE X+2,Y,RIGHT
680 GOSUB 930
690 Y=Y-1:GOTO 780
700 REM 3=MOVING LEFT
710 LOCATE X,Y+1,FRONT:LOCATE X,Y,RIGHT:LOCATE X,Y+2,LEFT
720 GOSUB 930
730 X=X-1:GOTO 780
740 REM 4=MOVING DOWN
750 LOCATE X+1,Y+2,FRONT:LOCATE X+2,Y+2,LEFT:LOCATE X,Y+2,RIGHT
760 GOSUB 930
770 Y=Y+1
780 IF X>=(SIZE=8) AND X<=8+(SIZE=10) AND Y>=(SIZE=8) AND Y<=8+(SIZE=10) THEN 610
790 IF SIZE=10 THEN 850
800 ON DRN GOTO 810,820,830,840
810 X=X+1:GOTO 850
820 Y=Y-1:GOTO 850
830 X=X-1:GOTO 850
840 Y=Y+1
850 TURNS=TURNS+2:GOSUB 10000
860 POSITION X+1,Y+1:? #6;CHR$(LETTER):POSITION OLDX+1,OLDY+1
870 ? #6;CHR$(LETTER):LET LETTER=LETTER+1:GOTO 900
880 GOSUB 10000:TURNS=TURNS+1:POSITION OLDX+1,OLDY+1:? #6;CHR$(138):GOTO 900
890 GOSUB 10000:TURNS=TURNS+1:POSITION OLDX+1,OLDY+1:? #6;CHR$(9):GOTO 900
900 POSITION 13,5:IF TURNS>9 THEN POSITION 12,5
910 ? #6;"{inv}turns{/inv} ";TURNS
920 GOTO 330
930 IF FRONT=172 OR FRONT=140 THEN POP :GOTO 880:REM ABSORPTION
940 IF MOVX=1 THEN IF LEFT=172 OR RIGHT=172 OR LEFT=140 OR RIGHT=140 THEN POP :GOTO 890:REM REFLECTION
950 IF (LEFT=172 OR LEFT=140) AND (RIGHT=172 OR RIGHT=140) THEN POP :GOTO 890:REM REFLECTION
960 MOVX=MOVX+1
970 IF LEFT<>172 AND RIGHT<>172 AND LEFT<>140 AND RIGHT<>140 THEN RETURN :REM NOTHING AHEAD
980 IF RIGHT=172 OR RIGHT=140 THEN 1040
990 REM BOUNCE RIGHT
1000 DRN=DRN-1:IF DRN=0 THEN DRN=4
1010 POP
1020 GOTO 610
1030 REM BOUNCE LEFT
1040 DRN=DRN+1:IF DRN=5 THEN DRN=1
1050 POP
1060 GOTO 610
1070 REM {inv}CHARACTER REDEFINITION{/inv}
1080 GRAPHICS 18:POKE 106,PEEK(106)-3:CHBASE=PEEK(106)+1:GRAPHICS 18:POKE 756,CHBASE:CHBASE=CHBASE*256
1090 DV=USR(ADR("hh{inv}{CTRL-E}U{/inv}h{inv}{CTRL-E}T{/inv}h{inv}{CTRL-E}W{/inv}h{inv}{CTRL-E}V"{/inv}{CTRL-B}{inv} {/inv}{CTRL-,}{inv}1T{CTRL-Q}VHPyfUfWJPp{/inv}{CTRL-.}"),57344,CHBASE)
1100 READ CHNUM:IF CHNUM=-1 THEN POKE 709,102:POKE 710,182:POKE 711,72:POKE 708,26:RETURN
1110 FOR I=CHBASE+8*CHNUM TO CHBASE+8*CHNUM+7:READ D:POKE I,D:NEXT I:GOTO 1100
1120 DATA 1,255,153,153,255,255,153,153,255
1130 DATA 3,0,0,0,31,31,24,24,24
1140 DATA 4,0,0,0,255,255,0,0,0
1150 DATA 5,0,0,0,248,248,24,24,24
1160 DATA 6,24,24,24,24,24,24,24,24
1170 DATA 7,24,24,24,31,31,0,0,0
1180 DATA 8,24,24,24,248,248,0,0,0
1190 DATA 9,60,82,137,197,163,145,74,60
1200 DATA 10,255,129,189,165,165,189,129,255
1210 DATA 11,255,129,129,129,129,129,129,255
1220 DATA 12,255,129,129,129,129,129,129,255
1230 DATA -1
1240 REM SHOW PARTICLE LOCATION
1250 RESTORE 1250:FOR I=CHBASE+96 TO CHBASE+103:READ D:POKE I,D:NEXT I
1260 DATA 60,126,255,255,255,255,126,60
1270 POSITION 13,8:? #6;"{inv}TRIGGER{/inv}":POSITION 15,9:? #6;"{inv}TO{/inv}":POSITION 14,10:? #6;"{inv}REDO{/inv} "
1280 IF STRIG(0) THEN 1280
1290 POSITION 0,0:? #6;"{CLEAR}"
1300 FOR I=CHBASE+96 TO CHBASE+103:POKE I,PEEK(I-8):NEXT I
1310 POKE 764,255:GOTO 130
1320 REM GUESS MODE
1330 POSITION 14,10:? #6;"{inv}PROBE{/inv}"
1340 S=STICK(0)
1350 X1=X1+(S>=5 AND S<=7)-(S>=9 AND S<=11):IF X1>8+(SIZE=10) THEN X1=(SIZE=8)
1360 IF X1<(SIZE=8) THEN X1=8+(SIZE=10)
1370 Y1=Y1+(S=5 OR S=9 OR S=13)-(S=6 OR S=10 OR S=14):IF Y1>8+(SIZE=10) THEN Y1=(SIZE=8)
1380 IF Y1<(SIZE=8) THEN Y1=8+(SIZE=10)
1390 LOCATE X1+1,Y1+1,UNDER1:POSITION X1+1,Y1+1:? #6;"!"
1400 IF STRIG(0) THEN 1410
1405 FOR I=1 TO 30:NEXT I:UNDER1=UNDER1+32*(UNDER1<160)-32*(UNDER1>160)
1410 FOR I=1 TO 10:IF PEEK(53279)=5 THEN 1437
1415 NEXT I
1420 POSITION X1+1,Y1+1:? #6;CHR$(UNDER1)
1430 IF PEEK(764)=33 THEN POP :GOTO 1250
1435 GOTO 1340
1437 POSITION X1+1,Y1+1:? #6;CHR$(UNDER1)
1440 FOR I=1 TO 30:NEXT I:POSITION 14,10:? #6;"{inv}GUESS{/inv}":RETURN
1450 GOTO 1330
1460 REM TITLE PAGE
1470 GRAPHICS 18:POKE 710,0:POKE 709,40:POKE 708,6
1480 DL=PEEK(560)+PEEK(561)*256:POKE DL+10,6
1490 POSITION 6,3:? #6;"{inv}black box{/inv}"
1500 POSITION 3,5:? #6;"BY KEN ARROMDEE"
1510 POKE DL+13,2:POSITION 10,8:? #6;"PRESS TRIGGER TO PLAY"
1530 IF STRIG(0) THEN 1530
1540 RETURN
9999 REM RANDOM DELAY
10000 FOR I=1 TO 60-6*MOVX+40*RND(0):NEXT I:RETURN
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: BLACKBOX.BAS.
Credits
- Program listing: Black Box — program listing (Antic, August 1988 (Vol. 7, No. 4), Game of the Month) — Ken Arromdee
- Picture: An 8×8 box after two probes. Each letter pair marks where a ray went in and where it came out. — Ken Arromdee (program); screenshot by the site
- Antic, August 1988 - Vol. 7 No. 4 — article: game by Ken Arromdee — Ken Arromdee, 1988
- Antic Software Archive — August 1988 - Vol. 7 No. 4 disk: BLACKBOX.BAS — AtariMagazines.com (Kevin Savetz), 1988
