Pegboard
- Type
- Game
- Category
- Peg solitaire puzzle
- Author
- Robert "Rassilon" Patton
- Published in
- Antic, January 1988 (Vol. 6, No. 9), Game of the Month ("Rassilon's Triple-Header")
- Year
- 1988
- Language
- Atari BASIC
- Requirements
- Any Atari 8-bit, any memory size, Atari BASIC, joystick in port 1
- Related
- Bounce, Rollout, Red Squares, Biffdrop, Black Box, Diamond Dave
About the program
The second game in Robert "Rassilon" Patton's January 1988 Triple-Header (the others are Rollout and Bounce) is the old board puzzle peg solitaire. The board is the 33-hole cross, and the variant is "Center to Center": the centre hole starts empty and the goal is to finish with a single peg in it. A peg is removed by jumping an adjacent peg horizontally or vertically into an empty hole, never diagonally. When no more jumps are possible, the program rates you on the number of pegs left. Three or four is average, two is excellent, one is genius, and one peg in the centre earns "A MENSA ATTEMPT". The article said it can be done in 18 moves if a chain of jumps counts as one.
Typing it in
The program is short and almost all plain text. The only special characters are in the title on lines 520–530, where {inv}…{/inv} means type with the Atari (inverse) key on, and {BELL} in lines 80 and 310 (ESC, then CTRL-2). The pegs are the letter O, the border is drawn with COLOR 131 (character code 131, which GRAPHICS 1 shows as a purple # lattice), and the cursor is COLOR 207, an inverse O in another colour.
How to play
Move the stick to begin. That removes the centre peg and puts the cursor there. Steer the cursor onto a peg and press the button: it changes colour and a tone sounds. Then move to an empty hole two places away, in a straight line, and press the button again to jump. The jumped peg disappears. To change your mind, go back to the selected peg and press the button. The move counter is in the top-left corner.
The printed article says to press HELP for your score, but the program actually uses SELECT, as its own on-screen prompt says. If there's still a legal jump, it tells you "you are not done yet". START restarts at any time.
How it works
The board is the data. There's no array. Every test uses LOCATE to read the character at a screen position: 79 is a peg (O), 32 is a hole, and 131 is the border, which the cursor isn't allowed to enter. A jump is legal (line 90) if the target is empty and exactly two cells away in a straight line. Line 100 then wipes the start, middle and end cells by drawing a line of spaces from start to target with PLOT/DRAWTO, and puts a peg back on the target.
The "are you done?" check (lines 120–190) is cleverer. DATA line 300 gives the centres of four 3×3 patches, one on each arm of the cross, which between them cover almost the whole board. From every cell in each patch, the program LOCATEs three cells across and three cells down, looking for a peg–peg–hole or hole–peg–peg pattern, which means a jump is still possible. When the DATA runs out, TRAP 200 catches the error and goes on to count the pegs. That's using an error as the end-of-data signal.
Variations to try
- Start with a different empty hole (change
C=9:R=9in line 480) to try other classic peg solitaire puzzles. - Add a "take back" key that remembers the last jump's three cells and restores them.
Listing
5 REM PEGBOARD
10 REM BY ROBERT PATTON
15 REM (c)1987, ANTIC PUBLISHING
20 GOSUB 450
30 GOSUB 330
40 IF P<>79 THEN 30
50 UPC=C:UPR=R:GOSUB 440
60 GOSUB 330
70 M=M+1:POSITION 0,0:? #6;M
80 IF C=UPC AND R=UPR THEN ? "{BELL}";:M=M-1:GOTO 30
90 IF P<>32 OR (ABS(UPC-C)<>2 AND ABS(UPR-R)<>2) OR (ABS(UPC-C)=2 AND ABS(UPR-R)=2) THEN M=M-1:GOTO 60
100 DNC=C:DNR=R:COLOR 32:PLOT UPC,UPR:DRAWTO DNC,DNR:COLOR 79:PLOT DNC,DNR
110 GOSUB 440:L=79:GOTO 30
120 RESTORE 300
130 TRAP 200:READ CKC,CKR
140 FOR CC=CKC-1 TO CKC+1
150 FOR RR=CKR-1 TO CKR+1
160 LOCATE CC,RR,LL0:LOCATE CC,RR+1,LL1:LOCATE CC,RR+2,LL2:LOCATE CC+1,RR,L1L:LOCATE CC+2,RR,L2L
170 IF (LL0=79 AND LL1=79 AND LL2=32) OR (LL0=79 AND L1L=79 AND L2L=32) THEN POP :POP :GOSUB 310:RETURN
180 IF (LL0=32 AND LL1=79 AND LL2=79) OR (LL0=32 AND L1L=79 AND L2L=79) THEN POP :POP :GOSUB 310:RETURN
190 NEXT RR:NEXT CC:GOTO 130
200 FOR CC=6 TO 12:FOR RR=6 TO 12:LOCATE CC,RR,LL:SOUND 0,2*CC*RR+LL,10,6
210 IF LL=79 THEN PEG=PEG+1
220 NEXT RR:NEXT CC:SOUND 0,0,0,0
230 T$=" NOT AN"
240 IF PEG<5 THEN T$=" AVERAGE"
250 IF PEG<3 THEN T$=" EXCELLENT"
260 IF PEG<2 THEN T$=" GENIUS":LOCATE 9,9,X:IF X=79 THEN T$=" A MENSA"
270 POSITION 0,19:? #6;T$;" ATTEMPT":POSITION 0,0:? #6;"{inv}FIRE STARTS NEW GAME{/inv}";
280 IF STRIG(0)=1 THEN 280
290 RUN
300 DATA 9,7,11,9,9,11,7,9
310 POSITION 0,19:? #6;"you are not done yet";:? "{BELL}";
320 FOR X=0 TO 333:NEXT X:POSITION 0,19:? #6;" ";:RETURN
330 S=PEEK(632):T=PEEK(644)
340 IF PEEK(H)=5 THEN GOSUB 120
350 IF PEEK(53279)=6 THEN RUN
360 IF S=15 AND T=0 THEN P=L:RETURN
370 IF S=15 THEN 330
380 COLOR L:PLOT C,R
390 LC=C:LR=R:LL=L
400 C=C+((S=5)+(S=6)+(S=7))-((S=9)+(S=10)+(S=11)):R=R+((S=5)+(S=9)+(S=13))-((S=6)+(S=10)+(S=14))
410 LOCATE C,R,L:IF L=131 THEN C=LC:R=LR:L=LL
420 COLOR 207:PLOT C,R
430 GOTO 330
440 FOR W=0 TO 50:NEXT W:SOUND 0,30,10,10:W=2^2:SOUND 0,0,0,0:RETURN
450 DIM T$(20):GRAPHICS 1:POKE 752,1:H=53279
460 FOR C=8 TO 10:FOR R=6 TO 12:POSITION C,R:? #6;"O";:NEXT R:NEXT C
470 FOR C=6 TO 12:FOR R=8 TO 10:POSITION C,R:? #6;"O";:NEXT R:NEXT C
480 GOSUB 490:C=9:R=9:L=32:RETURN
490 COLOR 131:PLOT 7,5
500 DRAWTO 11,5:DRAWTO 11,7:DRAWTO 13,7:DRAWTO 13,11:DRAWTO 11,11:DRAWTO 11,13:DRAWTO 7,13:DRAWTO 7,11
510 DRAWTO 5,11:DRAWTO 5,7:DRAWTO 7,7:DRAWTO 7,5
520 ? "{TAB}{inv}::PEGBOARD:by:RASSILON::{/inv}":? "{TAB}{inv}::::::::::::::::::::::::{/inv}"
530 ? " Move STICK to remove first PEG":? " Press <SELECT> for SCORE";:RETURN
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: PEGBOARD.BAS.
Credits
- Program listing: Pegboard — program listing (Antic, January 1988 (Vol. 6, No. 9), Game of the Month ("Rassilon's Triple-Header")) — Robert "Rassilon" Patton
- Picture: The cross board after the first move, with the cursor (blue) on the peg that has just jumped. — Robert "Rassilon" Patton (program); screenshot by the site
- Antic, January 1988 - Vol. 6 No. 9 — article: games by Robert "Rassilon" Patton — Robert "Rassilon" Patton, 1988
- Antic Software Archive — January 1988 - Vol. 6 No. 9 disk: PEGBOARD.BAS — AtariMagazines.com (Kevin Savetz), 1988
