      PROGRAM LOGIKU
C     VIDEOGAME ON BOOLEAN OPERATORS OF LOGICS
C     OPEN SOURCE PUBLIC DOMAIN SOFTWARE- Alexor (2014)
      CHARACTER SINPUT*14
1     CONTINUE
      CALL SRAND(TIME())
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)
     * '******************************************************'
      WRITE(*,*)
     * '*                                                    *'
      WRITE(*,*)
     * '*               Logiku 2014 - version 1              *'
      WRITE(*,*)
     * '*                                                    *'
      WRITE(*,*)
     * '* Open source public domain software - Alexor (2014) *'
      WRITE(*,*)
     * '*                                                    *'
      WRITE(*,*)
     * '******************************************************'
      WRITE(*,*)
      WRITE(*,*)'Press any key to begin'
      WRITE(*,*)
      READ(*,100)SINPUT
      CALL XHELP
2     CONTINUE
      CALL XGAME(ITOT)
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)'GAME OVER - TOTAL SCORE =',ITOT
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)'AGAIN? (Y/N)'
100   FORMAT(A)
      READ(*,100)SINPUT
      WRITE(*,*)
      IF(SINPUT(1:4).EQ.'help'.OR.SINPUT(1:5).EQ.'aiuto')THEN
        CALL XHELP
        GOTO 2
      ENDIF
      IF(SINPUT(1:4).EQ.'quit'.OR.SINPUT(1:4).EQ.'exit'.OR.
     * SINPUT(1:1).EQ.' ')STOP
      IF(SINPUT(1:1).EQ.'Y'.OR.SINPUT(1:1).EQ.'y')GOTO 2
      WRITE(*,*)'End.'
      END

      SUBROUTINE XGAME(ITOT)
      IMPLICIT LOGICAL (L)
      IMPLICIT CHARACTER*2 (S)
      CHARACTER SINPUT
      LOGICAL A1,A2,A3,A4,B1,B2,B3,B4,C1,C2,C3,C4,D1,D2,D3,D4,
     * E1,E2,E3,E4,F1,F2,F3,F4,G1,G2,G3,G4,P,Q,R,S
      ITOT=0
      P=.FALSE.
      Q=.FALSE.
      R=.FALSE.
      S=.FALSE.
      A1=.FALSE.
      A2=.FALSE.
      A3=.FALSE.
      A4=.FALSE.
      B1=.FALSE.
      B2=.FALSE.
      B3=.FALSE.
      B4=.FALSE.
      C1=.FALSE.
      C2=.FALSE.
      C3=.FALSE.
      C4=.FALSE.
      D1=.FALSE.
      D2=.FALSE.
      D3=.FALSE.
      D4=.FALSE.
      E1=.FALSE.
      E2=.FALSE.
      E3=.FALSE.
      E4=.FALSE.
      F1=.FALSE.
      F2=.FALSE.
      F3=.FALSE.
      F4=.FALSE.
      G1=.FALSE.
      G2=.FALSE.
      G3=.FALSE.
      G4=.FALSE.
      IF(RAND().GE.0.5)A1=.TRUE.
      IF(RAND().GE.0.5)A2=.TRUE.
      IF(RAND().GE.0.5)A3=.TRUE.
      IF(RAND().GE.0.5)A4=.TRUE.
      IF(RAND().GE.0.5)B1=.TRUE.
      IF(RAND().GE.0.5)B2=.TRUE.
      IF(RAND().GE.0.5)B3=.TRUE.
      IF(RAND().GE.0.5)B4=.TRUE.
      IF(RAND().GE.0.5)C1=.TRUE.
      IF(RAND().GE.0.5)C2=.TRUE.
      IF(RAND().GE.0.5)C3=.TRUE.
      IF(RAND().GE.0.5)C4=.TRUE.
      IF(RAND().GE.0.5)D1=.TRUE.
      IF(RAND().GE.0.5)D2=.TRUE.
      IF(RAND().GE.0.5)D3=.TRUE.
      IF(RAND().GE.0.5)D4=.TRUE.
      IF(RAND().GE.0.5)E1=.TRUE.
      IF(RAND().GE.0.5)E2=.TRUE.
      IF(RAND().GE.0.5)E3=.TRUE.
      IF(RAND().GE.0.5)E4=.TRUE.
      IF(RAND().GE.0.5)F1=.TRUE.
      IF(RAND().GE.0.5)F2=.TRUE.
      IF(RAND().GE.0.5)F3=.TRUE.
      IF(RAND().GE.0.5)F4=.TRUE.
      IF(RAND().GE.0.5)G1=.TRUE.
      IF(RAND().GE.0.5)G2=.TRUE.
      IF(RAND().GE.0.5)G3=.TRUE.
      IF(RAND().GE.0.5)G4=.TRUE.
