home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1991-03-22 | 5.2 KB | 238 lines |
- ' **************************************
- ' *** Noughts & Crosses ***
- ' *** by John J. Cassar ***
- ' **************************************
- Set Buffer 10
- Close Workbench
- Unpack 6 To 0
- Get Palette 0
- Double Buffer
- Autoback 2
- Dim LOC(8,3),PL(8),COM(8),CH(9),P(9),C(9)
- TURN=1 : SP=2
- Global LOC(),PL(),COM(),CH(),P(),C(),Z,PLY,SP,CONT,WIN,TURN,TU,FM
- Colour 9,$C00 : Colour 10,$F60
- Flash 11,"(FE0,30)(F00,5)"
- INIT_ZONES
- GO:
- OXO
- If Z=1 Then Goto GO
- Cls 0
- Run "AutoExec.AMOS"
- End
- ' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Procedure INIT_ZONES
- Reserve Zone 17
- Set Zone 1,70,40 To 122,78
- Set Zone 2,130,40 To 185,78
- Set Zone 3,193,40 To 248,78
- Set Zone 4,65,86 To 122,127
- Set Zone 5,130,86 To 185,127
- Set Zone 6,193,86 To 248,127
- Set Zone 7,65,135 To 122,175
- Set Zone 8,130,135 To 185,175
- Set Zone 9,193,135 To 248,175
- End Proc
- Procedure OXO
- USE=0 : USE2=0 : TU=0 : Z=0 : FM=True : Ink 12,14
- BEGIN
- If TURN=1 Then TURN=2 Else TURN=1
- If TURN=2
- Text 105,200,"I Start First"
- Wait(90)
- Text 100,200," "
- End If
- ' =======================================
- GAME_END=False
- While GAME_END=False
- If TURN=2 and TU=0 Then Goto C_F
- PL_MOVE
- CH_FOR_UWIN
- If WIN=True Then Text 129,200,"You win" : SP=4 : WOW : GAME_END=True : Goto N_GAME
- CH_FOR_DRAW
- If CONT=False Then Text 100,200,"Draw Nobody Wins" : GAME_END=True : Goto N_GAME
- '
- C_F:
- COMP_MOVE
- CH_FOR_IWIN
- If WIN=True Then Text 115,200," I win " : SP=3 : WOW : GAME_END=True : Goto N_GAME
- CH_FOR_DRAW
- If CONT=False Then Text 100,200,"Draw Nobody Wins" : GAME_END=True
- N_GAME:
- Wend
- Ink 4 : Text 55,220,"Left Button - Another Game"
- Text 65,230,"Right Button - Bye-Bye"
- Z=0 : Repeat : Z=Mouse Key : Until Z<>0
- Wait Vbl
- Text 100,200," "
- Text 55,220," "
- Text 65,230," "
- Bob Off
- End Proc
- Procedure WOW
- On Z Gosub D1,D2,D3,D4,D5,D6,D7,D8
- 'Bob Off J : Bob Off K : Bob Off L
- DISPLAY[J] : DISPLAY[K] : DISPLAY[L]
- Pop Proc
- D1: J=5 : K=9 : L=1 : Return
- D2: J=5 : K=7 : L=3 : Return
- D3: J=5 : K=6 : L=4 : Return
- D4: J=5 : K=8 : L=2 : Return
- D5: J=1 : K=3 : L=2 : Return
- D6: J=7 : K=9 : L=8 : Return
- D7: J=1 : K=7 : L=4 : Return
- D8: J=3 : K=9 : L=6 : Return
- End Proc
- Procedure BEGIN
- For T=1 To 9
- CH(T)=0
- P(T)=0
- C(T)=0
- Next T
- Restore DAT1
- For T=1 To 8
- Read A,B,C
- LOC(T,1)=A
- LOC(T,2)=B
- LOC(T,3)=C
- Next T
- DAT1:
- Data 5,9,1,5,7,3,5,6,4,5,8,2,1,3,2,7,9,8,1,7,4,3,9,6
- End Proc
- Procedure DISPLAY[G]
- On G Goto 1,2,3,4,5,6,7,8,9
- 1
- Bob 1,65,35,SP
- Pop Proc
- 2
- Bob 2,130,35,SP
- Pop Proc
- 3
- Bob 3,193,35,SP
- Pop Proc
- 4
- Bob 4,65,86,SP
- Pop Proc
- 5
- Bob 5,130,86,SP
- Pop Proc
- 6
- Bob 6,193,86,SP
- Pop Proc
- 7
- Bob 7,65,135,SP
- Pop Proc
- 8
- Bob 8,130,135,SP
- Pop Proc
- 9
- Bob 9,193,135,SP
- End Proc
- Procedure BRAIN
- PL(1)=P(5)+P(9)+P(1)
- PL(2)=P(5)+P(7)+P(3)
- PL(3)=P(5)+P(6)+P(4)
- PL(4)=P(5)+P(8)+P(2)
- PL(5)=P(1)+P(3)+P(2)
- PL(6)=P(7)+P(9)+P(8)
- PL(7)=P(1)+P(7)+P(4)
- PL(8)=P(3)+P(9)+P(6)
- '
- COM(1)=C(5)+C(9)+C(1)
- COM(2)=C(5)+C(7)+C(3)
- COM(3)=C(5)+C(6)+C(4)
- COM(4)=C(5)+C(8)+C(2)
- COM(5)=C(1)+C(3)+C(2)
- COM(6)=C(7)+C(9)+C(8)
- COM(7)=C(1)+C(7)+C(4)
- COM(8)=C(3)+C(9)+C(6)
- End Proc
- Procedure TABLE[M]
- For T=1 To 8
- For G=1 To 3
- If LOC(T,G)=M Then LOC(T,G)=0
- Next G
- Next T
- CH(M)=1
- End Proc
- Procedure CH_FOR_UWIN
- WIN=False
- For T=1 To 8
- If PL(T)=6 Then WIN=True : Z=T
- Next T
- End Proc
- Procedure CH_FOR_IWIN
- WIN=False
- For T=1 To 8
- If COM(T)=9 Then WIN=True : Z=T
- Next T
- End Proc
- Procedure CH_FOR_DRAW
- CONT=False
- For T=1 To 9
- If CH(T)=0 Then CONT=True
- Next T
- End Proc
- Procedure PL_MOVE
- PL_START:
- Text 122,200,"Your Move"
- Z=0
- While Z=0
- While Mouse Key=0 : Wend
- Z=Mouse Zone
- Wend
- Text 122,200," "
- Wait Vbl
- If CH(Z)<>0 Then Text 139,200,"USED" : Wait(40) : Goto PL_START
- SP=2 : DISPLAY[Z]
- P(Z)=2 : C(Z)=-10
- BRAIN
- TABLE[Z]
- End Proc
- Procedure COMP_MOVE
- Text 130,200,"My Move "
- Text 70,210,"Thinking...Please Wait"
- Wait(Rnd(100)+60)
- Inc TU : CONT=False
- If TU=3 Then BRAIN_LOAD
- Text 70,210," "
- If CONT=True Then Goto COMP_GO
- If FM=True Then FIRST_MOVE
- If FM=True Then FM=False : Goto COMP_GO
- K=-5 : FT=0
- Repeat
- For T=1 To 8
- If PL(T)>K and PL(T)<>FT Then K=PL(T) : S=T
- If COM(T)>K and PL(T)<>FT Then K=COM(T) : S=T
- Next T
- SS=False
- For Q=3 To 1 Step -1
- If LOC(S,Q)<>0 Then PLY=LOC(S,Q) : SS=True
- Next Q
- If SS=False Then FT=K
- Until SS=True
- COMP_GO:
- SP=1 : DISPLAY[PLY]
- P(PLY)=-4 : C(PLY)=3
- BRAIN
- TABLE[PLY]
- End Proc
- Procedure BRAIN_LOAD
- If P(2)=2 and P(7)=2 and P(6)=2 and P(9)=0
- PLY=9 : CONT=True : Inc USE
- End If
- If USE=1 Then CONT=False
- If P(1)=2 and P(6)=2 and P(8)=2 and P(9)=0
- PLY=9 : CONT=True : Inc USE2
- End If
- If USE2=1 Then CONT=False
- End Proc
- Procedure FIRST_MOVE
- If Z<>5 and Rnd(7)<>3 Then PLY=5 : Pop Proc
- Repeat
- FI=Rnd(3)
- If FI=1 Then PLY=3
- If FI=2 Then PLY=5
- If FI=3 Then PLY=9
- Until PLY<>Z
- End Proc