         Edinburgh IMP77 Compiler - Version 8.4

    1  %EXTERNALROUTINE DRAUGHTS(%STRING(12) S)
    2  !%EXTERNALROUTINESPEC CPULIMIT (%STRING(255) S)
    3  !%EXTERNALROUTINESPEC PROMPT(%STRING(15) S)
    4  %OWNINTEGER MOB WT = 6
    5  %CONSTINTEGER TRUE =1, FALSE = 0
    6  
    7  %OWNINTEGER BACK WT = 4
    8  %OWNINTEGER CENT WT = 4
    9  %OWNINTEGER ADV1 WT = 450
   10  %OWNINTEGER ADV2 WT = 50
   11  %OWNINTEGER CRAMP WT = 6
   12  %OWNINTEGER MON = 'Q'
   13  %OWNINTEGER A WIN = 0
   14  %OWNINTEGER SEARCH LIMIT = 3
   15  %OWNINTEGER CROWN = 1800
   16  %OWNINTEGERARRAY BACK1(1:5) = 77, 75, 73, 71, 64
   17  %OWNINTEGERARRAY BACK2(1:5) =  0,  2,  4,  6, 13
   18  %OWNINTEGERARRAY CENTSQ(0:7) = 51, 53, 42, 44, 33, 35, 24, 26
   19  %OWNINTEGERARRAY MOVE(0:7) =  9, 18, 11, 22, -9,-18,-11,-22
   20  %OWNINTEGERARRAY PLAYER1(-1:26) =     'W',    1,
   21+    77,   75,   73,   71,   64,   66,   62,   60,   57,   55,   53,   51,
   22+  1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000,
   23+    12,    0
   24  %OWNINTEGERARRAY PLAYER2(-1:26) =     'B',    2,
   25+     0,    2,    4,    6,   13,   11,   15,   17,   20,   22,   24,   26,
   26+  1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000,
   27+    12,    0
   28  %OWNINTEGERARRAY BOARD(-1:78) = %C
   29+   ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
   30+   ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
   31+   ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
   32+   ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
   33+   ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
   34+   ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
   35+   ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
   36+   ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
   37  ! This program compiles and runs under i2c if the following auto arrays are converted into own arrays.
   38  ! As soon as auto arrays are handled properly this program should run without modification.
   39  %INTEGERARRAY MIN(1:12)
   40  %INTEGERARRAY MAX(1:12)
   41  %INTEGERARRAY REPLY(1:9)
   42  %INTEGERARRAY COMP(-1:26)
   43  %INTEGERARRAY OPP(-1:26)
   44  %INTEGERNAME COMPNUM, OPPNUM
   45  %INTEGERARRAY PSTACK(1:12);            ! piece position take stack
   46  %INTEGERARRAY TSTACK(1:12);            ! piece type stack
   47  %INTEGERARRAY NSTACK(1:12);            ! piece number stack
   48  %OWNINTEGER SP;                        ! stack pointer
   49  %OWNINTEGER ME = 1
   50  %OWNINTEGER ONE = 1
   51  %OWNINTEGER TWO = 2
   52  %OWNINTEGER THREE = 3
   53  %INTEGER BEST PIECE, BEST MOVE, BEST TAKE
   54  %INTEGER VALUEB, I, P, M, PIECE, JMAN, JUMP, DIF, MODIF, MORE
   55  %INTEGER OLDPOS, NEWPOS, LASTPOS, COMPOS
   56  %INTEGER NODES, PLY NUMBER, EXPECTED MOVE
   57  %INTEGER A,B,C,POS
   58  
   59  !*   P L A Y I N G   F U N C T I O N S
   60  
   61     %INTEGERFN VALID POS(%INTEGER POS)
   62     %INTEGER I
   63        ! on the board?
   64        I = POS>>1
   65        %RESULT = -1 %IF POS < 0 %OR POS > 77 %C
   66+                    %OR I = 4 %OR I = 14 %OR I = 24 %OR I = 34
   67        ! square vacant?
   68        %CYCLE I = 1, 1, 12
   69           %RESULT = 1 %IF (I <= COMPNUM %AND POS = COMP(I)) %C
   70+                      %OR (I <= OPPNUM %AND POS = OPP(I))
   71        %REPEAT
   72        %RESULT = 0
   73     %END
   74  
   75     %INTEGERFN VALID MOVE(%INTEGER M, P, %INTEGERARRAYNAME COMP, OPP)
   76        %INTEGER CPOS, I, T
   77        %UNLESS COMP(P+12) = CROWN %START
   78           %IF COMP(0) = 1 %START;       ! player 1
   79              %RESULT = -1 %IF M&4 = 0;  ! backward move
   80           %FINISH %ELSE %START;         ! else player 2
   81              %RESULT = -1 %IF M&4 # 0;  ! backward move
   82           %FINISH
   83        %FINISH
   84        CPOS = COMP(P)
   85        %RESULT = -1 %UNLESS VALID POS(CPOS+MOVE(M)) = 0
   86        %RESULT = 0 %IF M&1 = 0;         ! ordinary move
   87        %RESULT = -1 %IF OPP(25)=0
   88        I = CPOS+MOVE(M-1);              !  else take-move
   89        %CYCLE T = 1, 1, OPP(25)
   90           %RESULT = T %IF I = OPP(T);   ! piece to take?
   91        %REPEAT
   92        %RESULT = -1
   93     %END
   94  
   95     %INTEGERFN PENDING MOVE(%INTEGERARRAYNAME COMP, OPP)
   96     %INTEGER P, M, T, COMPNUM
   97        COMPNUM = COMP(25)
   98        %RESULT = -1 %IF COMPNUM = 0;    ! no pieces left!!
   99        %CYCLE P = 1, 1, COMPNUM
  100           %CYCLE M = 1, 2, 7
  101              T = VALID MOVE(M, P, COMP, OPP)
  102              %RESULT = P %IF T > 0;     ! return piece doing take
  103           %REPEAT
  104        %REPEAT
  105        ! ordinary moves
  106        %CYCLE P = 1, 1, COMPNUM
  107           %CYCLE M = 0, 2, 6
  108              T = VALID MOVE(M, P, COMP, OPP)
  109              %RESULT = 0 %IF T = 0;     ! move ok
  110           %REPEAT
  111        %REPEAT
  112        %RESULT = -1;                   ! no moves
  113     %END
  114  
  115     %INTEGERFN CROWNING(%INTEGER POS, PLAYER)
  116        ! assumes valid pos
  117        %RESULT=TRUE %IF (PLAYER = 1 %AND POS < 7) %C
  118+             %OR (PLAYER = 2 %AND POS > 70)
  119        %RESULT=FALSE
  120     %END
  121  
  122     %INTEGERFN MOD(%INTEGER N)
  123  
  124        %RESULT = -N %IF N<0
  125        %RESULT = N
  126  
  127     %END
  128  
  129     %INTEGERFN VALUE OF SIDE(%INTEGERARRAYNAME COMP, OPP)
  130     %INTEGER V1, V2, V3, V4, V5, V6, V7
  131     %INTEGER P, PP, M, MM, MV, ADV1, VM, PLAYER
  132     %INTEGERNAME CPOS, CTYPE
  133        PLAYER = COMP(0)
  134  
  135        ! back control
  136        V2 = 0
  137        %IF OPP(26) = 0 %START;          ! OPP has no crowns yet
  138           %IF PLAYER = 1 %START;        ! player 1
  139              %CYCLE P = 1, 1, 5
  140                 V2 = V2+BACK WT %IF COMP(P) = BACK1(P)
  141              %REPEAT
  142           %FINISH %ELSE %START;         ! player 2
  143              %CYCLE P = 1, 1, 5
  144                 V2 = V2+BACK WT %IF COMP(P) = BACK2(P)
  145              %REPEAT
  146           %FINISH
  147        %FINISH
  148  
  149        V1 = 0;  V3 = 0;  V4 = 0;  V5 = 0;  V6 = 0;  V7 = 0
  150        %CYCLE P = 1, 1, COMP(25)
  151           CPOS ==COMP(P);  CTYPE ==  COMP(P+12)
  152           ADV1 = 0
  153  
  154           ! add up piece values
  155           V1 = V1+CTYPE
  156  
  157           %CYCLE M = 0, 1, 7
  158              VM = VALID MOVE(M, P, COMP, OPP)
  159              MV = MOVE(M)
  160  
  161              ! centre control
  162              %IF CPOS = CENTSQ(M) %START
  163                 V4 = V4+CENT WT
  164                 V4 = V4+CENT WT+1 %IF CTYPE = CROWN
  165              %FINISH
  166  
  167              %IF VM >= 0 %START
  168  
  169                 ! mobility
  170                 V3 = V3+MOB WT
  171                 V3 = V3+MOB WT %IF VM > 0
  172  
  173                 %IF CTYPE # CROWN %START
  174  
  175                    ! advancement 1
  176                    %IF ADV1 = 0 %AND TRUE=CROWNING(CPOS+MV, PLAYER) %THEN %C
  177+                    V5 = V5+ADV1 WT %AND ADV1 = 1
  178  
  179                    ! advancement 2
  180                    %IF VM = 0 %START;   ! ignore jumps to crown
  181                       CPOS = CPOS+MV
  182                       %CYCLE MM = 0, 2, 6
  183                          %IF TRUE=CROWNING(CPOS+MOVE(MM), PLAYER) %C
  184+                          %AND VALID MOVE(MM, P, COMP, OPP) >= 0 %START
  185                             V6 = V6+ADV2 WT;  %EXIT
  186                          %FINISH
  187                       %REPEAT
  188                       CPOS = CPOS-MV
  189                    %FINISH
  190                 %FINISH
  191  
  192                 ! cramp
  193                 %IF VM = 0 %AND CTYPE = CROWN %AND OPP(25) > 0 %START
  194                    CPOS = CPOS+MV
  195                    %CYCLE PP = 1, 1, OPP(25)
  196                       %CYCLE MM = 1, 2, 7
  197                          %IF VALID MOVE(MM, PP, OPP, COMP) >= 0 %START
  198                             V5 = V5-CRAMP WT;  %EXIT
  199                          %FINISH
  200                       %REPEAT
  201                    %REPEAT
  202                    CPOS = CPOS-MV
  203                 %FINISH
  204              %FINISH
  205           %REPEAT
  206        %REPEAT
  207        %RESULT = V1+V2+V3+V4+V5+V6+V7
  208     %END
  209  
  210     %INTEGERFN VALUE OF POS(%INTEGERARRAYNAME COMP, OPP)
  211     %INTEGER VALUE
  212        %IF PENDING MOVE(COMP, OPP) >= 0 %START
  213           VALUE = VALUE OF SIDE(COMP, OPP)-VALUE OF SIDE(OPP, COMP)-PLY NUMBER
  214        %FINISH %ELSE VALUE = -100000+PLYNUMBER;   ! no mobility!!
  215        %RESULT = VALUE %IF COMP(0) = ME
  216        %RESULT = -VALUE
  217     %END
  218  
  219     %ROUTINE MAKE MOVE(%INTEGER MV, P, %INTEGERNAME T, %C
  220+                                      %INTEGERARRAYNAME COMP, OPP)
  221     %INTEGERNAME CPOS, CTYPE, OPOS, OTYPE, ONUM, ONUMC
  222        CPOS == COMP(P);  CTYPE == COMP(P+12)
  223        CPOS = CPOS+MV
  224        %IF T # 0 %START;                ! a take
  225           OPOS == OPP(T);  OTYPE == OPP(T+12)
  226           ONUM == OPP(25);  ONUMC == OPP(26)
  227           SP = SP+1
  228           PSTACK(SP) = OPOS;            ! save position of taken piece
  229           TSTACK(SP) = OTYPE;           ! save piece type
  230           NSTACK(SP) = T;               ! save piece number
  231           OPOS = OPP(ONUM);             ! remove piece from board
  232           ONUM = ONUM-1;                ! reduce piece count for opp
  233           ONUMC = ONUMC-1 %IF OTYPE = CROWN
  234           OTYPE = OPP(ONUM+13)
  235        %FINISH
  236        %IF CTYPE # CROWN %AND TRUE=CROWNING(CPOS, COMP(0)) %START
  237           CTYPE = CROWN;                ! crown piece
  238           COMP(26) = COMP(26)+1;        ! increase crown count
  239           T = 0;                        ! no more takes
  240        %FINISH
  241     %END
  242  
  243     %INTEGERFN TRY POSSIBLE MOVES(%INTEGER PLY, DEPTH, %C
  244+                                  %INTEGERARRAYNAME COMP, OPP)
  245     %INTEGER M,MM,MMM,MMF,P,T,TT,APT,VALUE,TAKES,OLDPOS,OLDTYPE
  246     %INTEGERNAME MAXPLY, MINPLY
  247  
  248        %INTEGERFN PURSUIT
  249           %RESULT = 1 %IF PLY = 1
  250           %RESULT = \M&1
  251        %END
  252  
  253        NODES = NODES+1
  254        APT = PENDING MOVE(COMP, OPP)
  255        PLY NUMBER = PLY-1 %AND %RESULT = VALUE OF POS(COMP, OPP) %C
  256+        %IF (DEPTH >= SEARCH LIMIT %AND APT <=0) %OR PLY > 12
  257        MINPLY == MIN(PLY);  MINPLY = 100000
  258        MAXPLY == MAX(PLY);  MAXPLY =-100000
  259        %IF APT >= 0 %START;             ! COMP able to move
  260           %IF APT > 0 %START;           ! take priority
  261              P = APT;  APT = 2;  MMM = 1 ; MMF = 7
  262              SEARCH LIMIT = 2 %IF PLY = 1
  263           %FINISH %ELSE %START
  264              P = 1;  APT = 2;  MMM = 0; MMF=6
  265           %FINISH
  266           %CYCLE P = P, 1, COMP(25)
  267              OLDPOS = COMP(P);  OLDTYPE = COMP(P+12)
  268              %CYCLE M = MMM, APT, MMF
  269                 TAKES = 0
  270                 T = VALID MOVE(M, P, COMP, OPP)
  271                 %IF T >= 0 %START;               ! valid move
  272                    MM = M;  TT = T
  273  ANOTHER TAKE:     TAKES = TAKES+1 %IF TT > 0
  274                    MAKE MOVE(MOVE(MM), P, TT, COMP, OPP);! try this move
  275                    %IF TT > 0 %START;             ! another take
  276                       %CYCLE MM = 1, 2, 7
  277                          TT = VALID MOVE(MM, P, COMP, OPP)
  278                          -> ANOTHER TAKE %IF TT > 0
  279                       %REPEAT
  280                    %FINISH
  281                    VALUE = TRY POSSIBLE MOVES(PLY+1, DEPTH+PURSUIT, OPP, COMP)
  282                    COMP(P) = OLDPOS;  COMP(P+12) = OLDTYPE
  283                    OPP(25) = OPP(25)+TAKES
  284                    %WHILE TAKES > 0 %CYCLE
  285                       TT = NSTACK(SP)
  286                       OPP(TT) = PSTACK(SP)
  287                       OPP(TT+12) = TSTACK(SP)
  288                       TAKES = TAKES-1
  289                       SP = SP-1
  290                    %REPEAT
  291                    %IF COMP(0) = ME %START
  292                       %IF VALUE > MAXPLY %START
  293                          MAXPLY = VALUE
  294                          %IF PLY = 1 %START
  295                             BEST MOVE = M
  296                             BEST TAKE = T
  297                             BEST PIECE = P
  298                          %FINISH
  299                       %FINISH
  300                       %RESULT = MAXPLY %IF PLY # 1 %AND MAXPLY >= MIN(PLY-1)
  301                    %FINISH %ELSE %START
  302                       MINPLY = VALUE %IF VALUE < MINPLY
  303                       %RESULT = MINPLY %IF MINPLY <= MAX(PLY-1)
  304                    %FINISH
  305                 %FINISH
  306              %REPEAT
  307           %REPEAT
  308        %FINISH
  309        %RESULT = MAXPLY %IF COMP(0) = ME
  310        %RESULT = MINPLY
  311     %END
  312  
  313     %ROUTINE SAY PLEASE
  314        PRINTSTRING("Please re-type your move
  315+ ")
  316     %END
  317  
  318     %ROUTINE PRINT BOARD
  319     %INTEGER I, J, POS
  320        %CYCLE I = 0, 1, 7
  321           %CYCLE J = 0, 2, 6
  322              BOARD(10*I+J+I&1) = '#'
  323           %REPEAT
  324        %REPEAT
  325        %CYCLE I = 1, 1, 12
  326           %IF I <= COMP(25) %START
  327              POS = COMP(I)
  328             %IF COMP(I+12) = CROWN %THEN BOARD(POS) = 'X' %C
  329+              %ELSE BOARD(POS) = 'x'
  330           %FINISH
  331           %IF I <= OPP(25) %START
  332              POS = OPP(I)
  333              %IF OPP(I+12) = CROWN %THEN BOARD(POS) = 'O' %C
  334+              %ELSE BOARD(POS) = 'o'
  335           %FINISH
  336        %REPEAT
  337        PRINTSTRING("
  338+   A B C D E F G H")
  339        %CYCLE I = 70, -10, 0
  340           NEWLINE
  341           PRINTSYMBOL(I//10+'1')
  342           %CYCLE J = 0, 1, 7
  343              SPACE
  344              PRINTSYMBOL(BOARD(J+I))
  345           %REPEAT
  346           SPACE
  347           PRINTSYMBOL(I//10+'1')
  348        %REPEAT
  349        PRINTSTRING("
  350+   A B C D E F G H
  351+ ")
  352     %END
  353  
  354     %ROUTINE TROUT(%INTEGER OLDPOS, NEWPOS, %INTEGERNAME MODE)
  355     %INTEGER OLDX, OLDY, NEWX, NEWY
  356        OLDY = OLDPOS//10;  OLDX = OLDPOS-10*OLDY
  357        NEWY = NEWPOS//10;  NEWX = NEWPOS-10*NEWY
  358        %IF MODE = 0 %THEN PRINTSTRING("DRAFT4's move is ") %AND MODE = 1  %C
  359+                    %ELSE PRINTSTRING(" , ")
  360        PRINTSYMBOL(OLDX+'A')
  361        PRINTSYMBOL(OLDY+'1')
  362        PRINTSYMBOL('-')
  363        PRINTSYMBOL(NEWX+'A')
  364        PRINTSYMBOL(NEWY+'1')
  365     %END
  366  
  367     %INTEGERFN POSITION OF(%INTEGER S1, S2)
  368        %RESULT = (S1-'A')+10*(S2-'1')
  369     %END
  370  
  371     %ROUTINE SKIP SPACES AND NLS
  372        SKIP SYMBOL %WHILE NEXT SYMBOL=' ' %OR NEXT SYMBOL=NL
  373     %END
  374  
  375     COMPNUM == COMP(25);  OPPNUM == OPP(25)
  376     !CPULIMIT ("12"); ! FOR EMAS - JGH MOD, AS CS1 WERE RUNNING OUT
  377     PRINTSTRING("The Draughts programme  DRAFT4.4
  378+ 
  379+ ")
  380     PRINT STRING("Do you want some help?"); NEWLINE
  381     PROMPT(":")
  382     READ SYMBOL(REPLY(1)); SKIP SYMBOL %WHILE NEXT SYMBOL#NL; SKIP SYMBOL
  383     REPLY(1) = REPLY(1)-32 %IF REPLY(1)>='a'
  384     %IF REPLY(1)='Y' %START
  385        PRINTSTRING("
  386+ 
  387+    Moves are typed in in the following form:  (e.g.)
  388+ 
  389+       C3-D4      move the piece on square C3 to square D4.")
  390  PRINTSTRING("
  391+       C3-E5      move C3 to E5, taking the piece on D4
  392+ "); PRINTSTRING("      C3-E5,
  393+       E5-C7      an example of a multiple jump
  394+ 
  395+                                                     e.t.c.")
  396     %FINISH
  397  RESTART:
  398     EXPECTED MOVE = 0
  399     ! setting up the pieces
  400     %CYCLE P = -1, 1, 26
  401        COMP(P) = PLAYER1(P)
  402        OPP(P) = PLAYER2(P)
  403     %REPEAT
  404     NEWLINE
  405     PRINT STRING("Do you want to start?")
  406     NEWLINE
  407     PROMPT(":")
  408     READ SYMBOL(REPLY(1))
  409     REPLY(1) = REPLY(1)-32 %IF REPLY(1)>='a'
  410     SKIP SYMBOL %WHILE NEXT SYMBOL#NL; SKIP SYMBOL
  411     %IF REPLY(1)='R' %START
  412        ! Read board position
  413        %CYCLE P = -1,1,26
  414           COMP(P) = 0
  415           OPP(P) = 0
  416        %REPEAT
  417        PRINT STRING("Where are your pieces?"); NEWLINE
  418        PROMPT(":")
  419        %CYCLE P = 1,1,12
  420           SKIP SPACES AND NLS
  421           READ SYMBOL(A); %IF A='.' %THEN %EXIT
  422           READ SYMBOL(B); READ SYMBOL(C)
  423           A = A-32 %IF A>='a'
  424           B = B-32 %IF A>='a'
  425           POS = POSITION OF(A,B)
  426           OPP(P) = POS
  427           %IF C=' ' %THEN OPP(P+12) = 1000 %ELSE OPP(P+12) = CROWN
  428        %REPEAT
  429        OPP(0) = 2
  430        OPP(25) = P;        ! no of pieces.
  431        PRINT STRING("Where are my pieces?"); NEWLINE
  432        %CYCLE P = 1,1,12
  433           SKIP SPACES AND NLS
  434           READ SYMBOL(A); %IF A='.' %THEN %EXIT
  435           READ SYMBOL(B); READ SYMBOL(C)
  436           A = A-32 %IF A>='a'
  437           B = B-32 %IF B>='a'
  438           POS = POSITION OF(A,B)
  439           COMP(P) = POS
  440           %IF C=' ' %THEN COMP(P+12) = 1000 %ELSE COMP(P+12) = CROWN
  441        %REPEAT
  442        COMP(0)  = ME
  443        COMP(25) = P;        ! NO OF PIECES
  444        SKIP SYMBOL;       ! NL
  445        PROMPT("Your move?")
  446        READ SYMBOL(A)
  447        SKIP SYMBOL %WHILE NEXT SYMBOL#NL; SKIP SYMBOL
  448        A = A-32 %IF A>='a'
  449        %IF A='Y' %THEN -> READ MOVE %ELSE -> COMP MOVE
  450     %FINISH
  451     %IF REPLY(1) = 'N' %START
  452        PRINT STRING("Think of a number please"); NEWLINE
  453        READ SYMBOL(I); SKIP SYMBOL
  454        I = (I-'0')&3
  455        COMP(-1) = 'B';  OPP(-1) = 'W'
  456        PRINTSTRING("DRAFT4's opening move is ")
  457        %IF I = 1 %THEN PRINTSTRING("D6-C5") %AND COMP(11) = 42
  458        %IF I = 2 %THEN PRINTSTRING("D6-E5") %AND COMP(11) = 44
  459        %IF I = 3 %THEN PRINTSTRING("F6-E5") %AND COMP(10) = 44
  460        NEWLINE
  461     %FINISH
  462  READ MOVE:
  463     PRINT BOARD
  464     PROMPT("Your move:")
  465     SKIP SYMBOL %WHILE NEXT SYMBOL <= ' '
  466     %CYCLE I = 1, 1, 8
  467        READ SYMBOL(REPLY(I))
  468        REPLY(I) = REPLY(I)-32 %IF REPLY(I)>='a'
  469        %EXIT %IF REPLY(I) = NL
  470     %REPEAT
  471     REPLY(I) = ' ' %AND I = I+1 %UNTIL I = 9
  472     %IF REPLY(1) = 'M' %THEN MON = 'M' %AND -> READ MOVE
  473     %IF REPLY(1) = 'Q' %THEN MON = 'Q' %AND -> READ MOVE
  474  TRANS:
  475     %IF REPLY(1) = 'I' %THEN -> STOP
  476     %IF REPLY(6) = ','%THEN MORE = 'M' %ELSE MORE = ' '
  477     OLDPOS = POSITION OF(REPLY(1), REPLY(2))
  478     NEWPOS = POSITION OF(REPLY(4), REPLY(5))
  479     %IF VALID POS(OLDPOS) = -1 %START
  480        PRINTSTRING("The square ")
  481        PRINT SYMBOL(REPLY(1));  PRINT SYMBOL(REPLY(2))
  482        PRINTSTRING(" does not exist!
  483+ ")
  484        SAY PLEASE
  485        -> READ MOVE
  486     %FINISH
  487     M = VALID POS(NEWPOS)
  488     %IF M = -1 %START
  489        PRINTSTRING("You cannot move to square ")
  490        PRINTSYMBOL(REPLY(4));  PRINTSYMBOL(REPLY(5))
  491        PRINTSTRING(";  it does not exist!
  492+ ")
  493        SAY PLEASE
  494        -> READ MOVE
  495     %FINISH
  496     %IF M = 1 %START
  497        PRINTSTRING("You cannot move to square ")
  498        PRINT SYMBOL(REPLY(4));  PRINT SYMBOL(REPLY(5))
  499        PRINTSTRING(";  it is already occupied!
  500+ ")
  501        SAY PLEASE
  502        -> READ MOVE
  503     %FINISH
  504     %CYCLE P = 1, 1, OPP(25)
  505        %IF OLDPOS = OPP(P) %THENEXIT
  506     %REPEAT
  507     %UNLESS OLDPOS = OPP(P) %START
  508        PRINTSTRING("You do not have a piece on square ")
  509        PRINT SYMBOL(REPLY(1));  PRINT SYMBOL(REPLY(2))
  510        NEWLINE
  511        SAY PLEASE
  512        -> READ MOVE
  513     %FINISH
  514     PIECE = P
  515     DIF = NEWPOS-OLDPOS
  516     MODIF = MOD(DIF)
  517     %IF MODIF < 12 %AND EXPECTED MOVE > 0 %START
  518        PRINTSTRING("You MUST take the piece that I am offering you
  519+ ")
  520        SAY PLEASE
  521        -> READ MOVE
  522     %FINISH
  523     %IF MODIF < 12 %AND MORE = 'M' %START
  524        PRINTSTRING("That's not part of a multiple jump move
  525+ ")
  526        SAY PLEASE
  527        -> READ MOVE
  528     %FINISH
  529     %IF DIF < 0 %AND OPP(PIECE+12) # CROWN %START
  530        PRINTSTRING("You cannot move that piece backwards!
  531+ ")
  532        SAY PLEASE
  533        -> READ MOVE
  534     %FINISH
  535     %UNLESS MODIF = 11 %OR MODIF = 9 %OR MODIF = 22 %OR MODIF = 18 %START
  536        PRINTSTRING("That move does not exist in my rule book!
  537+ ")
  538        SAY PLEASE
  539        -> READ MOVE
  540     %FINISH
  541     %IF MODIF > 11 %START
  542        JUMP = DIF//2
  543        COMPOS = OLDPOS+JUMP
  544        %CYCLE I = 1, 1, COMP(25)
  545           %EXIT %IF COMPOS = COMP(I)
  546        %REPEAT
  547        %UNLESS COMPOS = COMP(I) %START
  548           PRINTSTRING("You cannot do that.  You are not jumping one of my pieces
  549+ ")
  550           SAY PLEASE
  551           -> READ MOVE
  552        %FINISH
  553        JMAN = I
  554     %FINISH %ELSE JMAN = 0
  555     MAKE MOVE(DIF, PIECE, JMAN, OPP, COMP)
  556     %IF MORE = 'M' %START
  557        LASTPOS = NEWPOS
  558  READ AGAIN:
  559        PROMPT("and:")
  560        %CYCLE I = 1, 1, 8
  561           READ SYMBOL(REPLY(I))
  562           REPLY(I) = REPLY(I)-32 %IF REPLY(I)>='a'
  563           %EXIT %IF REPLY(I) = NL
  564        %REPEAT
  565        %IF REPLY(1) = '.'%THEN -> COMP MOVE
  566        REPLY(I) = ' ' %AND I = I+1 %UNTIL I = 9
  567        OLDPOS = POSITION OF(REPLY(1), REPLY(2))
  568        NEWPOS = POSITION OF(REPLY(4), REPLY(5))
  569        DIF = NEWPOS-OLDPOS
  570        DIF = MOD(DIF)
  571        %IF DIF > 11 %AND OLDPOS = LASTPOS %THEN -> TRANS
  572        PRINTSTRING("That's not part of a multiple jump
  573+ Please re-type that part
  574+ ")
  575        -> READ AGAIN
  576     %FINISH
  577  COMP MOVE: ! COMPUTER MAKES MOVE.
  578     %IF COMPNUM = 0 %START
  579        PRINTSTRING(" I have no pieces left so I suppose you have won
  580+ ")
  581        -> STOP
  582     %FINISH
  583     %IF PENDING MOVE(COMP, OPP) = -1 %START
  584        PRINTSTRING("I cannot move any of my pieces so you win
  585+ ")
  586         -> STOP
  587     %FINISH
  588     ! If in end game then increase search.
  589     I = COMPNUM+OPPNUM
  590     %IF I <= 6 %THEN SEARCH LIMIT = 4
  591     ! FIND BEST MOVE.
  592     NODES = 0;  SP = 0
  593     VALUEB = TRY POSSIBLE MOVES(1, 1, COMP, OPP)
  594     %IF VALUEB <= -99990 %START
  595         PRINTSTRING("I resign
  596+ ")
  597         -> STOP
  598     %FINISH
  599     I = 0
  600  ANOTHER TAKE:
  601     TROUT(COMP(BEST PIECE), COMP(BEST PIECE)+MOVE(BEST MOVE), I)
  602     MAKE MOVE(MOVE(BEST MOVE), BEST PIECE, BEST TAKE, COMP, OPP)
  603     %IF BEST TAKE > 0 %START
  604        %CYCLE BEST MOVE = 1, 2, 7
  605           BEST TAKE = VALID MOVE(BEST MOVE, BEST PIECE, COMP, OPP)
  606           -> ANOTHER TAKE %IF BEST TAKE>0
  607        %REPEAT
  608     %FINISH
  609     NEWLINE
  610     %IF MON = 'M' %START
  611        PRINTSTRING("Nodes considered =");  WRITE(NODES, 4)
  612        PRINTSTRING("
  613+ Value of board =");  WRITE(VALUEB, 4)
  614        NEWLINE
  615     %FINISH
  616     %IF OPPNUM = 0 %START
  617         PRINTSTRING("You have no pieces left so I win
  618+ ")
  619        -> STOP
  620     %FINISH
  621     EXPECTED MOVE = PENDING MOVE(OPP, COMP)
  622     %IF EXPECTED MOVE = -1 %START
  623        PRINTSTRING("You cannot move any of your pieces so I win
  624+ ")
  625        -> STOP
  626     %FINISH
  627     %IF VALUEB >= 99990  %AND AWIN = 0 %START
  628        PRINTSTRING("He-He!  I am going to win!!
  629+ ")
  630        AWIN = 1
  631     %FINISH
  632     -> READ MOVE
  633  STOP:
  634     PRINTSTRING("
  635+ The final board position is -
  636+ ")
  637     PRINT BOARD
  638  %END
?RESTART unused
?THREE unused
?TWO unused
?ONE unused
?S unused
  639  
  640  %begin
  641    select input(0)
  642    select output(0)
  643    DRAUGHTS("")
  644  %end
  645  
  646  %ENDOFFILE

  572 Statements compiled
