A more or less pointless implementation of “Russian Roulette”, printed in David H. Ahl’s BASIC Computer Games:
In this game, you are given by the computer a revolver loaded with one bullet and five empty chambers. You spin the chamber and pull the trigger by inputting a “1”, or, if you want to quit, input a “2”. You win if you play then times and are still alive.
The game calls three procedures that are not part of the ANSI FORTRAN 77 language standard:
RESULT = TIME()
INTEGER
). Required for the
initialisation of the pseudo-random number generator.RESULT = RAND(I)
REAL
).CALL SRAND(ISEED)
INTEGER
).Most modern compilers provide these through extensions.
Save the source as russian.f
on your computer.
C ******************************************************************
C
C RUSSIAN ROULETTE
C
C ORIGINAL BASIC VERSION WRITTEN BY TOM ADAMETX, MODIFIED AND
C PUBLISHED BY DAVID H. AHL. CONVERTED TO FORTRAN BY PHILIPP ENGEL.
C
C ******************************************************************
PROGRAM RUSSIA
INTEGER N, INPUT, ISTAT
CALL SRAND(TIME())
PRINT 100
C
C THE MAIN LOOP.
C
10 CONTINUE
N = 0
PRINT 200
C
C USER INPUT LOOP.
C
20 CONTINUE
READ (*, 300, IOSTAT=ISTAT) INPUT
IF (ISTAT .NE. 0 .OR. (INPUT .NE. 1 .AND. INPUT .NE. 2)) THEN
PRINT 400
GOTO 20
END IF
IF (INPUT .EQ. 1) THEN
N = N + 1
C
C UHH-OHH ...
C
IF (RAND(0) .LE. 1.0 / 6) THEN
PRINT 500
PRINT 900
GOTO 10
END IF
C
C PLAYER HAS WON.
C
IF (N .GT. 10) THEN
PRINT 600
GOTO 10
END IF
C
C PLAYER GOT LUCKY.
C
PRINT 700
GOTO 20
ELSE IF (INPUT .EQ. 2) THEN
PRINT 800
PRINT 900
GOTO 10
END IF
100 FORMAT (27X,' RUSSIAN ROULETTE',/,
&26X,' CREATIVE COMPUTING',/,24X,' MORRISTOWN, NEW JERSEY',/,/,
&' THIS IS A GAME OF RUSSIAN ROULETTE. HERE IS A REVOLVER.')
200 FORMAT (/,' TYPE "1" TO SPIN THE CHAMBER AND PULL THE TRIGGER.',/,
&' TYPE "2" TO GIVE UP.',/,' GO!')
300 FORMAT (I1)
400 FORMAT (' INVALID INPUT. TRY AGAIN:')
500 FORMAT (' BANG!! YOU ARE DEAD!',/,
&' CONDOLENCES WILL BE SENT TO YOUR RELATIVES.')
600 FORMAT (' YOU WIN!',/,' LET SOMEONE ELSE BLOW HIS BRAINS OUT.')
700 FORMAT (' - CLICK -')
800 FORMAT (' CHICKEN!!')
900 FORMAT (/,' ... NEXT VICTIM ...')
END
UNIX | Flang/F18 | $ flang -o russian russian.f |
---|---|---|
GNU Fortran | $ gfortran -o russian russian.f | |
Intel Fortran Compiler | $ ifort -o russian russian.f | |
Win32 | Digital/Compaq Visual Fortran | > fl32.exe russian.f /Fe=russian.exe |