         Edinburgh IMP77 Compiler - Version 8.4

    1  %BEGIN
    2  
    3  
    4  %BYTEINTEGERARRAY DEAL(1:52)
    5  %BYTEINTEGERARRAY HAND(0:3,2:14)
    6  %OWNBYTEINTEGERARRAY S(0:3)='S','H','D','C'
    7  %INTEGER POINTS,BALANCE,LIMIT,CUT
    8  %INTEGERARRAY DIST,PTS(0:3)
    9  %OWNINTEGER HANDCOUNT=0
   10  
   11  %ROUTINE INITIALISE; ! INITIALISES PACK
   12     %INTEGER I,J,K
   13     K=-1
   14     %CYCLE I=0,16,48; ! SUIT
   15         %CYCLE J=2,1,14; ! VALUE
   16             DEAL(K+J)=I+J
   17         %REPEAT; K=K+13; %REPEAT
   18     %END; ! OF INITIALISE
   19  
   20  %ROUTINE SHUFFLE; ! SHUFFLES AND CUTS PACK
   21     %BYTEINTEGERARRAY A(1:52)
   22     %INTEGER I,J
   23     %CYCLE I=1,1,26
   24        A(2*I-1)=DEAL(I); A(2*I)=DEAL(53-I)
   25        %REPEAT
   26     CUT=CUT+11
   27     %IF CUT>=52 %THEN CUT=CUT-52
   28     %IF CUT=0 %THEN CUT=1
   29     %CYCLE I=1,1,CUT
   30        DEAL(52-CUT+I)=A(I); %REPEAT
   31     %CYCLE I=CUT+1,1,52
   32        DEAL(I-CUT)=A(I); %REPEAT
   33     %END;
?J unused
   34          ; ! OF SHUFFLE
   34  
   35  %ROUTINE DEALPACK
   36     %OWNBYTEINTEGERARRAY T(11:14)='J','Q','K','A'
   37     %INTEGER I,J,K,M
   38     POINTS=0;BALANCE=0
   39     %IF HANDCOUNT&7=0 %THENSTART
   40        NEWPAGE; print string("BRIDGEHANDS")
   41        NEWLINES(3); %FINISH
   42     %CYCLE I=0,1,3
   43        %CYCLE J=2,1,14
   44           HAND(I,J)=0; %REPEAT; %REPEAT
   45     %CYCLE I=1,4,49
   46        HAND(DEAL(I)>>4,DEAL(I)&15)=1
   47        %REPEAT
   48     %CYCLE I=0,1,3
   49        K=0; PRINTSYMBOL(S(I)); SPACES(3)
   50        M=0; ! COUNTS POINTS
   51        %CYCLE J=14,-1,11
   52           ->L1 %IF HAND(I,J)=0
   53           SPACE;PRINTSYMBOL(T(J));K=K+1;M=M+J-10
   54    L1:    %REPEAT
   55        %IF HAND(I,10)#0 %THENSTART
   56           WRITE(10,2); K=K+1; %FINISH
   57        %CYCLE J=9,-1,2
   58           ->L2 %IF HAND(I,J)=0
   59           K=K+1; WRITE(J,1)
   60    L2:     %REPEAT
   61        %IF K=0 %THEN print string(" --")
   62        %IF 1<=M<=3 %AND K=1 %THEN M=M-1
   63        PTS(I)=M; POINTS=POINTS+M; DIST(I)=K
   64        %IF K>5 %THEN BALANCE=BALANCE+K-5
   65                 %IF K<2 %THEN BALANCE=BALANCE+2{-???}
   66              NEWLINE; %REPEAT
   67           HANDCOUNT=HANDCOUNT+1
   68           %END; ! OF DEAL
   69  
   70        INITIALISE; READ(CUT); READ(LIMIT)
   71        ->L2 %IF 0<=CUT<=52
   72        print string( "INVALID CUT"); %STOP
   73  L2:   SHUFFLE; SHUFFLE; SHUFFLE; SHUFFLE
   74  L1:   SHUFFLE; DEALPACK
   75        %BEGIN; ! BIDDING BLOCK
   76           %INTEGER LS,NO,SUITPTS
   77                    %SWITCH B(0:20)
   78           %INTEGER I,N
   79           %ROUTINE BIDSUIT(%INTEGER I)
   80              WRITE(I,1); SPACE; PRINTSYMBOL(S(LS))
   81              %END
   82  
   83           %ROUTINE NT(%INTEGER I)
   84              WRITE(I,1); print string(" NT")
   85              %END
   86  
   87           NO=3
   88           %CYCLE I=0,1,3
   89              %IF DIST(I)>NO %THENSTART
   90                 LS=I; NO=DIST(I)
   91                 %FINISH; %REPEAT
   92           %IF LS=0 %AND DIST(3)=NO %THEN LS=3
   93           SUITPTS=PTS(LS)+5*(NO-4); SPACES(18)
   94           N=BALANCE; %IF N>3 %THEN BALANCE=3
   95           ->B(BALANCE)
   96     B(0): ->L2 %IF POINTS>=12
   97     NB:            print string(" NO BID"); ->L1
   98    L2:     %IF POINTS<=15 %THENSTART
   99               ->L3 %IF SUITPTS>10
  100               NT(1); ->L1; %FINISH
  101            %IF POINTS<20 %THENSTART
  102        L3:    BIDSUIT(1); ->L1; %FINISH
  103            %IF POINTS>=23 %THEN ->TC
  104            %IF SUITPTS>=15 %THEN BIDSUIT(2) %ELSE NT(2)
  105            ->L1
  106     B(1):  %IF POINTS=11 %AND SUITPTS>10 %THEN ->L3
  107            ->NB %IF POINTS<=11
  108            ->L3 %IF POINTS<=18
  109            ->L7 %IF POINTS<22
  110     TC:    print string(" 2 C(ACOL)"); ->L1
  111     B(2):  ->PR %IF POINTS<10
  112            ->L6 %IF POINTS>=12
  113            ->L3 %IF SUITPTS>10; ->NB
  114     B(3):  ->PR %IF POINTS<8
  115    L6:     ->L3 %IF POINTS<=18-N
  116            ->TC %IF POINTS>=22-N
  117    L7:     %IF SUITPTS>15 %THEN I=2 %ELSE I=1
  118            ->L8
  119     PR:    SUITPTS=5*(NO-4)+POINTS
  120            ->NB %IF SUITPTS <=20; ->L9 %IF LS<2
  121    L9:     %IF SUITPTS<=27 %THEN I=3 %ELSE I=4
  122            ->NB %IF SUITPTS <=22
  123            %IF SUITPTS >30 %THENSTART
  124               I=5; ->L8; %FINISH
  125    L8:     BIDSUIT(I)
  126    L1:     %END; ! OF BIDDING BLOCK
  127  
  128                   NEWLINES(3)
  129         ->L1 %IF HANDCOUNT<LIMIT
  130         %ENDOFPROGRAM

  166 Statements compiled
