"Flood" in Applesoft.

Anything to do with New Zealand Classic or Vintage Computing not covered in the other forums

"Flood" in Applesoft.

Postby Gibsaw on Sat Aug 13, 2016 7:08 pm

Here's something interesting I hacked together today for people to play with. It's a very rough version of flood for the Apple II in "applesoft".

It's nothing fancy and it's slow as all bejesus, but for me it was an exercise in implementing my workarounds and stack for the recursion involved and quite fun working around a hardware stack that can only really do about 21 subroutine calls deep.

The colours are in order along the bottom. Use numbers 1-6 and 0 to quit. Have a play. :D

Code: Select all
REM Apple II Flood Clone
REM Devlin Sakey 2016

REM Define any arrays and constants

REM Constants
REM STACK MAX
10 SM=400
REM Define X/Y Coordinate Stack for board flood
20 DIM SX%(SM) : DIM SY%(SM) : DIM RL%(SM)

REM Initialise the game
REM BOARD SIZE MAX
100 BS=10
110 BX=BS-1: BY=BS-1

REM Main Loop
200 GR : TN=0
210 GOSUB 1100: OC=SCRN(0,0)
220 INPUT "NEXT COLOR:";C: IF C=0 THEN TEXT:HOME:END
225 TN=TN+1
230 NC=C
240 COLOR=NC
250 X=0 : Y=0: GOSUB 2000: NL=1: GOTO 1000
260 OC=NC
270 WN=1:CC=SCRN(0,0): FOR I=0 TO BY : FOR J=0 TO BX :
280 IF WN=1 THEN IF SCRN(J*2,I*2) <> CC THEN WN=0
290 NEXT J:?".";:NEXT I:?
300 IF WN=1 THEN PRINT "YOU WON IN ";TN; " TURNS": GOTO 200

999 GOTO 220

REM Flood the board
1000 IF NC=OC OR SCRN(X*2,Y*2)<>OC THEN ON NL GOTO 260,1025,1035,1045,1055 : PRINT "MISSED": STOP
1010 COLOR=15: HLIN X*2,X*2+1 AT Y*2 : HLIN X*2,X*2+1 AT Y*2 + 1
1020 IF NOT (X > 0)  THEN GOTO 1030
1021 GOSUB 2010 : NL=2:X=X-1 : GOTO 1000
1025 GOSUB 2030
1030 IF NOT (X < BX) THEN GOTO 1040
1031 GOSUB 2010 : NL=3:X=X+1 : GOTO 1000
1035 GOSUB 2030
1040 IF NOT (Y > 0)  THEN GOTO 1050
1041 GOSUB 2010 : NL=4:Y=Y-1 : GOTO 1000
1045 GOSUB 2030
1050 IF NOT (Y < BX) THEN GOTO 1090
1051 GOSUB 2010 : NL=5:Y=Y+1 : GOTO 1000
1055 GOSUB 2030
1090 COLOR=NC: HLIN X*2,X*2+1 AT Y*2 : HLIN X*2,X*2+1 AT Y*2 + 1
1099 ON NL GOTO 260,1025,1035,1045,1055 : PRINT "1099: MISSED": STOP

REM INIT THE BOARD - Only a basic random board. No intelligence involved.
1100 PRINT "BOARD DIMENSIONS:";BS;",";BS
1110 FOR I = 0 TO BY
1120 FOR J = 0 TO BX
1130 COLOR=INT(RND(1)*6)+1: HLIN J*2,J*2+1 AT I*2 : HLIN J*2,J*2+1 AT I*2 + 1
1140 NEXT J,I
1150 FOR I=0 TO 5: COLOR=I+1: PLOT I*2,39: NEXT I
1160 RETURN

REM Clear the Stack
2000 SP=-1
2005 RETURN

REM Push onto the Stack.
2010 IF SP=SM THEN PRINT "STACK IS FULL": STOP
2020 SP=SP+1: SX%(SP)=X: SY%(SP)=Y: RL%(SP)=NL: RETURN

REM Pop from the stack
2030 IF SP=-1 THEN PRINT "STACK IS EMPTY" : STOP
2040 X=SX%(SP): Y=SY%(SP): NL=RL%(SP): SP=SP-1: RETURN
"dsakey" on trademe. Apple II's are my thing.
Gibsaw
 
Posts: 709
Joined: Sun Dec 19, 2010 2:45 pm
Location: Auckland

Return to General

Who is online

Users browsing this forum: No registered users and 10 guests

cron