home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MISC / REC.ZIP / GATO.CNV < prev    next >
Encoding:
Text File  |  1986-12-01  |  3.6 KB  |  116 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. Press "return" to begin]]
  12.  
  13. [get a move from the console]
  14. (()(
  15.     ((%t,your turn: give me a number between 1 and 9)(%R)) N
  16. )(0 1)(
  17.     ((and,<[9]>,<0>):(and,(IVL,1,9,),<1>)<>,<<
  18.             >>(IF,(2 3),<0>,(and,<[(#m,<1>)]>,<2>) <3>,<<
  19.                 >><2>X<3>,(%t,Not available)(t,<0>):(N))):
  20.     (<[9]><>,(T,(t,<=>)(%t)));
  21.     (<0>:,<0>:(N)):
  22. )) j
  23.  
  24. [display the board]
  25. (()()()(
  26.     (,<=>(WHILE,(0 1 2 3),<=>,<:0:><:1:><:2:><3>,<<
  27.         >>(%t, <0> | <1> | <2>(if,<3>,<[3]>,(^MJ)---+---+---,)),<<
  28.         >><3>,));
  29. )) t
  30.  
  31. [check whether winning is possible or an opponent win must be stopped]
  32. (()()(0 1 2 3)(
  33.     ((and,(OR,,<[3]>,<[6]>)(or,00 ,0 0, 00),<0><[3]>)<1>,<<
  34.         >>(,(t,<0>000<1>))(G));
  35.     ((and,(OR,,<[1]>,<[2]>)<<
  36.         >>(and,(or,0<[2]>0<[2]> ,0<[2]> <[2]>0, <[2]>0<[2]>0),<1>),<<
  37.         >><0><1>)<2>,(,(t,<0>(IF,(3 4),<1>,(and,<[6]>,<3>) ,<3>0,<<
  38.                     >><=>,(and,<[3]>,<3>) <4>,<3>0<4>,<<
  39.                     >><=>, <4>,0<4>)<2>))(G));
  40.     (0(and,<[3]>,<0>)0(and,<[3]>,<1>) ,(,(t,0<0>0<1>0))(G));
  41.     ( (and,<[3]>,<0>)0(and,<[3]>,<1>)0,(,(t,0<0>0<1>0))(G));
  42.     ((and,<[2]>,<0>)0<:1:>0<:2:> <3>,(,(t,<0>0<1>0<2>0<3>))(G));
  43.     ((and,<[2]>,<0>) <:1:>0<:2:>0<3>,(,(t,<0>0<1>0<2>0<3>))(G));
  44.     ((and,(OR,,<[3]>,<[6]>)(or,XX ,X X, XX),<0><[3]>,<0><1>)<2>,<<
  45.         >><0>(IF,(3 4),<1>,<3> <4>,<3>0<4>)<2>:);
  46.     ((and,(OR,,<[1]>,<[2]>)<<
  47.         >>(and,(or,X<[2]>X<[2]> ,X<[2]> <[2]>X, <[2]>X<[2]>X),<1>),<<
  48.         >><0><1>)<2>,<0>(IF,(3 4),<1>,(and,<[6]>,<3>) ,<3>0,<<
  49.                     >><=>,(and,<[3]>,<3>) <4>,<3>0<4>,<<
  50.                     >><=>, <4>,0<4>)<2>:);
  51.     (X(and,<[3]>,<0>)X(and,<[3]>,<1>) ,X<0>X<1>0:);
  52.     ( (and,<[3]>,<0>)X(and,<[3]>,<1>)X,0<0>X<1>X:);
  53.     ((and,<[2]>,<0>)X<:1:>X<:2:> <3>,<0>X<1>X<2>0<3>:);
  54.     ((and,<[2]>,<0>) <:1:>X<:2:>X<3>,<0>0<1>X<2>X<3>:);
  55. )) T
  56.  
  57. [first response]
  58. (()()(0 1)(
  59.     (    X    ,(j,(t,0   X    ):));
  60.     ((and,<[4]>,<0>) (and,<[4]>,<1>),(j,(t,<0>0<1>):));
  61. )) A
  62.  
  63. [second response: prevent double plays]
  64. (()()(0 1 2 3)(
  65.     (<-->:,(j,(t,<=>)));
  66.     ((and,(OR,X<[7]>X,<[2]>X<[3]>X<[2]>),<:1:> <0>),(j,(t,<1>0<0>):));
  67.     ((and,   <[3]>,<0>)(and,(or,X<[2]>,<[2]>X),<:1:><:2:><:3:>),<<
  68.         >>(j,(t,<0>(if,<1>, ,0)<2>(if,<3>, ,0)):));
  69.     ((and,(or,X<[2]>,<[2]>X),<:1:><:2:><:3:>)(and,<[3]>   ,<0>),<<
  70.         >>(j,(t,(if,<1>, ,0)<2>(if,<3>, ,0)<0>):));
  71.     ((and,(or,X<[8]>,<[6]>X<[2]>),<:0:><:1:>  0 <:2:><:3:> ),<<
  72.         >>(j,(t,(if,<0>, ,0)<1>  0 (if,<2>, ,0)<3> ):));
  73.     ((and,(or,<[[2]>X<[6]>,<[8]>X), <:0:><:1:> 0  <:2:><:3:>),<<
  74.         >>(j,(t, <0>(if,<1>, ,0) 0  <2>(if,<3>, ,0)):));
  75.     (   (and,<[3]>,<0>)<:1:><:2:><:3:>,<<
  76.         >>(j,(t,   <0>(if,<0>,X0,0,<1>)<2>(if,<0>,X0,<3>,0)):));
  77.     (<:1:><:2:><:3:>(and,<[3]><0>)   ,<<
  78.         >>(j,(t,(if,<0>,X0,0,<1>)<2>(if,<0>,X0,<3>,0)<0>   ):));
  79.     ( <0>,(j,(t,0<0>):));
  80.     ((and,<[2]>,<0>) <1>,(j,(t,<0>0<1>):));
  81. )) B
  82.  
  83. [third response: choose the best position if stopping was not needed]
  84. (()()(0 1 2 3)(
  85.     (<>,);
  86.     (<-->:,(j,(t,<=>)));
  87.     ((and,<[3]>,<0>) 0 <1>,(j,(t,<0>00 <1>):));
  88.     (<:0:> (and,<[2]>,<1>)0(and,<[2]>,<2>) <:3:>,(j,(t,<0>0<1>0<2> <3>):));
  89.     ( <0>,(j,(t,0<0>):));
  90.     (<:0:><:1:> <2>,(j,(t,<0><1>0<2>):));
  91. )) C
  92.  
  93. [last response: necessarily a tie]
  94. (()()(0 1)(
  95.     (<>,);
  96.     (<-->:,(,(t,<=>))(%t,Tie));
  97.     (<0> <1>,(,(t,<0>0<1>))(%t,Tie));
  98. )) D
  99.  
  100. [main program]
  101. ((
  102.     ((and,<[1]>,<0>)) 0
  103.     ((and,<[1]>,<1>)) 1
  104.     ((and,<[1]>,<2>)) 2
  105.     ((and,<[1]>,<3>)) 3
  106. )(
  107.     ((%t, ====(>)  I win!  (<)====)) G
  108. )()(
  109.     (<>,(D,(C,(B,(A,(j,         :)))))<<
  110.         >>(%t,Answer t to terminate, h for help,<<
  111.         >> anything else to continue)<<
  112.         >>(if,(%R),(or,T,t),T,<=>,(or,H,h),(%Q),)):
  113.     (,Stop);
  114. ))
  115.  
  116. [end]