1     CONTINUE
      WRITE(*,*)
      WRITE(*,*)'p =',P,'           q =',Q,'           r =',R,
     * '            s =',S
      LA=(P.AND.A2).OR.(A3.AND.S)
      LB=B1.AND.(Q.OR.(R.AND.B4))
      LC=((P.AND.C2).OR.C3).AND.S
      LD=(S.AND..NOT.D2).OR.(R.AND..NOT.D4)
      LE=(Q.AND..NOT.E2).OR.(P.AND..NOT.E4)
      LF=(S.OR..NOT.F2).AND..NOT.(R.OR.F4)
      LG=(p.OR..NOT.G2).AND..NOT.(s.OR.G4)
      SA=' 0'
      SB=' 0'
      SC=' 0'
      SD=' 0'
      SE=' 0'
      SF=' 0'
      SG=' 0'
      IF(LA)SA='+1'
      IF(LB)SB='+1'
      IF(LC)SC='+1'
      IF(LD)SD='+1'
      IF(LE)SE='+1'
      IF(LF)SF='+1'
      IF(LG)SG='+1'
      WRITE(*,*)
      WRITE(*,*)' ( p','   AND  ',A2,' ) OR (',A3,'   AND   s )  = ',
     * LA,'    SCORE =', SA
      WRITE(*,*)
      WRITE(*,*)
     * '  ',B1,'   AND (',' q   OR ( r','   AND  ',B4,' )) = ',
     * LB,'    SCORE =', SB
      WRITE(*,*)
       WRITE(*,*)'(( p','   AND  ',C2,' ) OR  ',C3,' ) AND   s    = ',
     * LC,'    SCORE =', SC
      WRITE(*,*)
      WRITE(*,*)' ( s',' AND NOT',D2,' ) OR ( r AND NOT',D4,' )  = ',
     * LD,'    SCORE =', SD
      WRITE(*,*)
      WRITE(*,*)' ( q',' AND NOT',E2,' ) OR ( p AND NOT',E4,' )  = ',
     * LE,'    SCORE =', SE
      WRITE(*,*)
      WRITE(*,*)' ( s','  OR NOT',F2,' ) AND NOT ( r OR',F4,' )  = ',
     * LF,'    SCORE =', SF
      WRITE(*,*)
      WRITE(*,*)' ( p','  OR NOT',G2,' ) AND NOT ( s OR',G4,' )  = ',
     * LG,'    SCORE =', SG
      ISCORE=0
      IF(LA)ISCORE=ISCORE+1
      IF(LB)ISCORE=ISCORE+1
      IF(LC)ISCORE=ISCORE+1
      IF(LD)ISCORE=ISCORE+1
      IF(LE)ISCORE=ISCORE+1
      IF(LF)ISCORE=ISCORE+1
      IF(LG)ISCORE=ISCORE+1
      ITOT=ITOT+ISCORE
      WRITE(*,*)
     * '                                             ','---------'
      WRITE(*,*)
     * '                                             ',
     * 'SCORE =',ISCORE,'   TOTAL SCORE =',ITOT
      IF(P.AND.Q.AND.R.AND.S)RETURN
2     CONTINUE
      WRITE(*,*)
      WRITE(*,*)'Which one of p, q, r and s (only among those false) ',
     * 'do you want to change?'
100   FORMAT(A)
      READ(*,100)SINPUT
      IF(SINPUT.NE.'p'.AND.SINPUT.NE.'q'.AND.SINPUT.NE.'r'.
     * AND.SINPUT.NE.'s')GOTO 2
      IF(P.AND.SINPUT.EQ.'p')GOTO 3
      IF(Q.AND.SINPUT.EQ.'q')GOTO 3
      IF(R.AND.SINPUT.EQ.'r')GOTO 3
      IF(S.AND.SINPUT.EQ.'s')GOTO 3
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)
      WRITE(*,*)'Let''s change ',SINPUT,' from FALSE to TRUE:'
      IF(SINPUT.EQ.'p')P=.TRUE.
      IF(SINPUT.EQ.'q')Q=.TRUE.
      IF(SINPUT.EQ.'r')R=.TRUE.
      IF(SINPUT.EQ.'s')S=.TRUE.
      GOTO 1
      RETURN
3     CONTINUE
      WRITE(*,*)'* * * ERROR * * * ',SINPUT,' is already TRUE'
      GOTO 2
      END

      SUBROUTINE XHELP
      WRITE(*,*)
      WRITE(*,*)
     * 'T = TRUE      F = FALSE        AND = ET       OR = VEL'
      WRITE(*,*)
      WRITE(*,*)'At the beginning, p, q, r and s are FALSE.'
      WRITE(*,*)
     * 'At the end of the game, after 4 steps, they are TRUE.'
      WRITE(*,*)
     * 'Essentially, you have only to choose in which order to change'
      WRITE(*,*)'each of them from FALSE to TRUE,',
     * ' in order to sum the highest score.'
      RETURN
      END