[comp.sys.handhelds] Tandy PC-6: Basic source code: Blackbox

dgross@polyslo.CalPoly.EDU (Dave Gross) (04/11/90)

Blackbox is a modified version of a game that first appeared in the August,
1977 issue of "Games and Puzzles" and appeared in a computerized form in the
May/June 1978 issue of "Creative Computing."  The Black Box is an 8 by 8 square
in which several strange particles are hidden.  The object of the game is to
discover the positions of the particles by projecting rays at them from the
sides of the box and observing how these rays are deflected, reflected, or
absorbed.  Rays enter the box across one of the four edges and travel
horizontally or vertically.  The entry points are numbered from 1 to 32,
counterclockwise, starting at the top of the left edge, as follows:

		    32 31 30 29 28 27 26 25	 
		   +--+--+--+--+--+--+--+--+
		01 |  |  |  |**|  |  |  |  | 24
		   +--+--+--+--+--+--+--+--+
		02 |  |  |  |  |  |  |  |  | 23
		   +--+--+--+--+--+--+--+--+
		03 |  |  |  |**|  |  |  |  | 22
		   +--+--+--+--+--+--+--+--+
		04 |  |  |  |  |  |  |  |  | 21
		   +--+--+--+--+--+--+--+--+
		05 |  |  |  |  |  |  |  |  | 20
		   +--+--+--+--+--+--+--+--+
		06 |  |  |  |  |  |**|  |  | 19
		   +--+--+--+--+--+--+--+--+
		07 |  |  |  |  |  |  |  |  | 18
		   +--+--+--+--+--+--+--+--+
		08 |  |  |  |  |  |  |  |  | 17
		   +--+--+--+--+--+--+--+--+
		    09 10 11 12 13 14 15 16

To play the game, you first specify how many particles to place in the Black
Box.  Then you are given the option to place the particles yourself or to have
random placement of the particles.  Then you type in the point at which you
send the ray into the box, and you are told whether the ray was absorbed, or
where it emerged from the box.  Type a zero at the "RAY>" prompt to end the
game, make your guesses, print the box, and get your score.
 
The path of the ray inside the box is governed by the following rules:
 
	(1) Rays that strike a particle directly are absorbed.
 
	(2) Rays that come within one square of a particle in a diagonal
	    direction (so that they would pass next to the particle if the
	    continued) are deflected by 90 degrees.
 
	(3) Rays aimed between two particles one square apart are reflected.

	(4) Rays that enter on either side of a particle which is on the
	    edge of the box are reflected.

	(5) Rays otherwise travel in straight lines.
 
In the example above (where "**" represents a particle):
 
	A ray entering at 28 is REFLECTED
	A ray entering at 02 is REFLECTED
	A ray entering at 22 is ABSORBED
	A ray entering at 21 is DEFLECTED to 05
        A ray entering at 15 is DEFLECTED to 18

The score is based on the number of rays which enter the box, and on incorrect
guesses.  The lower the score, the better you have done.



100 PRINT "        BLACKBOX"
102 DIM B(9,9)
105 INPUT "# of particles",N
110 PRINT "Random placement?";
115 $= KEY$: IF $="" THEN 115
120 IF $="N" THEN GOSUB 500: GOTO 150
125 FOR J=0 TO 9: FOR I=0 TO 9:B(I,J)=0: NEXT I: NEXT J
130 FOR I=1 TO N
135 X= INT( RAN#*8+1):Y= INT( RAN#*8+1): IF B(X,Y)#0 THEN 135
                          -- use <SHIFT>=         ^
140 B(X,Y)=1: NEXT I
150 INPUT "RAY>",R: IF R<1 THEN 285
155 ON (R-1)/8+1 GOTO 165,170,175,180
160 GOTO 150
165 X=0:Y=R:U=1:V=0: GOTO 185
170 X=R-8:Y=9:U=0:V=-1: GOTO 185
175 X=9:Y=25-R:U=-1:V=0: GOTO 185
180 X=33-R:Y=0:U=0:V=1
185 P=X+U:Q=Y+V
190 IF U=0 THEN L=P-1:G=P+1:M=Q:H=1: GOTO 200
195 M=Q-1:H=Q+1:L=P:G=P
200 ON 8*B(P,Q)+B(L,M)+2*B(G,H)+1 GOTO 210,215,220,215
205 PRINT "ABSORBED":S=S+1: GOTO 150
210 X=P:Y=Q: GOTO 235
215 Z=1: GOTO 225
220 Z=-1
225 IF U=0 THEN U=Z:V=0: GOTO 235
230 U=0:V=Z
235 ON (X+15)/8 GOTO 255,245,260
240 STOP
245 ON (Y+15)/8 GOTO 265,185,270
250 STOP
255 Z=Y: GOTO 275
260 Z=25-Y: GOTO 275
265 Z=33-X: GOTO 275
270 Z=8+X
275 IF Z=R THEN PRINT "REFLECTED":S=S+1: GOTO 150
280 PRINT "DEFLECTED TO ";Z:S=S+2: GOTO 150
285 PRINT "YOUR GUESSES?"
290 FOR Q=1 TO N
295 PRINT "PARTICLE #";Q;: INPUT " ROW",I
300 PRINT "PARTICLE #";Q;: INPUT " COL",I
305 IF B(J,I)#1 THEN S=S+5:B(J,I)=-1: GOTO 320
310 B(J,I)=2
315 C=C+1
320 NEXT Q
325 FOR J=1 TO 8: PRINT J;">";: FOR I=1 TO 8
330 IF B(J,I)=0 THEN PRINT " .";: GOTO 340
                             ^  use <ext><shift>X
332 IF B(J,I)=-1 THEN PRINT " @";
                              ^  use <ext><shift>S
335 PRINT " *";
            ^  use <ext><shift>K
340 NEXT I: PRINT "": NEXT J: PRINT ""
345 PRINT C;"/";N;" CORRECT"
350 PRINT "SCORE: ";S
355 END
500 PRINT : FOR I=1 TO N
505 PRINT "PARTICLE #";I;: INPUT ", ROW",X
510 PRINT "PARTICLE #";I;: INPUT ", COL",Y
515 B(Y,X)=1: NEXT I
520 RETURN
--
************************ dgross@polyslo.CalPoly.EDU ****************************
From the National Archives, this letter to Franklin Roosevelt from a 14-year-
old Cuban boy:  "If you like, give me ten dollars green American.  I have never
seen a ten dollars bill... I would like to have one of them. -- Fidel Castro."