Tiny BASIC

Interpreter and Compiler Project

Tic-tac-toe

Tic-tac-toe is the famous children's pencil-and-paper game, where the object is to form a line of three of your symbol (X or O) on a 3x3 grid before the opponent does the same. It's descended from the board game of Three Men's Morris, which had a similar aim but limited the players to three pieces each which, once placed, could be moved around the board.

This sample game allows the player to compete against the computer. The player gets to decide whether to play first or second, after which player and computer take it in turns to place a marker. The player moves by inputting a square number; the layout of the squares is printed when the game starts. The computer then makes its move by saying which square it placed its marker in. Due to the limitations of Tiny BASIC it's up to the player to remember what squares contain what markers. Playing by memory might add some interest to the game.

Most adults know that, once the strategy is learnt, either player can force the game into a draw. This is generally when people move on to more advanced games. The computer in this implementation is not perfect. Usually it can exploit a player's mistake to win the game, or at least play well enough to force a draw. There is one counter-intuitive strategy that can beat it, however.

The computer plays heuristically, that is, by following a set of "how to try to win" steps, and does not learn from one game to the next. That is the main interest of this program; its simplistic artificial intelligence is one of the things that makes it the largest of the example programs. Another is the way in which the program deals with the lack of arrays. Unlike Hunt the Wumpus this game mainly uses brute force to achieve that, mapping square numbers 1-9 onto the variables R-Z with a series of IF statements.

FIlename: tictactoe.bas.

Comments

New Comment

Yes No