Classic Computer Magazine Archive COMPUTE! ISSUE 90 / NOVEMBER 1987 / PAGE 75

The Inscrutable Sphinx

Brain Flynn

This colorful puzzle game for the PC/PCjr and compatibles conjures up the mystery of ancient Egypt. In "The Inscrutable Sphinx," you pit your strategic powers against either the computer or a human opponent. A color/graphics adapter or equivalent hardware is required along with BASICA for the PC, GW-BASIC for compatibles, or Cartridge BASIC for the PCjr.


Near the ancient pyramids of Giza, not far from the river Nile, sits the inscrutable Egyptian Sphinx. Part man and part lion, this colossus has intrigued archeologists for ages. The mighty Sphinx is nearly 5000 years old, but its exact purpose seems buried forever in the sands of time.

This much we do know: The man-lion was carved out of a single sandstone knoll. It is four-fifths the length of a football field, measures 66 feet at its highest point, and is roughly 14 feet at its widest point. The Sphinx's headdress with Cobra was a sign of royalty, and its face was thought to resemble the features of Kephren, son of the great Pharaoh Cheops.

Whatever its original purpose, the ancient Sphinx reappears in all its regal splendor in this beguiling board game of wits. Indeed, you'll think you're on the Giza Plateau as you and your opponent (human or computer) alternately place Sphinxes and pyramids on the board.

The next few paragraphs will explain the rules of "The Inscrutable Sphinx." We'll see how the PC searches for an optimal move, and how to fine tune the program to take advantage of some of the features available on more recent PCs.

How To Play

The intellectual action in this game of thought takes place on a 7×7 board (see figure on following page). Your goal is to line up four Sphinxes in a row, in any direction, before the computer lines up four of its pyramids. To make a move, use the arrow keys to slide a Sphinx along the top edge of the board, then press ENTER or RETURN. The Sphinx will fall to the bottom of the column. The computer moves similarly.

You can go first, if you'd like, but it may not do you any good: The computer is very clever. You'll have to think ahead to win. And if you blunder badly, be warned that the PC will mercilessly exploit your mistake.

Finally, the game ends in a draw if you and the computer fill the board without success.

Enhancements

IBM PC-compatible computers come in all shapes and sizes. To take advantage of some of the enhanced features on the newer models, a few key variables appear at the beginning of the program:

110 ‘ CLEAR ,,,32768!	: ‘PC jr Mode (SCREEN 5)
120 ‘ PLAY "V8"		: ‘VOLUME (0 to 15)
130 PLAY "MB"		: ‘MUSIC BACK GROUND

Line 110: Eliminate the first tic mark or REM symbol to reserve enough RAM for Screen 5 graphics. This mode makes your game more colorful. If your computer doesn't support Screen 5, you'll get a syntax error upon striking the tic mark.

Line 120: Eliminate the first tic mark to set the level of sound to medium (V8), and change the volume to any value you'd like, using a scale of 0–15. Earlier versions of Microsoft BASIC do not support this parameter.

Line 130: If your machine locks up when it tries to play music while executing additional program lines, insert a tic mark at the beginning of this line.

Program Notes

After you've placed a Sphinx, the computer searches the board for a good move using these steps:

First, it finds the last empty square in each column.

Second, it evaluates that square from the point of view of both itself and the human player. It tallies a score based on the number of like markers in a row, assuming there are blank squares at each end of the sequence.

Third, it chooses as a next move that square with the highest number of points.

More concisely, to use the language of Artificial Intelligence, the computer applies an evaluation function to each possible move, and makes what it reasons to be an optimal selection. Here are the details.

The computer uses a special version of the board to facilitate its search for a good move:

123456789
1011121314151618
192021222324252627
282930313233343536
373839404142434445
464748495051525254
555657585960616263
646566676869707172
737475767778798081

The center box (with corners 11, 17, 65, and 71) is the playing surface. Each of these middle 49 squares takes on one of three values throughout the game: 0 = blank, 1 = computer, 2 = human. Each square in the outer border, on the other hand, always holds a value of—9. This tags the square as an off-the-board position.

The rules are simple, but the strategy can be complex in "The Inscrutable Sphinx."

Two subroutines constitute the search procedure: lines 2510–2700 and lines 2760–2900. In the first subroutine, the PC finds the last empty square (SQ.END) in each of seven columns (2 through 8). For each SQ.END, or possible move, the PC generates a score for itself (J = 1) and for its opponent (J = 2). The computer wants to play aggressively while blocking good opportunities for the human. Whichever score is higher (human or computer) becomes the rank for that square (lines 2600 and 2620). The square's rank, in turn, is compared to the previous highest rank (lines 2630–2650), and a new best value is chosen, if appropriate.

The PC tallies a score for each square in the second subroutine, using these steps:

First, for each of four directions (horizontal, upward slant, vertical, and downward slant), the PC counts the number of like markers in a row.

Second, it determines whether or not the squares at each end of the sequence are blank (lines 2830 and 2870).

Third, it ranks the square according to the evaluation function in line 2880. The variable T represents the number of markers in a row, not counting the marker to be laid down. The binary variables F1 and S1 equal one for blank end squares, and zero otherwise. Notice that T>2 (win on next move) gives a score of at least 1000.