forked from OilegorAerep/CircuitMaze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoCo ECB PCBoard Maze
65 lines (65 loc) · 2.55 KB
/
CoCo ECB PCBoard Maze
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
10 PCLEAR 4:PMODE 4,1:PCLS:SCREEN 1,1:REM INITIALIZE SCREEN
20 GOSUB 9000: REM INITIALIZE
30 GOSUB 1000: REM CHOOSE FREE SPOT
40 IF NOT OK THEN END : REM END IF NO SPOTS LEFT
50 GOSUB 2000: REM BEGIN TRACE
60 GOSUB 3000: REM CHOOSE ANY FREE DIRECTION
70 GOSUB 4000: REM DRAW LINE
80 GOSUB 5000: REM BLOCK DIRECTIONS IN CURRENT & SURROUNDING SPOTS
90 GOSUB 6000: REM CHOOSE NEXT FREE DIRECTION
100 IF OK THEN 70
110 GOSUB 7000: REM END TRACE
120 GOTO 30
1000 REM CHOOSE FREE SPOT
1010 X=RND(MX):Y=RND(MY):XX=X:YY=Y
1020 IF P(X,Y)<>B8 THEN OK=YES:RETURN
1030 X=X+1:IF X>MX THEN X=1:Y=Y+1:IF Y>MY THEN Y=1
1040 IF X=XX AND Y=YY THEN OK=NO:RETURN
1050 GOTO 1020
2000 REM BEGIN TRACE
2010 REM
2020 PX=X*8:PY=Y*8:PSET(PX,PY):PSET(PX+1,PY+1):PSET(PX-1,PY+1):PSET(PX-1,PY-1):PSET(PX+1,PY-1):RETURN
3000 REM CHOOSE ANY FREE DIRECTION
3010 I=RND(8)
3020 FOR I=I TO I+7:D=I AND 7
3030 IF (P(X,Y) AND B(D))=0 THEN I=BREAK
3040 NEXT I: RETURN
4000 REM DRAW LINE
4010 X2=X+DX(D):Y2=Y+DY(D)
4020 LINE(X*8,Y*8)-(X2*8,Y2*8),PSET:RETURN
5000 REM BLOCK DIRECTIONS IN CURRENT & SURROUNDING SPOTS
5010 P(X,Y)=B8
5020 FOR I=0 TO 7:XX=X+DX(I):YY=Y+DY(I):B=B((I+4) AND 7)
5030 GOSUB 5500:NEXT I
5040 IF D AND 1 THEN 5095
5050 REM DIAGONAL
5060 XX=X+DX((D+1) AND 7):YY=Y+DY((D+1) AND 7):B=B((D-1) AND 7) OR B((D-2) AND 7)
5070 GOSUB 5500
5080 XX=X+DX((D-1) AND 7):YY=Y+DY((D-1) AND 7):B=B((D+1) AND 7) OR B((D+2) AND 7)
5090 GOSUB 5500:RETURN
5095 REM ORTHOGONAL
5100 XX=X+DX((D+2) AND 7):YY=Y+DY((D+2) AND 7):B=B((D-1) AND 7):GOSUB 5500
5110 XX=X+DX((D-2) AND 7):YY=Y+DY((D-2) AND 7):B=B((D+1) AND 7):GOSUB 5500
5120 RETURN
5500 IF P(XX,YY) <> B8 THEN P(XX,YY)=P(XX,YY) OR B
5510 IF P(XX,YY)=B8 THEN PSET(XX*8,YY*8)
5520 RETURN
6000 REM CHOOSE NEXT FREE DIRECTION
6010 X=X2:Y=Y2:S=1-2*RND(2):A=(RND(0)>.75 AND 1)
6020 OK=NO:FOR I=0 TO 4:D2=(D+DD(A)*S) AND 7
6030 IF (P(X,Y) AND B(D2))=0 THEN D=D2:OK=YES:I=BREAK:GOTO 6050
6040 A=A+1:IF A>4 THEN A=0
6050 NEXT I:RETURN
7000 REM END TRACE
7010 P(X,Y)=B8
7020 PX=X*8:PY=Y*8:PSET(PX,PY):PSET(PX+1,PY+1):PSET(PX-1,PY+1):PSET(PX-1,PY-1):PSET(PX+1,PY-1):RETURN
9000 REM INITIALIZE
9010 ' DIM X,Y,D,XX,YY,X2,Y2,D2,I,B8,B,S,A,MX,MY,OK,YES,NO
9020 MX=31:MY=23:YES=NOT(0):NO=0:BREAK=2^125
9030 DIM P(MX+1,MY+1),B(7),DX(7),DY(7),DD(4)
9040 B8=0:FOR I=0 TO 7:B(I)=2^I:B8=B8 OR B(I):READ DX(I),DY(I):NEXT I
9050 DATA 1,-1,0,-1,-1,-1,-1,0,-1,1,0,1,1,1,1,0
9060 FOR I=1 TO MX:P(I,1)=B(0) OR B(1) OR B(2):P(I,MY)=B(4) OR B(5) OR B(6):NEXT
9070 FOR I=1 TO MY:P(1,I)=P(1,I) OR B(2) OR B(3) OR B(4):P(MX,I)=P(MX,I) OR B(6) OR B(7) OR B(0):NEXT
9080 FOR I=0 TO 4:READ DD(I):DATA 0,-1,1,-2,2
9090 RETURN