         Edinburgh IMP77 Compiler - Version 8.4

    1  %EXTERNALROUTINE BACKGAMMON (%STRING(255) ST)
    2   %OWNINTEGER BBOFF,WBOFF,DICE1,DICE2,BARFL,BRDVAL,BSTVAL,COMPVAL
    3   %OWNINTEGER M1,M2,M3,M4,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,I,J,K,RUNNING
    4   %OWNINTEGER NOMOV,BARPT1,BARPT2,PT1,PT2,L,M,N,TEMP,BSTMOV1,BSTMOV2
    5   %OWNINTEGER BSTPT1,BSTPT2,W1,W2,W3,W4,W5,W6,W7,W8,W9,W10
    6   %OWNINTEGER SECOND,BV1,BV2,BV3,BV4,BV5,BV6,BV7,BV8,BV9,BV10
    7   %CONSTINTEGERARRAY ODDS(1:12)=35,38,44,47,47,53,18,21,15,12,6,9
    8   %RECORDFORMAT F(%INTEGER WS,BS)
    9   %OWNRECORD(f)%ARRAY BOARD(0:25){(F)}
   10   %OWNINTEGER G,H,PT3,PT4,DICE3,DICE4,BSTPT3,BSTPT4,BARPT3,BARPT4
   11   %INTEGERFN HOMEB
   12   %INTEGER NO,I
   13   NO=BBOFF
   14   %CYCLE I=1,1,6
   15       NO=NO+BOARD(I)_BS
   16   %REPEAT
   17   %IF NO=15 %THENRESULT = 1 %ELSERESULT = 0
   18   %END
   19  
   20   %ROUTINE DOBLACK
   21   %INTEGER PT,NO,M,D1,D2,D3,D4,TOT
   22     PROMPT ("Point:")
   23   %CYCLE
   24      READ(D1); READ(D2)
   25      %IF D1>6 %OR D2>6 %THEN PRINTSTRING("No way") %AND NEWLINE %ELSEEXIT
   26   %REPEAT
   27   %IF D1=D2 %THEN D3=D1 %AND D4=D2 %ELSE D3=0 %AND D4=0
   28   PRINTSTRING("Your throw was")
   29   WRITE(D1,2); WRITE(D2,2)
   30   NEWLINE
   31   %IF BOARD(25)_BS>0 %THENSTART
   32      %IF BOARD(25-D1)_WS>1 %AND BOARD(25-D2)_WS>1 %C
   33+        %THEN PRINTSTRING("You cannot move") %AND NEWLINE %ANDRETURN
   34      %IF BOARD(25)_BS#1 %THENSTART
   35         %IF D1#D2 %THENSTART
   36            %IF BOARD(25-D1)_WS>1 %THENSTART
   37               BOARD(25-D2)_BS=BOARD(25-D2)_BS+1
   38               BOARD(25)_BS=BOARD(25)_BS-1
   39               BOARD(25-D2)_WS=0
   40               BOARD(0)_WS=BOARD(0)_WS+1
   41               PRINTSTRING("I have made your move")
   42               NEWLINE
   43               %RETURN
   44            %FINISH
   45            %IF BOARD(25-D2)_WS>1 %THENSTART
   46               BOARD(25-D1)_BS=BOARD(25-D1)_BS+1
   47               BOARD(25)_BS=BOARD(25)_BS-1
   48               BOARD(25-D1)_WS=0
   49               BOARD(0)_WS=BOARD(0)_WS+1
   50               PRINTSTRING("I have made your move")
   51               NEWLINE
   52               %RETURN
   53            %FINISH
   54         %FINISH
   55      %FINISH
   56   %FINISH
   57   PRINTSTRING("Make your move"); NEWLINE
   58   %CYCLE M=1,1,4
   59  AGN: TOT=D1+D2+D3+D4
   60   %IF TOT=0 %THENRETURN
   61   READ(PT); %IF PT=100 %THENRETURN; READ(NO)
   62   %IF BOARD(PT)_BS=0 %THEN PRINTSTRING("No blacks on point") %C
   63+     %AND NEWLINE %AND ->AGN
   64   %IF BOARD(25)_BS#0 %AND PT#25 %THEN %C
   65+     PRINTSTRING("You have pieces on the bar") %AND NEWLINE %AND ->AGN
   66   %IF PT-NO<=0 %THENSTART
   67      %IF HOMEB=0 %THEN PRINTSTRING("Not all home") %AND %C
   68+        NEWLINE %AND ->AGN; ->LEGMOV
   69   %FINISH
   70   %IF BOARD(PT-NO)_WS>1 %THEN PRINTSTRING("White has point") %C
   71+     %AND NEWLINE %AND ->AGN
   72  LEGMOV: %IF NO=D1 %THEN D1=0 %ELSESTART
   73      %IF NO=D2 %THEN D2=0 %ELSESTART
   74         %IF NO=D3 %THEN D3=0 %ELSESTART
   75            %IF NO=D4 %THEN D4=0 %ELSESTART
   76               PRINTSTRING("Illegal move"); NEWLINE; ->AGN
   77            %FINISH
   78         %FINISH
   79      %FINISH
   80   %FINISH
   81   %IF PT-NO <=0 %THEN ->BBEARO
   82   BOARD(PT)_BS=BOARD(PT)_BS-1
   83   BOARD(PT-NO)_BS=BOARD(PT-NO)_BS+1
   84   %IF BOARD(PT-NO)_WS=1 %THEN BOARD(PT-NO)_WS=0 %C
   85+     %AND BOARD(0)_WS=BOARD(0)_WS+1
   86   ->SKP
   87  BBEARO: BBOFF=BBOFF+1
   88   BOARD(PT)_BS=BOARD(PT)_BS-1
   89   %IF BBOFF=15 %THENRETURN
   90  SKP: %REPEAT
   91   %END
   92  
   93   %ROUTINE INITIALIZE
   94   WBOFF=0
   95   BBOFF=0
   96   BOARD(1)_WS=2
   97   BOARD(6)_BS=5
   98   BOARD(8)_BS=3
   99   BOARD(12)_WS=5
  100   BOARD(13)_BS=5
  101   BOARD(17)_WS=3
  102   BOARD(19)_WS=5
  103   BOARD(24)_BS=2
  104   %END
  105  
  106   %ROUTINE PRINTSTATE
  107   %INTEGER I,J,K,M
  108   NEWLINES(2)
  109   PRINTSTRING(" 12  11  10   9   8   7      6   5   4   3   2   1")
  110   NEWLINE
  111   PRINTSTRING("___________________________________________________")
  112   %CYCLE I=0,1,6
  113      NEWLINE
  114      SPACES(2)
  115      %CYCLE J=12,-1,1
  116         %IF BOARD(J)_WS>I %THEN PRINTSYMBOL('W') %AND ->RPT
  117         %IF BOARD(J)_BS>I %THEN PRINTSYMBOL('B') %AND ->RPT
  118         SPACE
  119  RPT:   %IF J=7 %THEN PRINTSTRING("  **  ") %ELSE SPACES(3)
  120      %REPEAT
  121   %REPEAT
  122   %CYCLE K=6,-1,0
  123      NEWLINE
  124      SPACES(2)
  125      %CYCLE M=13,1,24
  126         %IF BOARD(M)_WS>K %THEN PRINTSYMBOL('W') %AND ->RPT2
  127         %IF BOARD(M)_BS>K %THEN PRINTSYMBOL('B') %AND ->RPT2
  128         SPACE
  129  RPT2:  %IF M=18 %THEN PRINTSTRING("  **  ") %ELSE SPACES(3)
  130      %REPEAT
  131   %REPEAT
  132   NEWLINE
  133   PRINTSTRING("____________________________________________________")
  134   NEWLINE
  135   PRINTSTRING(" 13  14  15  16  17  18      19  20  21  22  23  24")
  136   NEWLINE
  137   %IF BOARD(0)_WS>0 %THENSTART
  138      NEWLINE
  139      PRINTSTRING("There are")
  140      WRITE(BOARD(0)_WS,2)
  141      PRINTSTRING(" whites on the bar")
  142   %FINISH
  143   %IF BOARD(25)_BS>0 %THENSTART
  144      NEWLINE
  145      PRINTSTRING("there are")
  146      WRITE(BOARD(25)_BS,2)
  147      PRINTSTRING(" blacks on the bar")
  148   %FINISH
  149   %IF WBOFF>0 %THENSTART
  150      NEWLINE
  151      PRINTSTRING("white has born off")
  152      WRITE(WBOFF,3)
  153   %FINISH
  154   %IF BBOFF>0 %THENSTART
  155      NEWLINE
  156      PRINTSTRING("black has born off")
  157      WRITE(BBOFF,3)
  158   %FINISH
  159   NEWLINE
  160   %END
  161  
  162   %INTEGERFN BBAR
  163   %RESULT = BOARD(25)_BS
  164   %END
  165  
  166   %INTEGERFN WBAR
  167   %RESULT = BOARD(0)_WS
  168   %END
  169  
  170   %INTEGERFN BSIN
  171   %INTEGER I,J; J=0
  172   %CYCLE I=1,1,25
  173      %IF BOARD(I)_BS=1 %THEN J=J+1
  174   %REPEAT
  175   %RESULT = J
  176   %END
  177  
  178   %INTEGERFN WSIN
  179   %INTEGER I,J; J=0
  180   %CYCLE I=0,1,24
  181      %IF BOARD(I)_WS=1 %THEN J=J+1
  182   %REPEAT
  183   %RESULT = J
  184   %END
  185  
  186   %INTEGERFN BSINCL
  187   %INTEGER I,J,K,SUM; SUM=0
  188   %CYCLE I=25,-1,1
  189      %IF BOARD(I)_BS=1 %THENSTART
  190      %IF I-12<0 %THEN J=0 %ELSE J=I-12
  191      %CYCLE K=I-1,-1,J
  192         %IF BOARD(K)_WS>0 %THEN SUM=SUM+ODDS(I-K)
  193      %REPEAT
  194      %FINISH
  195   %REPEAT
  196   %RESULT = SUM
  197   %END
  198  
  199   %INTEGERFN WSINCL
  200   %INTEGER I,J,K,SUM; SUM=0
  201   %CYCLE I=0,1,24
  202      %IF BOARD(I)_WS=1 %THENSTART
  203      %IF I+12>25 %THEN J=25 %ELSE J=I+12
  204      %CYCLE K=I+1,1,J
  205         %IF BOARD(K)_BS>0 %THEN SUM=SUM+ODDS(K-I)
  206      %REPEAT
  207      %FINISH
  208   %REPEAT
  209   %RESULT = SUM
  210   %END
  211  
  212   %INTEGERFN WPTSHOME
  213   %INTEGER I,J; J=0
  214   %CYCLE I=19,1,24
  215      %IF BOARD(I)_WS>1 %THEN J=J+1
  216   %REPEAT
  217   %RESULT = J
  218   %END
  219  
  220   %INTEGERFN BPTSHOME
  221   %INTEGER I,J; J=0
  222   %CYCLE I=1,1,6
  223      %IF BOARD(I)_BS>1 %THEN J=J+1
  224   %REPEAT
  225   %RESULT = J
  226   %END
  227  
  228   %INTEGERFN WPTS
  229   %INTEGER I,J; J=0
  230   %CYCLE I=1,1,24
  231      %IF BOARD(I)_WS>1 %THEN J=J+1
  232   %REPEAT
  233   %RESULT = J
  234   %END
  235  
  236   %INTEGERFN BPTS
  237   %INTEGER I,J;J=0
  238   %CYCLE I=1,1,24
  239      %IF BOARD(K)_BS>1 %THEN J=J+1
  240   %REPEAT 
  241   %RESULT = J
  242   %END
  243  
  244   %INTEGERFN WPTSSUCC
  245   %INTEGER I,J,K; K=0
  246   %CYCLE J=1,1,22
  247      %IF BOARD(J)_BS>0 %THENSTART
  248         %CYCLE I=J+1,1,23
  249            %IF BOARD(I)_WS>1 %THENSTART
  250               %IF BOARD(I+1)_WS>1 %THEN K=K+1
  251            %FINISH
  252         %REPEAT
  253         %EXIT
  254      %FINISH
  255   %REPEAT
  256   %RESULT = K
  257   %END
  258  
  259   %INTEGERFN BPTSSUCC
  260   %INTEGER I,J,K; K=0   
  261   %CYCLE J=24,-1,3
  262      %IF BOARD(J)_WS>0 %THENSTART
  263         %CYCLE I=J-1,-1,2
  264            %IF BOARD(I)_BS>1 %THENSTART
  265               %IF BOARD(I-1)_BS>1 %THEN K=K+1
  266            %FINISH
  267         %REPEAT
  268         %EXIT
  269      %FINISH
  270   %REPEAT
  271   %RESULT = K
  272   %END
  273  
  274   %INTEGERFN BFST3
  275   %INTEGER I,J; J=0
  276   %CYCLE I=22,1,25
  277      J=J+BOARD(I)_BS
  278   %REPEAT
  279   %RESULT = J
  280   %END
  281  
  282   %INTEGERFN WFST3
  283   %INTEGER I,J; J=0
  284   %CYCLE I=0,1,3
  285      J=J+BOARD(I)_WS
  286   %REPEAT
  287   %RESULT = J
  288   %END
  289  
  290   %INTEGERFN BFST6
  291   %INTEGER I,J; J=0
  292   %CYCLE I=19,1,25
  293      J=J+BOARD(I)_BS
  294   %REPEAT
  295   %RESULT = J
  296   %END
  297  
  298   %INTEGERFN WFST6
  299   %INTEGER I,J; J=0
  300   %CYCLE I=0,1,6
  301      J=J+BOARD(I)_WS
  302   %REPEAT
  303   %RESULT = J
  304   %END
  305  
  306   %INTEGERFN BFST12
  307   %INTEGER I,J
  308   J=BFST6
  309   %CYCLE I=13,1,18
  310      J=J+BOARD(I)_BS
  311   %REPEAT
  312   %RESULT = J
  313   %END
  314  
  315   %INTEGERFN WFST12
  316   %INTEGER I,J
  317   J=WFST6
  318   %CYCLE I=7,1,12
  319      J=BOARD(I)_WS+J
  320   %REPEAT
  321   %RESULT = J
  322   %END
  323  
  324   %INTEGERFN WHOME
  325   %INTEGER I,J; J=0
  326   %CYCLE I=19,1,24
  327      J=J+BOARD(I)_WS
  328   %REPEAT
  329   %RESULT = J
  330   %END
  331  
  332   %INTEGERFN BHOME
  333   %INTEGER I,J; J=0
  334   %CYCLE I=1,1,6
  335      J=J+BOARD(I)_BS
  336   %REPEAT
  337   %RESULT = J
  338   %END
  339  
  340   %INTEGERFN WTOGO
  341   %INTEGER I,J,K,SUM; SUM=0
  342   %CYCLE I=0,1,18
  343      J=BOARD(I)_WS
  344      %IF J>0 %THENSTART
  345         %CYCLE K=1,1,J
  346            SUM=SUM+19-I
  347         %REPEAT
  348      %FINISH
  349   %REPEAT
  350   %RESULT = SUM
  351   %END
  352  
  353   %INTEGERFN BTOGO
  354   %INTEGER I,J,K,SUM; SUM=0
  355   %CYCLE I=7,1,25
  356      J=BOARD(I)_BS
  357      %IF J>0 %THENSTART
  358         %CYCLE K=1,1,J
  359            SUM=SUM+I-6
  360         %REPEAT
  361      %FINISH
  362   %REPEAT
  363   %RESULT = SUM
  364   %END
  365  
  366   %ROUTINE GBRDVAL
  367   V1=W1*(BBAR-WBAR)
  368   V2=W2*(BSIN-WSIN)
  369   V3=W3*(BSINCL-WSINCL)//10
  370   V4=W4*(WPTSHOME-BPTSHOME)
  371   V5=W5*(WPTS-BPTS)
  372   V6=W6*(WPTSSUCC-BPTSSUCC)
  373   V7=W7*(BFST6-WFST6)
  374   V8=W8*(BTOGO//6-WTOGO//6)
  375   V9=W9*(BFST3-WFST3)
  376   V10=W10*(WHOME-BHOME)
  377   BRDVAL=V1+V2+V3+V4+V5+V6+V7+V8+V9+V10
  378   %END
  379  
  380   %ROUTINE GBRD
  381   V1=W1*(BBAR)
  382   V2=W2*(-WSIN)
  383   V3=W3*(-WSINCL)//10
  384   V4=W4*(WPTSHOME)
  385   V5=W5*(WPTS)
  386   V6=W6*(WPTSSUCC)
  387   V7=W7*(-WFST6)
  388   V8=W8*(-WTOGO)//6
  389   V9=W9*(-WFST3)
  390   V10=W10*(WHOME)
  391   BRDVAL=V1+V2+V3+V4+V5+V6+V7+V8+V9+V10
  392   %IF BRDVAL>BSTVAL %THENSTART
  393      BV1=V1; BV2=V2; BV3=V3; BV4=V4; BV5=V5; BV6=V6; BV7=V7; BV8=V8
  394      BV9=V9; BV10=V10; BSTVAL=BRDVAL; BSTMOV1=DICE1; BSTPT1=PT1
  395      BSTMOV2=DICE2; BSTPT2=PT2; BSTPT3=PT3; BSTPT4=PT4
  396   %FINISH
  397   %END
  398  
  399  
  400   %ROUTINE MTSTMOV (%INTEGER P,D,%INTEGERNAME BP)
  401   BOARD(P)_WS=BOARD(P)_WS-1
  402   BOARD(P+D)_WS=BOARD(P+D)_WS+1
  403   %IF BOARD(P+D)_BS=1 %THEN BOARD(P+D)_BS=0 %C
  404+     %AND BOARD(25)_BS=BOARD(25)_BS+1 %AND BP=1
  405   %END
  406  
  407   %ROUTINE CLTSTMOV (%INTEGER P,D,%INTEGERNAME BP)
  408   BOARD(P)_WS=BOARD(P)_WS+1
  409   BOARD(P+D)_WS=BOARD(P+D)_WS-1
  410   %IF BP=1 %THEN BOARD(P+D)_BS=1 %AND BOARD(25)_BS=BOARD(25)_BS-1 %C
  411+     %AND BP=0
  412   %END
  413  
  414   %ROUTINE MMOVE (%INTEGER P,D)
  415   BOARD(P)_WS=BOARD(P)_WS-1
  416   BOARD(P+D)_WS=BOARD(P+D)_WS+1
  417   BOARD(25)_BS=BOARD(25)_BS+BOARD(P+D)_BS
  418   BOARD(P+D)_BS=0
  419   %END
  420  
  421   %ROUTINE GOOD (%INTEGERNAME S,WT)
  422   %IF S=0 %THENRETURN
  423   %IF S<0 %THEN WT=WT-1 %ELSE WT=WT+1
  424   %END
  425  
  426   %ROUTINE BAD (%INTEGERNAME S,WT)
  427   %IF S=0 %THENRETURN
  428   %IF S>0 %THEN WT=WT-1 %ELSE WT=WT+1
  429   %END
  430  
  431   %ROUTINE LOADWTS
  432     W1 = 19
  433     W2 = 117
  434     W3 = 102
  435     W4 = 15
  436     W5 = 15
  437     W6 = 12
  438     W7 = 64
  439     W8 = 43
  440     W9 = 62
  441     W10 = 15
  442   %END
  443  
  444   %ROUTINE DUMPWTS
  445   SELECTOUTPUT(2)
  446   NEWLINES(3); WRITE(W1,1); NEWLINE; WRITE(W2,1)
  447   NEWLINE; WRITE(W3,1); NEWLINE; WRITE(W4,1)
  448   NEWLINE; WRITE(W5,1); NEWLINE; WRITE(W6,1)
  449   NEWLINE; WRITE(W7,1); NEWLINE; WRITE(W8,1)
  450   NEWLINE; WRITE(W9,1); NEWLINE; WRITE(W10,1)
  451   %END
  452  
  453   %INTEGERFN WBEARO
  454   %INTEGER I,J; J=WBOFF
  455   %CYCLE I=19,1,24
  456      J=J+BOARD(I)_WS
  457   %REPEAT
  458   %RESULT = J
  459   %END
  460  
  461   %ROUTINE DOBEST(%INTEGER D)
  462   %IF D#0 %THENSTART
  463      %IF BOARD(25-D)_WS>0 %THENSTART
  464         BOARD(25-D)_WS=BOARD(25-D)_WS-1
  465         WBOFF=WBOFF+1
  466      %FINISHELSESTART
  467         %IF BOARD(25-D+1)_WS>0 %THENSTART
  468            BOARD(25-D+1)_WS=BOARD(25-D+1)_WS-1
  469            WBOFF=WBOFF+1
  470         %FINISHELSESTART
  471            %CYCLE M=19,1,25-D
?Non-local
  472               %IF WBOFF<8 %THENSTART
  473                  %IF BOARD(M)_WS>2 %THEN MMOVE(M,D) %ANDRETURN
  474               %FINISHELSESTART
  475                  %IF BOARD(M)_WS>1 %THEN MMOVE(M,D) %ANDRETURN
  476               %FINISH
  477            %REPEAT
  478             %CYCLE M=19,1,24
?Non-local
  479                %IF DICE2+M<25 %THENSTART
  480                   %IF BOARD(M)_WS>0 %THEN MMOVE(M,DICE2) %ANDRETURN
  481                %FINISHELSESTART
  482                   %IF BOARD(M)_WS>0 %THENSTART
  483                      BOARD(M)_WS=BOARD(M)_WS-1
  484                      WBOFF=WBOFF+1; %RETURN
  485                   %FINISH
  486                %FINISH
  487             %REPEAT
  488         %FINISH
  489      %FINISH
  490   %FINISH
  491   %END
  492  
  493   %ROUTINE MTSTBOFF(%INTEGER NUM,DIE)
  494   %IF NUM+DIE<25 %THENSTART
  495      %IF BOARD(NUM+DIE)_BS=0 %THEN MMOVE(NUM,DIE) %ELSE NOMOV=1
  496   %FINISHELSESTART
  497      BOARD(NUM)_WS=BOARD(NUM)_WS-1
  498      WBOFF=WBOFF+1
  499   %FINISH
  500   %END
  501  
  502   %ROUTINE CLTSTBOFF(%INTEGER NUM,DIE)
  503   TEMP=0
  504   %IF NUM+DIE<25 %THEN CLTSTMOV(NUM,DIE,TEMP) %ELSESTART
  505      BOARD(NUM)_WS=BOARD(NUM)_WS+1
  506      WBOFF=WBOFF-1
  507   %FINISH
  508   %END
  509  
  510   !
  511   !
  512   !
  513   LOADWTS
  514   SELECTINPUT(0)
  515   CLOSESTREAM(1)
  516   INITIALIZE
  517   PRINTSTATE
  518  STRT: %CYCLE
  519   READ(DICE1); READ(DICE2); BSTVAL=X'80000000'
  520   %IF DICE1=DICE2 %THEN DICE3=DICE1 %AND DICE4=DICE2 %C
  521+     %ELSE DICE3=0 %AND DICE4=0
  522   RUNNING=0
  523   %IF WBEARO=15 %THEN -> BEAROFF
  524   TEMP=BBOFF
  525   %CYCLE L=0,1,24
  526      %IF BOARD(L)_WS>0 %THENEXIT
  527      TEMP=TEMP+BOARD(L)_BS
  528   %REPEAT
  529   %IF TEMP=15 %THEN RUNNING=1 %AND -> RUN
  530   M1=0;M2=0;M3=0;M4=0;BARFL=0
  531   %IF WBAR>0 %THENSTART
  532      %IF WBAR>1 %THENSTART
  533         %IF BOARD(DICE1)_BS<2 %THEN MMOVE(0,DICE1)
  534         %IF BOARD(DICE2)_BS<2 %THEN MMOVE(0,DICE2)
  535         -> DONE
  536      %FINISH
  537      %IF BOARD(DICE1)_BS>1 %AND BOARD(DICE2)_BS>1 %THEN -> DONE
  538      BARFL=1
  539   %FINISH
  540   %CYCLE K=1,1,2
  541   %IF K=1 %THEN SECOND=0 %ELSESTART
  542      TEMP=DICE1; DICE1=DICE2; DICE2=TEMP; SECOND=1
  543   %FINISH
  544   %CYCLE I=0,1,23
  545      %IF BOARD(I)_WS>0 %THEN PT1=I %ELSE -> CYC1
  546      %IF PT1+DICE1<25 %AND BOARD(PT1+DICE1)_BS<2 %THENSTART
  547         MTSTMOV(PT1,DICE1,BARPT1); M1=1
  548         %IF WBEARO=15 %THEN DICE1=0 %AND -> BEAROFF
  549         %IF SECOND=1 %THEN N=I+1 %ELSE N=I
  550         %CYCLE J=N,1,24
  551            %IF BOARD(J)_WS>0 %THEN PT2=J %ELSE -> CYC2
  552            %IF PT2+DICE2<25 %AND BOARD(PT2+DICE2)_BS<2 %THENSTART
  553               MTSTMOV(PT2,DICE2,BARPT2); M2=1
  554               %IF DICE1=DICE2 %THENSTART
  555                  %IF WBEARO=15 %THEN DICE2=0 %AND DICE1=0 %AND -> BEAROFF
  556                  %CYCLE G=J,1,23
  557                     %IF BOARD(G)_WS>0 %THEN PT3=G %ELSE -> CYC3
  558                     %IF PT3+DICE1<25 %AND BOARD(PT3+DICE1)_BS<2 %C
  559+                       %THENSTART
  560                        MTSTMOV(PT3,DICE1,BARPT3); M3=1
  561                        %IF WBEARO=15 %THEN DICE1=0 %AND DICE2=0 %C
  562+                          %AND DICE3=0 %AND -> BEAROFF
  563                        %CYCLE H=G,1,23
  564                           %IF BOARD(H)_WS>0 %THEN PT4=H %ELSE -> CYC4
  565                           %IF PT4+DICE2<25 %AND BOARD(PT4+DICE2)_BS<2 %C
  566+                             %THENSTART
  567                              MTSTMOV(PT4,DICE2,BARPT4); M4=1
  568                              GBRD
  569                              CLTSTMOV(PT4,DICE2,BARPT4)
  570                           %FINISH
  571  CYC4:                 %REPEAT
  572                        %IF M4=0 %THEN GBRD %AND BSTVAL=X'80000000'
  573                        CLTSTMOV(PT3,DICE1,BARPT3)
  574                     %FINISH
  575  CYC3:           %REPEAT
  576                  %IF M3=0 %THEN GBRD %AND BSTVAL=X'80000000'
  577               %FINISHELSE GBRD
  578               CLTSTMOV(PT2,DICE2,BARPT2)
  579            %FINISH
  580  CYC2:  %REPEAT
  581         %IF M2=0 %THEN GBRD %AND BSTVAL=X'80000000'
  582         CLTSTMOV(PT1,DICE1,BARPT1)
  583      %FINISH
  584      %EXITIF BARFL=1
  585  CYC1: %REPEAT
  586   %EXITIF DICE1=DICE2
  587   %REPEAT
  588   %IF M1=1 %THEN MMOVE(BSTPT1,BSTMOV1)
  589   %IF M2=1 %THEN MMOVE(BSTPT2,BSTMOV2)
  590   %IF DICE1=DICE2 %THENSTART
  591      %IF M3=1 %THEN MMOVE(BSTPT3,BSTMOV1)
  592      %IF M4=1 %THEN MMOVE(BSTPT4,BSTMOV2)
  593   %FINISH
  594  DONE: %IF WBOFF=15 %THEN PRINTSTRING("yeah") %AND NEWLINE %ANDEXIT
  595   PRINTSTATE; DOBLACK
  596   %IF BBOFF=15 %THEN PRINTSTRING("pity") %AND NEWLINE %ANDEXIT
  597   %IF RUNNING=1 %THEN -> STRT
  598   GBRDVAL
  599   %IF BRDVAL=COMPVAL %THEN -> STRT
  600   %IF COMPVAL<BRDVAL %THENSTART
  601      GOOD(BV1,W1); GOOD(BV2,W2); GOOD(BV3,W3); GOOD(BV4,W4)
  602      GOOD(BV5,W5); GOOD(BV6,W6); GOOD(BV7,W7); GOOD(BV8,W8)
  603      GOOD(BV9,W9); GOOD(BV10,W10)
  604   %FINISHELSESTART
  605      BAD(BV1,W1); BAD(BV2,W2); BAD(BV3,W3); BAD(BV4,W4); BAD(BV5,W5)       
  606      BAD(BV6,W6); BAD(BV7,W7); BAD(BV8,W8); BAD(BV9,W9); BAD(BV10,W10)
  607   %FINISH
  608   COMPVAL=BRDVAL; -> STRT
  609  RUN: %IF DICE2>DICE1 %THENSTART
  610      TEMP=DICE2; DICE2=DICE1; DICE1=TEMP
  611   %FINISH
  612   TEMP=0
  613   %CYCLE I=1,1,18
  614      %IF BOARD(I)_WS>0 %THENSTART
  615         MMOVE(I,DICE1); TEMP=1
  616         %CYCLE J=I,1,18
  617            %IF BOARD(J)_WS>0 %THENSTART
  618               %IF DICE1#DICE2 %THEN MMOVE(J,DICE2) %C
  619+                 %ELSE MMOVE(J,DICE1); TEMP=2
  620               %IF DICE1=DICE2 %THENSTART
  621                  %CYCLE G=J,1,18
  622                     %IF BOARD(G)_WS>0 %THENSTART
  623                        MMOVE(G,DICE1); TEMP=3
  624                        %CYCLE H=G,1,18
  625                           %IF BOARD(H)_WS>0 %THENSTART
  626                              MMOVE(H,DICE2); TEMP=4
  627                              %EXIT
  628                           %FINISH
  629                        %REPEAT
  630                        %EXIT
  631                     %FINISH
  632                  %REPEAT
  633               %FINISH
  634               %EXIT
  635            %FINISH
  636         %REPEAT
  637         %EXIT
  638      %FINISH
  639   %REPEAT
  640   %IF DICE1=DICE2 %AND TEMP=4 %THEN -> DONE
  641   %IF DICE1#DICE2 %AND TEMP=2 %THEN -> DONE
  642   %IF DICE1#DICE2 %THEN DICE1=0 %AND -> BEAROFF
  643   DICE1=0
  644   %IF TEMP>1 %THEN DICE2=0
  645   %IF TEMP>2 %THEN DICE3=0
  646  BEAROFF: RUNNING=1
  647   TEMP=WBOFF
  648   %CYCLE M=24,-1,19
  649      %IF BOARD(M)_BS>0 %THEN -> SAFETY
  650      TEMP=TEMP+BOARD(M)_WS
  651      %IF TEMP=15 %THENEXIT
  652   %REPEAT
  653   %IF DICE1>DICE2 %THENSTART
  654      TEMP=DICE2; DICE2=DICE1; DICE1=TEMP
  655   %FINISH
  656   %IF DICE1#0 %THENSTART
  657      %IF BOARD(25-DICE1)_WS>0 %THENSTART
  658         BOARD(25-DICE1)_WS=BOARD(25-DICE1)_WS-1
  659         WBOFF=WBOFF+1
  660      %FINISHELSESTART
  661         %IF BOARD(25-DICE1+1)_WS>0 %THENSTART
  662            BOARD(25-DICE1+1)_WS=BOARD(25-DICE1+1)_WS-1
  663            WBOFF=WBOFF+1
  664         %FINISHELSESTART
  665            %CYCLE M=19,1,25-DICE1
  666               %IF WBOFF<8 %THENSTART
  667                  %IF BOARD(M)_WS>2 %THEN MMOVE(M,DICE1) %AND -> SEC
  668               %FINISHELSESTART
  669                  %IF BOARD(M)_WS>1 %THEN MMOVE(M,DICE1) %AND -> SEC
  670               %FINISH
  671            %REPEAT
  672            %CYCLE M=19,1,24
  673               %IF DICE2+M<25 %THENSTART
  674                  %IF BOARD(M)_WS>0 %THEN MMOVE(M,DICE1) %ANDEXIT
  675               %FINISH
  676               %IF M+DICE2=25 %THENSTART
  677                  %IF BOARD(M)_WS>1 %THEN MMOVE(M,DICE1) %ANDEXIT
  678               %FINISH
  679               %IF DICE2+M>25 %THENSTART
  680                  %IF BOARD(M)_WS>0 %THENSTART
  681                     %IF M+DICE1<25 %THEN MMOVE(M,DICE1) %ELSE %C
  682+                      WBOFF=WBOFF+1 %AND BOARD(M)_WS=BOARD(M)_WS-1
  683                     %EXIT
  684                  %FINISH
  685               %FINISH
  686            %REPEAT
  687         %FINISH
  688      %FINISH
  689   %FINISH
  690  SEC: DOBEST(DICE2)
  691   %IF DICE4=0 %THEN ->DONE
  692   DOBEST(DICE3)
  693   DOBEST(DICE4)
  694   ->DONE
  695  SAFETY: %IF DICE4#0 %THENSTART
  696      %IF DICE3=0 %THEN DICE1=DICE4 %AND DICE4=0 %ELSESTART
  697         %IF DICE2=0 %THENSTART
  698            DICE1=DICE4; DICE4=0; DICE2=DICE3; DICE3=0
  699         %FINISHELSESTART
  700            %IF DICE1=0 %THEN DICE1=DICE4 %AND DICE4=0
  701         %FINISH
  702      %FINISH
  703   %FINISHELSESTART
  704      %IF DICE1=0 %THEN DICE1=DICE2 %AND DICE2=0
  705   %FINISH
  706   %IF DICE1<DICE2 %THENSTART
  707      TEMP=DICE2; DICE2=DICE1; DICE1=TEMP
  708   %FINISH
  709   %CYCLE K=35,3,56
  710   %CYCLE I=19,1,24
  711      %IF BOARD(I)_WS>0 %THENSTART
  712         NOMOV=0; MTSTBOFF(I,DICE1)
  713         %IF NOMOV=1 %THEN ->REP1
  714         %IF DICE2=0 %THENSTART
  715            %IF WSINCL<K %THEN ->DONE
  716         %FINISHELSESTART
  717            %CYCLE J=19,1,24
  718               %IF BOARD(J)_WS>0 %THENSTART
  719                  NOMOV=0; MTSTBOFF(J,DICE2)
  720                  %IF NOMOV=1 %THEN ->REP2
  721                  %IF DICE3=0 %THENSTART
  722                     %IF WSINCL<K %THEN ->DONE
  723                  %FINISHELSESTART
  724                     %CYCLE G=19,1,24
  725                        %IF BOARD(G)_WS>0 %THENSTART
  726                           NOMOV=0; MTSTBOFF(G,DICE3)
  727                           %IF NOMOV=1 %THEN ->REP3
  728                           %IF DICE4=0 %THENSTART
  729                              %IF WSINCL<K %THEN ->DONE
  730                           %FINISHELSESTART
  731                              %CYCLE H=19,1,24
  732                                 %IF BOARD(H)_WS>0 %THENSTART
  733                                    NOMOV=0; MTSTBOFF(H,DICE4)
  734                                    %IF NOMOV=1 %THEN ->REP4
  735                                    %IF WSINCL<K %THEN ->DONE
  736                                    CLTSTBOFF(H,DICE4)
  737                                 %FINISH
  738  REP4:                       %REPEAT
  739                           %FINISH
  740                           CLTSTBOFF(G,DICE3)
  741                        %FINISH
  742  REP3:              %REPEAT
  743                  %FINISH
  744                  CLTSTBOFF(J,DICE2)
  745               %FINISH
  746  REP2:     %REPEAT
  747         %FINISH
  748         CLTSTBOFF(I,DICE1)
  749      %FINISH
  750  REP1: %REPEAT
  751   %REPEAT
  752   %REPEAT
  753   DUMPWTS
  754  %END
?WFST12 unused
?BFST12 unused
?ST unused
  755  
  756  %begin
  757    backgammon("")
  758  %end
  759  
  760  %ENDOFFILE

  805 Statements compiled
