< Previous | Contents | Next >

Introducing the Tic-Tac-Toe Game

In this chapter project, youll learn how to create a computer opponent using a dash of AI (Artificial Intelligence). In the game, the player and computer square off in a high-stakes, man-versus-machine showdown of Tic-Tac-Toe. The computer plays a formidable (although not perfect) game and comes with enough attitude to make any match fun. Figure 6.5 shows the start of a match.


image

Figure 6.5

The computer is full of.. .confidence.


 

Planning the GameSetting Up the ProgramThe main() FunctionThe instructions() FunctionThe askYesNo() FunctionThe askNumber() FunctionThe humanPiece() FunctionThe opponent() FunctionThe displayBoard() FunctionThe winner() FunctionThe isLegal() FunctionThe humanMove() FunctionThe computerMove() FunctionThe announceWinner() Function