Othello

In-game screen.

Program listing on 48K Spectrum.

Key showing in-game features (labels refer to single player mode).

Text Listing

1 DIM t(91):
 INPUT "1-2?";f:
 READ n,t(41),t(42),t(50),t(51),t(1),z,p:
 DATA 23620,2,1,1,2,3,2,2: LET p=3-p:
 LET q=z>1:
 DIM c(3):
 FOR a=1 TO 8:
 FOR b=1 TO 8:
 LET k=t(a*9+b+1):
 PRINT AT 9,b;b;AT a,0;a;AT a,b; PAPER k+p*p*(a*9+b+1=z);" ":
 LET c(k+1)=c(k+1)+1:
 NEXT b:
 NEXT a:
 PRINT ''c(2);"x";c(3),:
 IF c(1)*c(p+1) THEN BORDER p:
 POKE (f<p)*n,20:
 INPUT a,b:
 FOR i=1 TO 62:
 LET z=CODE "!2j+qX=0-ol_D?ZB]HT\@[QAKOF/.nmVMYPG>^ULC9876fedcka4,ph;1:bg5!"(i)-32+(a*9+b)*(a*b>0)*(b<9):
 BEEP .01,i:
 FOR j=0 TO 9*(t(z)=0)-1:
 LET d=j+INT (j/3)*6-10:
 LET w=z+d:
 POKE (t(w)<>3-p)*n,32:
 LET w=w+d:
 POKE (t(w)<>p)*n,26:
 LET w=w-d:
 LET t(w)=p:
 POKE (w<>z)*n,29:
 NEXT j:
 POKE n,4+15*(2*(i*q<62)-(z>1=i))*(t(z)*j=0):
 NEXT i

About the game

This one-liner implements the popular board game Othello with support for matches between 2 human players or against the computer. The number of human players is selected by answering the initial INPUT prompt 1-2?

During the course of the game, the players alternate turns to place a piece onto an empty square on the board, with the human player always moving first. The most recent move taken by either player is highlighted in a lighter colour than usual, so it is easy to stay aware of the last move made. Human player is blue (last move appears in cyan), CPU (or second player) is red (last move appears in magenta).

How to play

At your turn, you must select an empty square to place a piece onto by inputting a pair of numbers for ROW and COLUMN respectively. A move is valid if your placed piece is immediately adjacent to a contiguous block of one or more opponent's pieces, with another one of your pieces already situated at the other end of a straight line, so that two of your pieces "bridge over" the opponent pieces. On taking your move, all of the opponent's pieces that you have "bridged over" will flip over, changing into your colour. However, if your selected move is invalid (i.e. no pieces could be flipped), then you will be returned to the INPUT prompt, so you can try again another move without wasting your turn.

If there are no valid moves available for you to play, simply enter your move as 0 (for both ROW and COLUMN) to request a PASS. In this case, the computer will scan the board to confirm that you really don't have any valid move before accepting your PASS. However, if you attempt a PASS when there are still valid moves available, then the computer will interpret it as a request for HELP, and choose the best move it can find on your behalf.

The match is finished when one of the following end game conditions is met:-
(1) A player has had all of his pieces eliminated from the board (he loses the game);
(2) The board is completely full (the player with the highest number of pieces on the board at this point wins the game); or
(3) Neither player has a valid move remaining (again, highest number of pieces wins).

Technical Details

The design of this game features some very clever concepts from Einar Saukas. The CPU AI is compressed down to a single string of 60 characters length, which lists the desired positions to hold on the board, in order of decreasing tactical importance. This seems at first sight to be quite simple, but in fact has proven able to beat the AI of all three other Othello games (two of them commercial releases) tested against it. Another clever part is the algorithm to both validate and execute player moves, which was whittled down into a compact sequence of logical tests and conditional jumps, aided by the fact that the underlying board data structure is a folded one-dimensional numeric array.

Credits

Einar had this idea to implement an OTHELLO game in a one-liner, as he had previously developed an Othello game along with Eduardo Ito back in 1989 (published by ZX-SOFT Brasil Ltda). Einar was responsible for the top-level design of the game (explained above), and jointly implemented and optimized it along with Dr BEEP and Digital Prawn.

Back to documentation index