      INTEGER B(10,10),DIR(30,8),CHT(8) 
      INTEGER MOVEI,MOVEJ 
      DIMENSION DRSPON(2),IAA(8),JAA(8),MOVESI(30)
     +,MOVESJ(30),LC(30),NFLIP(30)
      COMMON /OCOMMN/ OC
      DATA DRSPON/'YES','NO'/ 
      DATA IAA/-1,-1,-1,0,1,1,1,0/
      DATA JAA/-1,0,1,1,1,0,-1,-1/
      DATA CHT/'A','B','C','D','E','F','G','H'/ 
   22 DO 10 I=1,10
      DO 10 J=1,10
      B(I,J)=0
      IF(I.EQ.1.OR.I.EQ.10)B(I,J)=100 
   10 IF(J.EQ.1.OR.J.EQ.10)B(I,J)=100 
      B(5,5)=1
      B(5,6)=-1 
      B(6,5)=-1 
      B(6,6)=1
      WRITE(1,601)
  601 FORMAT(//,1X,'WELCOME TO THE GAME OF OTHELLO. DO YOU WISH TO' 
     +,/,1X,'GO FIRST? YOU ARE "X" IF YOU ARE FIRST. ') 
      READ(1,876)RESPON 
  876 FORMAT(A3)
      OC=1
      IF(RESPON.EQ.DRSPON(2))GOTO 11
      CALL HANDIC(OC,B,DRSPON,NHD)
      NM=NHD
      CALL BOARDP(B,NM,NHD) 
    8 IF(NM.EQ.60)GOTO 15 
      CALL MOVEG(B,-OC,NM,MOVESI,MOVESJ,DIR,LC,JAA,IAA, 
     +IM,NOMVE,NFLIP) 
      IF(IM.EQ.0)GOTO 12
      WRITE(1,713)
  713 FORMAT(//,1X,'WHAT IS YOUR MOVE ? (IJ) ') 
   14 READ(1,678)MOVEI,MOVEJ
  678 FORMAT(A1,I1) 
      MOVEI=MOVEI-1HA+2 
      MOVEJ=MOVEJ+1 
      DO 9 I=1,IM 
      IF(MOVESI(I).EQ.MOVEI.AND.MOVESJ(I).EQ.MOVEJ)GOTO 13
    9 CONTINUE
      WRITE(1,701)
  701 FORMAT(1X,'MOVE INVALID. PLEASE RE-ENTER. ')
      GOTO 14 
   13 NM=NM+1 
      CALL BOARDC(MOVESI,MOVESJ,I,IAA,JAA,B,-OC,DIR,LC) 
      CALL BOARDP(B,NM,NHD) 
      GOTO 2
   11 OC=-1 
      CALL HANDIC(OC,B,DRSPON,NHD)
      B(5,7)=1
      B(5,6)=1
      NM=NHD+1
      CALL BOARDP(B,NM,NHD) 
      GOTO 8
   12 WRITE(1,756)
  756 FORMAT(/,1X,'I CAN SEE NO MOVE FOR YOU, SO I WILL', 
     +' MOVE IF I CAN.')
    2 IF(NM.EQ.60)GOTO 15 
      CALL MOVEG(B,OC,NM,MOVESI,MOVESJ,DIR,LC,JAA,IAA,
     +IM,NOMVE,NFLIP) 
      IF(IM.EQ.0)GOTO 20
      CALL MOVEE(B,OC,NM,MOVESI,MOVESJ,NFLIP,DIR,LC,IM,IF,IAA,JAA)
      MOVEI=MOVESI(IF)-2+1HA
      MOVEJ=MOVESJ(IF)-1
      WRITE(1,603)MOVEI,MOVEJ 
  603 FORMAT(/,1X,'MY MOVE IS : ',A1,I1)
      CALL BOARDC(MOVESI,MOVESJ,IF,IAA,JAA,B,OC,DIR,LC) 
      NM=NM+1 
      CALL BOARDP(B,NM,NHD) 
      GOTO 8
   20 WRITE(1,602)
  602 FORMAT(/,1X,'DO YOU HAVE A MOVE? ') 
      READ(1,876)RESPON 
      IF(RESPON.EQ.DRSPON(1))GOTO 8 
      IF(IM.NE.0)GOTO 2 
   15 CALL COUNT(B,OC,NOC)
      CALL COUNT(B,-OC,NC)
      IF(NOC.LE.NC)GOTO 900 
      WRITE(1,610)
  610 FORMAT(/,1X,'CONGRATULATIONS, YOU PLAYED WELL AND HAVE WON.'
     +,/,1X,'THANK YOU FOR A FINE GAME.') 
      GOTO 920
  900 IF(NOC.EQ.NC)GOTO 910 
      WRITE(1,611)
  611 FORMAT(/,1X,'YOU PLAYED WELL; HOWEVER, YOUR LUCK WAS BAD AND' 
     +,/,1X,'I HAVE WON. THANK YOU FOR A FINE GAME.') 
      GOTO 920
  910 WRITE(1,612)
  612 FORMAT(/,1X,'YOU PLAYED WELL AND WE HAVE TIED. I WAS LUCKY.'
     +,/,1X,'THANK YOU FOR A FINE GAME.') 
  920 WRITE(1,613)
  613 FORMAT(/,1X,'DO YOU WISH TO PLAY AGAIN? ')
      READ(1,876)RESPON 
      IF(RESPON.EQ.DRSPON(1))GOTO 22
      STOP
      END 
      SUBROUTINE MOVEG(B,OC,NM,MOVESI,MOVESJ,DIR,LC,JAA,IAA,IM
     +,NOMVE,NFLIP) 
      INTEGER B(10,10),DIR(30,8)
      DIMENSION MOVESI(30),MOVESJ(30),LC(30),NFLIP(30)
     +,IAA(1),JAA(1)
      COMMON /OCOMMN/ OCA 
      DO 1 I=1,30 
      LC(I)=0 
    1 NFLIP(I)=0
      IM=0
      DO 20 I=2,9 
      DO 20 J=2,9 
      IF(B(I,J).NE.0)GOTO 20
      IC=0
      DO 5 L=1,8
      IA=IAA(L) 
      JA=JAA(L) 
      IAT=I+IA
      JAT=J+JA
      IF(B(IAT,JAT).NE.OC)GOTO 5
      IV=1
    4 IV=IV+1 
      MVI=I+IV*IA 
      MVJ=J+IV*JA 
      IF(B(MVI,MVJ).EQ.0)GOTO 5 
      IF(B(MVI,MVJ).EQ.100)GOTO 5 
      IF(B(MVI,MVJ).EQ.OC)GOTO 4
      IF(IC.EQ.1)GOTO 12
      IM=IM+1 
      IC=1
   12 NFLIP(IM)=NFLIP(IM)+IV
      LC(IM)=LC(IM)+1 
      LDX=LC(IM)
      DIR(IM,LDX)=L 
    5 CONTINUE
      IF(IC.EQ.0)GOTO 20
      MOVESI(IM)=I
      MOVESJ(IM)=J
   20 CONTINUE
      IF(IM.GT.0)GOTO 30
      IF(OCA.NE.OC)GOTO 30
      WRITE(1,100)
  100 FORMAT(/,1X,'I HAVE NO MOVE AND MUST PASS.')
   30 RETURN
      END 
      SUBROUTINE BOARDP(B,NM,NHD) 
      DIMENSION OUT(3),POUT(10,10)
      INTEGER B(10,1),CHT(8)
      COMMON /OCOMMN/ OCA 
      DATA OUT/'O','.','X'/ 
      DATA CHT/'A','B','C','D','E','F','G','H'/ 
      NMP=NM-NHD
      TOC=OCA 
      CALL COUNT(B,TOC,NOC) 
      TOC=0-TOC 
      CALL COUNT(B,TOC,NC)
      WRITE(1,100)NMP,NOC,NC
  100 FORMAT(/,6X,'BOARD POSITION AFTER ',I2,' MOVES',/ 
     +,6X,'YOU HAVE ',I2,' PIECES, I HAVE ',I2,/) 
      WRITE(1,101)
  101 FORMAT(6X,'J = 1  2  3  4  5  6  7  8') 
      WRITE(1,102)
  102 FORMAT(6X,'I')
      WRITE(1,103)
  103 FORMAT(6X,'"')
      DO 9 I=2,9
      DO 9 J=2,9
      IS=B(I,J)+2 
    9 POUT(I,J)=OUT(IS) 
      DO 10 I=2,9 
      I1=I-1
   10 WRITE(1,104)CHT(I1),(POUT(I,J),J=2,9) 
  104 FORMAT(6X,A1,3X,8(A1,2X)) 
      WRITE(1,105)
  105 FORMAT(//)
      RETURN
      END 
      SUBROUTINE COUNT(B,OC,NOC)
      INTEGER B(10,1) 
      NOC=0 
      DO 10 I=2,9 
      DO 10 J=2,9 
      IF(B(I,J).NE.OC)GOTO 10 
      NOC=NOC+1 
   10 CONTINUE
      RETURN
      END 
      SUBROUTINE BOARDC(MOVESI,MOVESJ,IF,IAA,JAA,B,OC,DIR,LC) 
      INTEGER B(10,10),DIR(30,8)
      DIMENSION MOVESI(30),MOVESJ(30),IAA(1),JAA(1),LC(30)
      MI=MOVESI(IF) 
      MJ=MOVESJ(IF) 
      B(MI,MJ)=-OC
      NDIR=LC(IF) 
      DO 40 I=1,NDIR
      L=DIR(IF,I) 
      IA=IAA(L) 
      JA=JAA(L) 
      IV=0
   31 IV=IV+1 
      MVI=MI+IV*IA
      MVJ=MJ+IV*JA
      IF(B(MVI,MVJ).EQ.-OC)GOTO 40
      B(MVI,MVJ)=-OC
      GOTO 31 
   40 CONTINUE
      RETURN
      END 
      SUBROUTINE MOVEE(B,OC,NM,MOVESI,MOVESJ,NFLIP,DIR,LC 
     +,IM,IF,IAA,JAA) 
      INTEGER B(10,1),DIR(30,1),BT(10,10),BTT(10,10),DIRB(20,8) 
     +,BTTS(9,9,20),DIRBB(20,8) 
      DIMENSION MOVESI(1),MOVESJ(1),LC(1),NFLIP(1),MBI(20),MBJ(20)
     +,LCB(20),NFLIPB(30),IAA(1),JAA(1),IY(24),JY(24) 
     +,IMID(24),JMID(24),ID(24),JD(24),NCORNI(4),NCORNJ(4)
     +,MBBI(20),MBBJ(20),LCBB(20),NFLIB(30) 
      DATA NCORNI,NCORNJ/2,2,9,9,2,9,9,2/ 
      DATA ID,JD/3,4,5,6,7,8,6*9,8,7,6,5,4,3,12*2,3,4,5,6,7,8 
     +,6*9,8,7,6,5,4,3/ 
      DATA IY,JY/5,1,3,8,1,6,9,1,9,9,1,9,6,1,8,3,1,5,2,1,2,2,1,2
     +,2,1,2,2,1,2,5,1,3,8,1,6,9,1,9,9,1,9,6,1,8,3,1,5/ 
      DATA IMID,JMID/4,1,4,7,1,7,9,1,9,9,1,9,7,1,7,4,1,4,2,1,2
     +,2,1,2,2,1,2,2,1,2,4,1,4,7,1,7,9,1,9,9,1,9,7,1,7,4,1,4/ 
      ICO=0 
      IF=1
      IF(NM.EQ.59)GOTO 20 
   10 DO 12 I=1,IM
      MI=MOVESI(I)
      MJ=MOVESJ(I)
      IF(MI.NE.3.AND.MI.NE.8)GOTO 13
      IF(MJ.NE.3.AND.MJ.NE.8)GOTO 13
      IF(MI.EQ.3.AND.MJ.EQ.3)IC=1 
      IF(MI.EQ.3.AND.MJ.EQ.8)IC=2 
      IF(MI.EQ.8.AND.MJ.EQ.8)IC=3 
      IF(MI.EQ.8.AND.MJ.EQ.3)IC=4 
      NCI=NCORNI(IC)
      NCJ=NCORNJ(IC)
      IF(B(NCI,NCJ).EQ.0)NFLIP(I)=NFLIP(I)-50 
   13 IF(MI.NE.2.AND.MI.NE.9)GOTO 11
      IF(MJ.NE.2.AND.MJ.NE.9)GOTO 11
      ICO=ICO+1 
      NFLIP(I)=NFLIP(I)+60
   11 IF(MI.LE.3.OR.MI.GE.8)GOTO 2
      IF(MJ.LE.3.OR.MJ.GE.8)GOTO 2
      NFLIP(I)=NFLIP(I)+10
      GOTO 12 
    2 ND=LC(I)
      DO 5 J=1,ND 
      L=DIR(I,J)
      IA=IAA(L) 
      JA=JAA(L) 
      IV=1
    4 IV=IV+1 
      MVI=MI+IV*IA
      MVJ=MJ+IV*JA
      IF(B(MVI,MVJ).EQ.OC)GOTO 4
    6 IV=IV+1 
      MVI=MI+IV*IA
      MVJ=MJ+IV*JA
      IF(B(MVI,MVJ).EQ.OC)GOTO 8
      IF(B(MVI,MVJ).NE.-OC)GOTO 5 
      GOTO 6
    8 MIT=MI-IA 
      MJT=MJ-JA 
      IF(B(MIT,MJT).NE.0)GOTO 5 
      NFLIP(I)=NFLIP(I)-5 
      GOTO 12 
    5 CONTINUE
   12 CONTINUE
      DO 32 I=1,IM
      NSUBO=0 
      MI=MOVESI(I)
      MJ=MOVESJ(I)
      IC=0
      DO 33 K=1,10
      DO 33 J=1,10
   33 BT(K,J)=B(K,J)
      LL=0
      DO 56 J=1,24
      IPP=ID(J) 
      JPP=JD(J) 
      IF(MOVESI(I).NE.IPP.OR.MOVESJ(I).NE.JPP)GOTO 56 
      LL=J
   56 CONTINUE
      CALL BOARDC(MOVESI,MOVESJ,I,IAA,JAA,BT,OC,DIR,LC) 
      CALL MOVEG(BT,-OC,NM,MBI,MBJ,DIRB,LCB,JAA,IAA,IM1 
     +,NOMVE,NFLIPB)
      IF(IM1.NE.0)GOTO 63 
      NFLIP(I)=NFLIP(I)+100 
      GOTO 32 
   63 DO 36 J=1,IM1 
      DO 34 K=1,10
      DO 34 L=1,10
   34 BTT(K,L)=BT(K,L)
      CALL BOARDC(MBI,MBJ,J,IAA,JAA,BTT,-OC,DIRB,LCB) 
      IF(LL.EQ.0)GOTO 38
      IC=1
      IZ=IY(LL) 
      JZ=JY(LL) 
      IF(B(IZ,JZ).NE.-OC)GOTO 41
      MK=JMID(LL) 
      ML=IMID(LL) 
      IF(B(ML,MK).EQ.0)NSUBO=90 
   41 IF(BTT(MI,MJ).NE.OC)GOTO 38 
      NFLIP(I)=NFLIP(I)-40
      IC=2
   38 CONTINUE
      CALL COUNT(BTT,-OC,NOC) 
      IF(NOC.GT.0)GOTO 42 
      NFLIP(I)=NFLIP(I)-200 
      GOTO 32 
   42 DO 37 K1=2,9
      DO 37 K2=2,9
   37 BTTS(K1,K2,J)=BTT(K1,K2)
      DO 100 IL=2,9 
      DO 100 JL=2,9 
      IF(BTT(IL,JL).EQ.0)GOTO 100 
      IF(BTT(IL,JL).EQ.OC)GOTO 100
      DO 90 IZ=1,8
      IV=0
   80 IV=IV+1 
      ILL=IL+IV*IAA(IZ) 
      JLL=JL+IV*JAA(IZ) 
      IF(BTT(ILL,JLL).EQ.0)GOTO 36
      IF(BTT(ILL,JLL).EQ.100)GOTO 36
      IF(BTT(ILL,JLL).NE.OC)GOTO 80 
   90 CONTINUE
  100 CONTINUE
   95 CALL MOVEG(BTT,OC,NM,MBBI,MBBJ,DIRBB,LCBB,JAA,IAA,IM2 
     +,NOMVE,NFLIB) 
      IF(IM2.EQ.0)GOTO 103
      DO 102 IL=1,IM2 
      IF(MBBI(IL).NE.2.OR.MBBI(IL).NE.9)GOTO 102
      IF(MBBJ(IL).NE.2.OR.MBBJ(IL).NE.9)GOTO 102
      GOTO 36 
  102 CONTINUE
  103 NFLIP(I)=NFLIP(I)-190 
   36 CONTINUE
      IF(IC.NE.1)GOTO 35
      DO 50 K=1,24
      IQ=ID(K)
      JQ=JD(K)
      IF(MI.EQ.IQ.AND.MJ.EQ.JQ)GOTO 50
      IF(B(IQ,JQ).NE.-OC)GOTO 50
      DO 54 K1=1,IM1
   54 IF(BTTS(IQ,JQ,K1).EQ.OC)NFLIP(I)=NFLIP(I)-8 
   50 CONTINUE
      NFLIP(I)=NFLIP(I)+25-NSUBO
   35 DO 60 K=1,4 
      KC1=NCORNI(K) 
      KC2=NCORNJ(K) 
      IF(B(KC1,KC2).NE.0)GOTO 60
      DO 61 K1=1,IM1
   61 IF(BTTS(KC1,KC2,K1).EQ.OC)NFLIP(I)=NFLIP(I)-55
      IF(ICO.LE.1)GOTO 60 
      IF(MI.EQ.KC1.AND.MJ.EQ.KC2)GOTO 60
      DO 62 K1=1,IM1
   62 IF(BTTS(KC1,KC2,K1).EQ.OC)NFLIP(I)=NFLIP(I)-20
   60 CONTINUE
   32 CONTINUE
      NFLIPM=-800 
      DO 15 I=1,IM
      IF(NFLIP(I).LT.NFLIPM)GOTO 15 
      NFLIPM=NFLIP(I) 
      IF=I
   15 CONTINUE
   20 RETURN
      END 
      SUBROUTINE HANDIC(OC,B,DRSPON,NHD)
      DIMENSION DRSPON(1) 
      INTEGER B(10,1) 
      NHD=0 
      WRITE(1,608)
  608 FORMAT(1X,'DO YOU WISH TO BE GIVEN A HANDICAP? ') 
      READ(1,876)RESPON 
  876 FORMAT(A3)
      IF(RESPON.EQ.DRSPON(1))GOTO 7 
      WRITE(1,610)
  610 FORMAT(1X,'DO YOU WISH TO GIVE ME A HANDICAP? ')
      READ(1,876)RESPON 
      IF(RESPON.EQ.DRSPON(2))GOTO 100 
      NAH=-OC 
      WRITE(1,609)
  609 FORMAT(1X,'HOW MANY CORNERS? (1-4) ') 
  607 READ(1,678)NHD
  678 FORMAT(I1)
      IF(NHD.LT.1.OR.NHD.GT.4)GOTO 607
      CALL HANDI(B,NHD,NAH,OC)
      CALL BOARDP(B,0,0)
      GOTO 100
    7 NAH=OC
      WRITE(1,609)
  606 READ(1,678)NHD
      IF(NHD.LT.1.OR.NHD.GT.4)GOTO 606
      CALL HANDI(B,NHD,NAH,OC)
  100 RETURN
      END 
      SUBROUTINE HANDI(B,NHD,NAH,OC)
      INTEGER B(10,1) 
      INTEGER NCORNI(4),NCORNJ(4) 
      DATA NCORNI,NCORNJ/2,2,9,9,2,9,9,2/ 
      SIGN=-1.0 
      IF(NAH.EQ.OC)SIGN=1.0 
      DO 10 I=1,NHD 
      I1=NCORNI(I)
      I2=NCORNJ(I)
   10 B(I1,I2)=SIGN*OC
      RETURN
      END 
Y EMPTY 
          DCR    B
          JZ     RCS1 
          DCX    H              ;ELSE DISCARD LAST CHAR 
          MOV   