Red, White and Blue
- Type
- Game
- Category
- Solitaire logic puzzle
- Author
- Heidi Brumbaugh
- Published in
- Antic, July 1987 (Vol. 6, No. 3), Game of the Month
- Year
- 1987
- Language
- Atari BASIC
- Requirements
- Any Atari 8-bit, any memory size, Atari BASIC, joystick in port 1
- Related
- Black Box, The Seven Skulls, Bounce, Hot and Cold, Pegboard, Red Squares
About the program
Antic called this "a kind of solitaire Othello" and asked whether it was more devilish than Rubik's Cube. It was the July 1987 Game of the Month, and the first Game of the Month written by a member of Antic's own staff. Heidi Brumbaugh, an editorial assistant, had written it for the IBM PC as Pathfinder, to learn Microsoft BASIC's logical operators. Antic agreed to publish it if the title and colours could change to something suitably patriotic for the Fourth of July.
The board is a square grid of hidden (white) cells, each secretly red or blue. You start on one blue square and move up, down, left or right. Moving onto a red square turns it blue. You can't step onto a blue square, and that includes the trail you have just made. Get every square blue to win. When you're boxed in, press the button to flip the board: every revealed square swaps colour, except the one you're standing on. Some boards can't be solved at all.
Typing it in
The special characters are mostly in the decorative GRAPHICS 2 screens. {inv}…{/inv} means type with the Atari (inverse) key on, and {CTRL-J} is CTRL+J. Lines 1205 and 1250 draw a border of alternating stars that runs off the right edge of this page. Copy them exactly. Line 3205 (D=SQR(2^4.4)) computes a value that is never used and seems to be there only as a short pause, so keep it as printed. Hold OPTION while typing RUN if you want the BREAK key to stay active (line 40).
How to play
Push the joystick up or down on the opening screen to choose a grid from 2×2 up to 9×9, then press the button. In play:
- Joystick moves you one square. A hidden square shows its true colour when you try it. If it's red you move there and it turns blue. If it's blue you get a beep and stay put.
- Button flips the board.
- ESC, or the stick pushed up while you press the button, asks whether to quit. Choose YES or NO with left/right and the button.
Antic pointed out that every command can be given from the joystick. That answered a March 1987 letter asking for games that physically handicapped readers could play.
The program's limit is nine squares a side. The article suggests shrinking LSQR in line 11000 to 3 or even 1, or switching to GRAPHICS 7+16, for boards up to 32×32, though play then gets slow.
How it works
Each square is a number in the array STAT(X,Y): 0 for red, 1 for blue, plus 10 while it's still hidden. So INT(STAT/10) (lines 3000, 5030) tells you whether a square is hidden. Flipping a revealed square is just STAT=ABS(STAT-1), which turns 0 into 1 and 1 into 0. Brumbaugh explained that in the PC original the four states were the bit patterns 0–3, manipulated with AND, OR and XOR. Atari BASIC's AND and OR only return true or false, so she switched to decimal arithmetic.
The win test in line 1080 compares a running count of blue squares, TGOTTEN, with the size of the board. After a flip, line 5150 works out the new count from how many squares have been found (TFOUND), so the board never has to be recounted. The grid is drawn in full-screen GRAPHICS 5 (mode 5+16) as filled squares, and the subroutine that draws a square sits at line 500, near the top of the program, because BASIC finds low line numbers faster.
Variations to try
- Make the board bigger, as the article suggests (line 11000:
MODE=7+16,WIDSCR=160,LENSCR=96, smallerLSQR). - Count your flips and show the total on the "you win" screen as a score to beat.
Listing
10 REM RED, WHITE AND BLUE
20 REM BY HEIDI BRUMBAUGH
30 REM (c) 1987, ANTIC PUBLISHING
40 BRK=(PEEK(53279)<>5)
100 GOSUB 11000:REM INITIALIZATION
110 GOSUB 7000:REM GET SKILL LEVEL
120 GOSUB 10000:REM MAKE RANDOM BOARD
130 GOSUB 6000:REM DRAW BOARD
140 GOTO 1000
500 LSQR1=INT(LSQR/2):FOR TY=Y-LSQR1 TO Y+LSQR1
510 PLOT (X-LSQR1),TY:DRAWTO (X+LSQR1),TY:NEXT TY
550 RETURN
1000 POKE 764,255
1010 IF PEEK(764)=ESC OR (STICK(0)=14 AND STRIG(0)=0) THEN 1200
1015 GOSUB 1830
1020 IF STRIG(0)=0 THEN GOSUB 5000:GOTO 1080:REM FLIP BOARD
1025 STK0=PEEK(632)
1030 IF STK0=7 THEN GOSUB 2000:GOTO 1080:REM RIGHT
1040 IF STK0=14 THEN GOSUB 2100:GOTO 1080:REM UP
1050 IF STK0=11 THEN GOSUB 2200:GOTO 1080:REM LEFT
1060 IF STK0=13 THEN GOSUB 2300:GOTO 1080:REM DOWN
1065 IF STK0=5 THEN IF STRIG(0)=0 THEN 1200
1070 GOTO 1010:REM REPEAT TIL KEY PRESSED
1080 IF (NSQRS+1)*(NSQRS+1)<>TGOTTEN THEN 1000:REM CHECK FOR WIN
1100 GRAPHICS 18
1110 POSITION 1,0:? #6;"!!!!!!!!!!!!!!!!!"
1120 POSITION 1,2:? #6;"!!! you win !!!"
1130 POSITION 1,4:? #6;"!!!!!!!!!!!!!!!!!"
1140 GOSUB 1810:POSITION 1,6:? #6;"{inv}CARE{/inv}"
1150 GOSUB 1810:POSITION 6,7:? #6;"{inv}FOR{/inv}"
1160 GOSUB 1810:POSITION 10,8:? #6;"{inv}A{/inv}"
1170 GOSUB 1810:POSITION 12,9:? #6;"{inv}CIGAR?{/inv}":GOSUB 1810
1180 FOR I=1 TO 500:NEXT I:GOTO 110
1200 IF STRIG(0)=0 THEN 1200
1205 GRAPHICS 18:POKE 708,RED:POKE 709,WHITE:POKE 710,BLUE:POSITION 0,0:? #6;"*{CTRL-J}{inv}*{/inv}*{CTRL-J}{inv}*{/inv}*{CTRL-J}{inv}*{/inv}*{CTRL-J}{inv}*{/inv}*{CTRL-J}{inv}*{/inv}*{CTRL-J}{inv}*{/inv}*{CTRL-J}"
1207 POKE 711,YELLOW:POKE 712,10:RESTORE 12000
1210 FOR R=1 TO 8:READ CJ:POSITION 0,R:? #6;CHR$(CJ):POSITION 19,R:? #6;CHR$(CJ):NEXT R
1220 POSITION 4,2:? #6;"{inv}really{/inv} {inv}quit{/inv}"
1230 POSITION 1,4:? #6;"RED white & {inv}BLUE?{/inv}"
1240 POSITION 6,7:? #6;"yes":POSITION 11,7:? #6;"{inv}no{/inv}"
1250 POSITION 0,9:? #6;"*{CTRL-J}{inv}*{/inv}*{CTRL-J}{inv}*{/inv}*{CTRL-J}{inv}*{/inv}*{CTRL-J}{inv}*{/inv}*{CTRL-J}{inv}*{/inv}*{CTRL-J}{inv}*{/inv}*{inv}*{/inv}"
1260 REM HIGHLIGHT NO
1280 REM CHECK TRIGGER
1290 IF STRIG(0)=0 THEN GOSUB 6000:GOTO 1000:REM NO
1295 POSITION 6,7:? #6;"{inv}yes{/inv}";
1297 POSITION 11,7:? #6;"No";:GOSUB 1820:POSITION 11,7:? #6;"n{inv}O{/inv}";:GOSUB 1820:POSITION 11,7:? #6;"{inv}N{/inv}O";
1298 GOSUB 1820
1300 IF STICK(0)<>11 THEN 1290
1310 REM HIGHLIGHT YES
1320 POSITION 11,7:? #6;"{inv}no{/inv}";
1325 POSITION 6,7:? #6;"Ye{inv}S{/inv}";:GOSUB 1820:POSITION 6,7:? #6;"{inv}Y{/inv}Es";:GOSUB 1820:POSITION 6,7:? #6;"y{inv}E{/inv}S";
1326 GOSUB 1820
1330 IF STRIG(0)=0 THEN 110
1340 IF STICK(0)<>7 THEN 1320
1350 GOTO 1290
1400 IF STRIG(0)=0 THEN 1400
1410 GOTO 110
1800 SOUND 0,45,10,8:FOR D=1 TO 25:NEXT D:SOUND 0,0,0,0:RETURN :REM SOUND ROUTINE
1810 FOR I=1 TO 200:NEXT I:RETURN :REM DELAY ROUTINE
1820 FOR D=1 TO 10:NEXT D:RETURN
1830 POKE 77,0:IF BRK THEN POKE 16,112:POKE 53774,112:RETURN
1840 RETURN
2000 IF XGUY<NSQRS THEN XTEMP=XTEMP+1:GOTO 3000
2010 GOSUB 1800:RETURN
2020 GRAPHICS 0:END
2100 IF YGUY>0 THEN YTEMP=YTEMP-1:GOTO 3000
2110 GOSUB 1800:RETURN
2200 IF XGUY>0 THEN XTEMP=XTEMP-1:GOTO 3000
2210 GOSUB 1800:RETURN
2300 IF YGUY<NSQRS THEN YTEMP=YTEMP+1:GOTO 3000
2310 GOSUB 1800:RETURN
3000 POKE 77,0:IF INT(STAT(XTEMP,YTEMP)/10) THEN 3180
3005 REM NOT HIDDEN
3100 IF STAT(XTEMP,YTEMP) THEN 3160
3110 REM NOT GOTTEN
3120 COLOR CGOT:PLOT XSTART+(LSQR*XGUY)+INT(LSQR/2),YSTART+(LSQR*YGUY)+INT(LSQR/2)
3130 X=XSTART+(LSQR*XTEMP)+INT(LSQR/2):Y=YSTART+(LSQR*YTEMP)+INT(LSQR/2):GOSUB 500
3140 COLOR CGUY:XGUY=XTEMP:YGUY=YTEMP:PLOT X,Y:STAT(XGUY,YGUY)=1:TGOTTEN=TGOTTEN+1:RETURN
3150 REM ALREADY GOTTEN
3160 GOSUB 1800:XTEMP=XGUY:YTEMP=YGUY:RETURN
3170 REM HIDDEN
3180 STAT(XTEMP,YTEMP)=STAT(XTEMP,YTEMP)-10:TFOUND=TFOUND+1:TGOTTEN=TGOTTEN+1
3185 IF STAT(XTEMP,YTEMP) THEN 3240
3190 REM NOT GOTTEN
3200 COLOR CNOTGOT:X=XSTART+(LSQR*XTEMP)+INT(LSQR/2):Y=YSTART+(LSQR*YTEMP)+INT(LSQR/2):GOSUB 500
3205 D=SQR(2^4.4)
3210 COLOR CGOT:PLOT XSTART+(LSQR*XGUY)+INT(LSQR/2),YSTART+(LSQR*YGUY)+INT(LSQR/2)
3220 COLOR CGOT:GOSUB 500:COLOR CGUY:XGUY=XTEMP:YGUY=YTEMP:PLOT X,Y:STAT(XGUY,YGUY)=1:RETURN
3230 REM GOTTEN, REVEAL SQUARE
3240 COLOR CGOT:X=XSTART+(LSQR*XTEMP)+INT(LSQR/2):Y=YSTART+(LSQR*YTEMP)+INT(LSQR/2):GOSUB 500
3250 GOSUB 1800:XTEMP=XGUY:YTEMP=YGUY:RETURN
5000 GRAPHICS MODE:POKE 712,BLACK:POKE 708,RED:POKE 709,WHITE:REM FLIP
5010 FOR Y=0 TO NSQRS
5020 FOR X=0 TO NSQRS
5030 IF INT(STAT(X,Y)/10) THEN COLOR CHIDE:GOTO 5070
5040 IF X=XGUY AND Y=YGUY THEN COLOR CGOT:GOTO 5070
5050 STAT(X,Y)=ABS(STAT(X,Y)-1)
5060 IF STAT(X,Y) THEN COLOR CGOT:GOTO 5070
5065 COLOR CNOTGOT
5070 FOR TY=YSTART+(Y*LSQR) TO YSTART+(Y*LSQR)+LSQR-1
5080 TX1=XSTART+X*LSQR:TX2=TX1+LSQR-1
5090 PLOT TX1,TY:DRAWTO TX2,TY:NEXT TY:NEXT X:NEXT Y
5140 COLOR CGUY:PLOT XSTART+(LSQR*XGUY)+INT(LSQR/2),YSTART+(LSQR*YGUY)+INT(LSQR/2)
5150 TGOTTEN=TFOUND-TGOTTEN+1:RETURN
6000 GRAPHICS MODE:POKE 712,BLACK:POKE 708,RED:POKE 709,WHITE
6010 FOR YTEMP=0 TO NSQRS:FOR XTEMP=0 TO NSQRS
6020 IF INT(STAT(XTEMP,YTEMP)/10) THEN COLOR CHIDE:GOTO 6050
6030 IF STAT(XTEMP,YTEMP) THEN COLOR CGOT:GOTO 6050
6040 COLOR CNOTGOT
6050 X=XSTART+(XTEMP*LSQR)+INT(LSQR/2):Y=YSTART+(YTEMP*LSQR)+INT(LSQR/2):GOSUB 500
6060 NEXT XTEMP
6070 NEXT YTEMP
6080 COLOR CGUY:PLOT XSTART+(LSQR*XGUY)+INT(LSQR/2),YSTART+(LSQR*YGUY)+INT(LSQR/2)
6090 XTEMP=XGUY:YTEMP=YGUY:RETURN
7000 GRAPHICS 18:GOSUB 1830
7010 PRINT #6;"skill level:":POSITION 13,0:? #6;NSQRS+1
7020 POSITION 3,3:? #6;"USE JOYSTICK TO":POSITION 1,5:? #6;"CHANGE SKILL LEVEL"
7030 POSITION 9,7:? #6;"{inv}***{/inv}":POSITION 2,9
7040 ? #6;"PRESS TRIGGER TO":POSITION 8,11:? #6;"PLAY"
7050 REM JOYSTICK INPUT
7060 IF STRIG(0)=0 THEN RETURN
7070 J=STICK(0):IF J<13 OR J>14 THEN 7060:REM CHECK RANGE
7075 ON 15-J GOTO 7080,7090
7080 IF NSQRS>MAXSQRS-1 THEN GOSUB 1800:GOTO 7060
7085 NSQRS=NSQRS+1:GOTO 7110
7090 IF NSQRS<2 THEN GOSUB 1800:GOTO 7060
7095 NSQRS=NSQRS-1
7110 POSITION 13,0:? #6;" ":POSITION 13,0:? #6;NSQRS+1:FOR I=1 TO 100:NEXT I
7120 GOTO 7060
10000 XSTART=INT((WIDSCR/2)-(((NSQRS+1)/2)*LSQR))
10005 YSTART=INT((LENSCR/2)-(((NSQRS+1)/2)*LSQR))
10010 FOR X=0 TO NSQRS
10015 FOR Y=0 TO NSQRS
10020 STAT(X,Y)=INT(RND(0)+0.5)+10
10030 NEXT Y
10040 NEXT X
10050 XGUY=INT(RND(0)*NSQRS+1):YGUY=INT(RND(0)*NSQRS+1):STAT(XGUY,YGUY)=1:XTEMP=XGUY:YTEMP=YGUY
10060 TGOTTEN=1:TFOUND=1
10080 RETURN
11000 MODE=5+16:WIDSCR=80:LENSCR=48:LSQR=5:MAXSQRS=INT((LENSCR/LSQR)-1):NSQRS=4
11010 CGUY=0:CGOT=3:CNOTGOT=1:CHIDE=2
11020 DIM STAT(MAXSQRS,MAXSQRS),CLS$(1)
11030 CLS$=CHR$(125):ESC=28:RED=50:WHITE=14:BLUE=114:YELLOW=30:BLACK=0
11040 RETURN
12000 DATA 170,10,42,170,10,42,170,10
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: RWB.BAS.
Credits
- Program listing: Red, White and Blue — program listing (Antic, July 1987 (Vol. 6, No. 3), Game of the Month) — Heidi Brumbaugh
- Picture: A 7×7 board a few moves in: white squares are still hidden, blue ones are captured, and the dot is you. — Heidi Brumbaugh (program); screenshot by the site
- Antic, July 1987 - Vol. 6 No. 3 — article: Red, White and Blue, game by Heidi Brumbaugh — Heidi Brumbaugh, 1987
- Antic Software Archive — July 1987 - Vol. 6 No. 3 disk: RWB.BAS — AtariMagazines.com (Kevin Savetz), 1987
