home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / sharew / exoten / rec / gato.cnv < prev    next >
Encoding:
Text File  |  1990-07-09  |  3.8 KB  |  117 lines

  1. [GATO.CNV]
  2. [G. Cisneros, 15.1.85]
  3. [[This program plays tic-tac-toe on a board numbered as follows:
  4.  
  5.  1 | 2 | 3
  6. ---+---+---
  7.  4 | 5 | 6
  8. ---+---+---
  9.  7 | 8 | 9
  10. ]]
  11.  
  12. [get a move from the console]
  13. (()(
  14.     ((%r,TTY:Your turn; give me a number between 1 and 9: )) N
  15. )(0 1)(
  16.     ((and,<[9]>,<0>):(and,(IVL,1,9,),<1>)<>,<<
  17.             >>(IF,(2 3),<0>,(and,<[(#m,<1>)]>,<2>) <3>,<<
  18.                 >><2>X<3>,(%t,Not available)(t,<0>):(N))):
  19.     (<[9]><>,(T,(t,<=>)(%t)));
  20.     (<0>:,<0>:(N)):
  21. )) j
  22.  
  23. [display the board]
  24. (()()()(
  25.     (,<=>(WHILE,(0 1 2 3),<=>,<:0:><:1:><:2:><3>,<<
  26.         >>(%t, <0> | <1> | <2>(if,<3>,<[3]>,(^MJ)---+---+---,)),<<
  27.         >><3>,));
  28. )) t
  29.  
  30. [check whether winning is possible or an opponent win must be stopped]
  31. (()()(0 1 2 3)(
  32.     ((and,(OR,,<[3]>,<[6]>)(or,00 ,0 0, 00),<0><[3]>)<1>,<<
  33.         >>(,(t,<0>000<1>))(G));
  34.     ((and,(OR,,<[1]>,<[2]>)<<
  35.         >>(and,(or,0<[2]>0<[2]> ,0<[2]> <[2]>0, <[2]>0<[2]>0),<1>),<<
  36.         >><0><1>)<2>,(,(t,<0>(IF,(3 4),<1>,(and,<[6]>,<3>) ,<3>0,<<
  37.                     >><=>,(and,<[3]>,<3>) <4>,<3>0<4>,<<
  38.                     >><=>, <4>,0<4>)<2>))(G));
  39.     (0(and,<[3]>,<0>)0(and,<[3]>,<1>) ,(,(t,0<0>0<1>0))(G));
  40.     ( (and,<[3]>,<0>)0(and,<[3]>,<1>)0,(,(t,0<0>0<1>0))(G));
  41.     ((and,<[2]>,<0>)0<:1:>0<:2:> <3>,(,(t,<0>0<1>0<2>0<3>))(G));
  42.     ((and,<[2]>,<0>) <:1:>0<:2:>0<3>,(,(t,<0>0<1>0<2>0<3>))(G));
  43.     ((and,(OR,,<[3]>,<[6]>)(or,XX ,X X, XX),<0><[3]>,<0><1>)<2>,<<
  44.         >><0>(IF,(3 4),<1>,<3> <4>,<3>0<4>)<2>:);
  45.     ((and,(OR,,<[1]>,<[2]>)<<
  46.         >>(and,(or,X<[2]>X<[2]> ,X<[2]> <[2]>X, <[2]>X<[2]>X),<1>),<<
  47.         >><0><1>)<2>,<0>(IF,(3 4),<1>,(and,<[6]>,<3>) ,<3>0,<<
  48.                     >><=>,(and,<[3]>,<3>) <4>,<3>0<4>,<<
  49.                     >><=>, <4>,0<4>)<2>:);
  50.     (X(and,<[3]>,<0>)X(and,<[3]>,<1>) ,X<0>X<1>0:);
  51.     ( (and,<[3]>,<0>)X(and,<[3]>,<1>)X,0<0>X<1>X:);
  52.     ((and,<[2]>,<0>)X<:1:>X<:2:> <3>,<0>X<1>X<2>0<3>:);
  53.     ((and,<[2]>,<0>) <:1:>X<:2:>X<3>,<0>0<1>X<2>X<3>:);
  54. )) T
  55.  
  56. [first response]
  57. (()()(0 1)(
  58.     (    X    ,(j,(t,0   X    ):));
  59.     ((and,<[4]>,<0>) (and,<[4]>,<1>),(j,(t,<0>0<1>):));
  60. )) A
  61.  
  62. [second response: prevent double plays]
  63. (()()(0 1 2 3)(
  64.     (<-->:,(j,(t,<=>)));
  65.     ((and,(OR,X<[7]>X,<[2]>X<[3]>X<[2]>),<:1:> <0>),(j,(t,<1>0<0>):));
  66.     ((and,   <[3]>,<0>)(and,(or,X<[2]>,<[2]>X),<:1:><:2:><:3:>),<<
  67.         >>(j,(t,<0>(if,<1>, ,0)<2>(if,<3>, ,0)):));
  68.     ((and,(or,X<[2]>,<[2]>X),<:1:><:2:><:3:>)(and,<[3]>   ,<0>),<<
  69.         >>(j,(t,(if,<1>, ,0)<2>(if,<3>, ,0)<0>):));
  70.     ((and,(or,X<[8]>,<[6]>X<[2]>),<:0:><:1:>  0 <:2:><:3:> ),<<
  71.         >>(j,(t,(if,<0>, ,0)<1>  0 (if,<2>, ,0)<3> ):));
  72.     ((and,(or,<[2]>X<[6]>,<[8]>X), <:0:><:1:> 0  <:2:><:3:>),<<
  73.         >>(j,(t, <0>(if,<1>, ,0) 0  <2>(if,<3>, ,0)):));
  74.     (   (and,<[3]>,<0>)<:1:><:2:><:3:>,<<
  75.         >>(j,(t,   <0>(if,<0>,X0,0,<1>)<2>(if,<0>,X0,<3>,0)):));
  76.     (<:1:><:2:><:3:>(and,<[3]><0>)   ,<<
  77.         >>(j,(t,(if,<0>,X0,0,<1>)<2>(if,<0>,X0,<3>,0)<0>   ):));
  78.     ( <0>,(j,(t,0<0>):));
  79.     ((and,<[2]>,<0>) <1>,(j,(t,<0>0<1>):));
  80. )) B
  81.  
  82. [third response: choose the best position if stopping was not needed]
  83. (()()(0 1 2 3)(
  84.     (<>,);
  85.     (<-->:,(j,(t,<=>)));
  86.     ((and,<[3]>,<0>) 0 <1>,(j,(t,<0>00 <1>):));
  87.     (<:0:> (and,<[2]>,<1>)0(and,<[2]>,<2>) <:3:>,(j,(t,<0>0<1>0<2> <3>):));
  88.     ( <0>,(j,(t,0<0>):));
  89.     (<:0:><:1:> <2>,(j,(t,<0><1>0<2>):));
  90. )) C
  91.  
  92. [last response: necessarily a tie]
  93. (()()(0 1)(
  94.     (<>,);
  95.     (<-->:,(,(t,<=>))(%t,Tie));
  96.     (<0> <1>,(,(t,<0>0<1>))(%t,Tie));
  97. )) D
  98.  
  99. [main program]
  100. ((
  101.     ((and,<[1]>,<0>)) 0
  102.     ((and,<[1]>,<1>)) 1
  103.     ((and,<[1]>,<2>)) 2
  104.     ((and,<[1]>,<3>)) 3
  105. )(
  106.     ((%t, ====(>)  I win!  (<)====)) G
  107.     ((%r,TTY:t terminates<,> p plays<,> (<)return(>) gives directions: )) E
  108. )()(
  109.     (<>,(%t,This program plays tic-tac-toe on a board numbered(^MJ)<<
  110.         >> from 1 to 9 as follows:(^MJMJ) 1 | 2 | 3(^MJ)---+---+---<<
  111.         >>(^MJ) 4 | 5 | 6(^MJ)---+---+---(^MJ) 7 | 8 | 9)(E)):
  112.     ((or,P,p),(D,(C,(B,(A,(j,         :)))))(E)):
  113.     ((or,T,t),Stop);
  114.     (,(E)):
  115. ))
  116.  
  117. [end]