Back in 1975 we developed a version of Tic Tac Toe that runs on the IBM System 360 or System 370 mainframe using a standard 3270 terminal. FORTRAN is standard for all mainframes from 1958 onwards. The code shown is standard FORTRAN IV which IBM developed and its largely compatible with more recent standards.
FORTRAN arrays are column major, but standard coding is always explicit when working with arrays to prevent problems.
The game required over 200 lines of code. The game AI was simple brute force as there are only 9 cells to consider and each cell is in only one of 3 states. The FORTRAN language supports multiple dimension arrays so this make the game board easy.
INTEGER BOARD DIMENSION BOARD(3,3)
then each cell can be empty or it can be X or O.
INTEGER EMPTY = 0 INTEGER X = 1 INTEGER O = 2
FORTRAN uses a FORMAT statement to control the way the printed lines are formatted. The the PRINT statement calls the FORMAT to be used before the data is then printed.
FORTRAN can use nested DO statement so initializing the game is comparatively easy. the CONTINUE statement helps the compiler know how the loops are to be handled.
DO 20 I=1,3 DO 10 J=1,3 BOARD(i,j) = 0 10 CONTINUE 20 CONTINUE
The 3270 display is 80×24 characters so there is lots of room to work with. The FORMAT can handle the special symbols easily so that a game board can be displayed.
990 FORMAT(I1, ' | ' ,I1, ' | ' , I1) 992 FORMAT("--------')
Now with the FORMAT statements ready we can now print the board with another DO loop.
DO 10 i=1,3 WRITE(*,990) BOARD(i, 1) BOARD(i, 2), BOARD(i,3) IF(I.NE.3) WRITE(*,992) 10 CONTINUE
The IF statement prevents the mid line from being drawn after the bottom of the game board. The rest of the game is more of the same, the game was built mostly to demonstrate how simple games take a fair bit of formal logic to convert into something a computer can handle.
The AI used a bank of IF ELSE statements to brute force the game.
We have a C++ version as source code available that can be compiled for any platform. We will update this when if anything is deprecated in the ISO standards.