home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / sourcecode / general / oxo.amos / oxo.amosSourceCode < prev    next >
Encoding:
AMOS Source Code  |  1991-03-22  |  5.2 KB  |  238 lines

  1. ' ************************************** 
  2. ' ***        Noughts & Crosses       *** 
  3. ' ***        by John J. Cassar       *** 
  4. ' ************************************** 
  5. Set Buffer 10
  6. Close Workbench 
  7.    Unpack 6 To 0
  8.    Get Palette 0
  9.    Double Buffer 
  10.    Autoback 2
  11.    Dim LOC(8,3),PL(8),COM(8),CH(9),P(9),C(9)
  12.    TURN=1 : SP=2
  13.    Global LOC(),PL(),COM(),CH(),P(),C(),Z,PLY,SP,CONT,WIN,TURN,TU,FM
  14.    Colour 9,$C00 : Colour 10,$F60
  15.    Flash 11,"(FE0,30)(F00,5)"
  16.    INIT_ZONES
  17. GO:
  18.    OXO
  19.    If Z=1 Then Goto GO
  20.    Cls 0
  21.    Run "AutoExec.AMOS"
  22.    End 
  23. ' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  24. Procedure INIT_ZONES
  25.    Reserve Zone 17
  26.    Set Zone 1,70,40 To 122,78
  27.    Set Zone 2,130,40 To 185,78
  28.    Set Zone 3,193,40 To 248,78
  29.    Set Zone 4,65,86 To 122,127
  30.    Set Zone 5,130,86 To 185,127
  31.    Set Zone 6,193,86 To 248,127
  32.    Set Zone 7,65,135 To 122,175
  33.    Set Zone 8,130,135 To 185,175
  34.    Set Zone 9,193,135 To 248,175
  35. End Proc
  36. Procedure OXO
  37.    USE=0 : USE2=0 : TU=0 : Z=0 : FM=True : Ink 12,14
  38.    BEGIN
  39.   If TURN=1 Then TURN=2 Else TURN=1
  40.   If TURN=2
  41.     Text 105,200,"I Start First"
  42.      Wait(90)
  43.     Text 100,200,"             "
  44.   End If 
  45. ' =======================================
  46. GAME_END=False
  47. While GAME_END=False
  48.  If TURN=2 and TU=0 Then Goto C_F
  49.  PL_MOVE
  50.  CH_FOR_UWIN
  51.  If WIN=True Then Text 129,200,"You win" : SP=4 : WOW : GAME_END=True : Goto N_GAME
  52.  CH_FOR_DRAW
  53.  If CONT=False Then Text 100,200,"Draw Nobody Wins" : GAME_END=True : Goto N_GAME
  54. '
  55. C_F:
  56.  COMP_MOVE
  57.  CH_FOR_IWIN
  58.  If WIN=True Then Text 115,200,"   I win   " : SP=3 : WOW : GAME_END=True : Goto N_GAME
  59.  CH_FOR_DRAW
  60.  If CONT=False Then Text 100,200,"Draw Nobody Wins" : GAME_END=True
  61. N_GAME:
  62. Wend 
  63. Ink 4 : Text 55,220,"Left Button - Another Game"
  64. Text 65,230,"Right Button  - Bye-Bye"
  65. Z=0 : Repeat : Z=Mouse Key : Until Z<>0
  66. Wait Vbl 
  67. Text 100,200,"                    "
  68. Text 55,220,"                           "
  69. Text 65,230,"                        "
  70. Bob Off 
  71. End Proc
  72. Procedure WOW
  73. On Z Gosub D1,D2,D3,D4,D5,D6,D7,D8
  74. 'Bob Off J : Bob Off K : Bob Off L 
  75. DISPLAY[J] : DISPLAY[K] : DISPLAY[L]
  76. Pop Proc
  77. D1: J=5 : K=9 : L=1 : Return 
  78. D2: J=5 : K=7 : L=3 : Return 
  79. D3: J=5 : K=6 : L=4 : Return 
  80. D4: J=5 : K=8 : L=2 : Return 
  81. D5: J=1 : K=3 : L=2 : Return 
  82. D6: J=7 : K=9 : L=8 : Return 
  83. D7: J=1 : K=7 : L=4 : Return 
  84. D8: J=3 : K=9 : L=6 : Return 
  85. End Proc
  86. Procedure BEGIN
  87.    For T=1 To 9
  88.       CH(T)=0
  89.       P(T)=0
  90.       C(T)=0
  91.    Next T
  92.    Restore DAT1
  93.    For T=1 To 8
  94.       Read A,B,C
  95.       LOC(T,1)=A
  96.       LOC(T,2)=B
  97.    LOC(T,3)=C
  98.    Next T
  99. DAT1:
  100.    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
  101. End Proc
  102. Procedure DISPLAY[G]
  103.    On G Goto 1,2,3,4,5,6,7,8,9
  104.    1
  105.    Bob 1,65,35,SP
  106.    Pop Proc
  107.    2
  108.    Bob 2,130,35,SP
  109.    Pop Proc
  110.    3
  111.    Bob 3,193,35,SP
  112.    Pop Proc
  113.    4
  114.    Bob 4,65,86,SP
  115.    Pop Proc
  116.    5
  117.    Bob 5,130,86,SP
  118.    Pop Proc
  119.    6
  120.    Bob 6,193,86,SP
  121.    Pop Proc
  122.    7
  123.    Bob 7,65,135,SP
  124.    Pop Proc
  125.    8
  126.    Bob 8,130,135,SP
  127.    Pop Proc
  128.    9
  129.    Bob 9,193,135,SP
  130. End Proc
  131. Procedure BRAIN
  132.    PL(1)=P(5)+P(9)+P(1)
  133.    PL(2)=P(5)+P(7)+P(3)
  134.    PL(3)=P(5)+P(6)+P(4)
  135.    PL(4)=P(5)+P(8)+P(2)
  136.    PL(5)=P(1)+P(3)+P(2)
  137.    PL(6)=P(7)+P(9)+P(8)
  138.    PL(7)=P(1)+P(7)+P(4)
  139.    PL(8)=P(3)+P(9)+P(6)
  140. '
  141.    COM(1)=C(5)+C(9)+C(1)
  142.    COM(2)=C(5)+C(7)+C(3)
  143.    COM(3)=C(5)+C(6)+C(4)
  144.    COM(4)=C(5)+C(8)+C(2)
  145.    COM(5)=C(1)+C(3)+C(2)
  146.    COM(6)=C(7)+C(9)+C(8)
  147.    COM(7)=C(1)+C(7)+C(4)
  148.    COM(8)=C(3)+C(9)+C(6)
  149. End Proc
  150. Procedure TABLE[M]
  151.    For T=1 To 8
  152.       For G=1 To 3
  153.          If LOC(T,G)=M Then LOC(T,G)=0
  154.       Next G
  155.    Next T
  156.    CH(M)=1
  157. End Proc
  158. Procedure CH_FOR_UWIN
  159.     WIN=False
  160.     For T=1 To 8
  161.       If PL(T)=6 Then WIN=True : Z=T
  162.     Next T
  163. End Proc
  164. Procedure CH_FOR_IWIN
  165.     WIN=False
  166.     For T=1 To 8
  167.       If COM(T)=9 Then WIN=True : Z=T
  168.     Next T
  169. End Proc
  170. Procedure CH_FOR_DRAW
  171.    CONT=False
  172.    For T=1 To 9
  173.       If CH(T)=0 Then CONT=True
  174.    Next T
  175. End Proc
  176. Procedure PL_MOVE
  177.     PL_START:
  178.     Text 122,200,"Your Move"
  179.     Z=0
  180.     While Z=0
  181.       While Mouse Key=0 : Wend 
  182.       Z=Mouse Zone
  183.     Wend 
  184.     Text 122,200,"         "
  185.     Wait Vbl 
  186.     If CH(Z)<>0 Then Text 139,200,"USED" : Wait(40) : Goto PL_START
  187.       SP=2 : DISPLAY[Z]
  188.       P(Z)=2 : C(Z)=-10
  189.       BRAIN
  190.       TABLE[Z]
  191. End Proc
  192. Procedure COMP_MOVE
  193.     Text 130,200,"My Move    "
  194.     Text 70,210,"Thinking...Please Wait"
  195.     Wait(Rnd(100)+60)
  196.     Inc TU : CONT=False
  197.     If TU=3 Then BRAIN_LOAD
  198.     Text 70,210,"                      "
  199.     If CONT=True Then Goto COMP_GO
  200.     If FM=True Then FIRST_MOVE
  201.     If FM=True Then FM=False : Goto COMP_GO
  202.     K=-5 : FT=0
  203.    Repeat 
  204.     For T=1 To 8
  205.       If PL(T)>K and PL(T)<>FT Then K=PL(T) : S=T
  206.       If COM(T)>K and PL(T)<>FT Then K=COM(T) : S=T
  207.     Next T
  208.     SS=False
  209.     For Q=3 To 1 Step -1
  210.       If LOC(S,Q)<>0 Then PLY=LOC(S,Q) : SS=True
  211.     Next Q
  212.     If SS=False Then FT=K
  213.    Until SS=True
  214. COMP_GO:
  215.     SP=1 : DISPLAY[PLY]
  216.     P(PLY)=-4 : C(PLY)=3
  217.     BRAIN
  218.     TABLE[PLY]
  219. End Proc
  220. Procedure BRAIN_LOAD
  221.      If P(2)=2 and P(7)=2 and P(6)=2 and P(9)=0
  222.        PLY=9 : CONT=True : Inc USE
  223.      End If 
  224.      If USE=1 Then CONT=False
  225.      If P(1)=2 and P(6)=2 and P(8)=2 and P(9)=0
  226.        PLY=9 : CONT=True : Inc USE2
  227.      End If 
  228.      If USE2=1 Then CONT=False
  229. End Proc
  230. Procedure FIRST_MOVE
  231.      If Z<>5 and Rnd(7)<>3 Then PLY=5 : Pop Proc
  232.     Repeat 
  233.      FI=Rnd(3)
  234.      If FI=1 Then PLY=3
  235.      If FI=2 Then PLY=5
  236.      If FI=3 Then PLY=9
  237.     Until PLY<>Z
  238. End Proc