The Oregon Trail

You probably have heard of the game The Oregon Trail, at least of the quite famous Apple II version (“You have died of dysentery”). Some of you may even know that there are text-based predecessors written in BASIC for several platforms. In 1978, the BASIC source code of an enhanced version was published in the Creative Computing magazine. So, I thought, how hard can it be to port the ~600 lines of BASIC source code to a more serious programming language like … FORTRAN 77?

Oh boy, that was far less fun than anticipated. But here it is:

The Oregon Trail in FORTRAN 77

The remake is written in ANSI FORTRAN 77 and should therefore be accepted by most FORTRAN compilers. The original BASIC version measured the time the player needed in the hunting/riders parts. Consequently, as the ANSI standard does not feature a TIME() function or similar, I had to implement some wrapper functions around the extensions provided by the various FORTRAN 77 compilers.

You can even try out the new LLVM-based Flang/F18 compiler to build the game!

4 Likes

Builds fine with LLVM 13 and F18/Flang on FreeBSD 12.

1 Like

For F90 compilers

  FUNCTION TIME()
  INTEGER TIME
  INTEGER IHR, IMIN, ISEC, IVAL(8)
  CALL DATE_AND_TIME(VALUES=IVAL)
  IHR = IVAL(5)
  IMIN = IVAL(6)
  ISEC = IVAL(7)
  TIME = (IHR * 3600) + (IMIN * 60) + ISEC
  END
1 Like

The DATE_AND_TIME routine is pretty slow. If you are trying to time execution of parts of a code the SYSTEM_CLOCK intrinsic is a better option.

OP isn’t trying to time execution of the code, they’re trying to time the user. In this case it doesn’t need to be fast and precise. Also, they’re trying to stick to F77, so the SYSTEM_CLOCK intrinsic wasn’t introduced yet (IIRC).

True. Both DATE_AND_TIME and SYSTEM_CLOCK were new in F90. My comment was mainly aimed at the proposed f90 replacement. Overall, the whole F77 code could use a conversion to standard Fortran.

Yeah, using more modern standards would certainly make the project easier, and easier to stick to the standard. But I think this was more of a fun exercise than a serious project.