Game Development Reference
In-Depth Information
Topics Covered In This Chapter:
— Artificial Intelligence
— List References
— Short-Circuit Evaluation
— The None Value
We will now create a Tic Tac Toe game where the player plays against a simple artificial
intelligence. An artificial intelligence (or AI ) is a computer program that can
intelligently respond to the player's moves. This game doesn't introduce any complicated
new concepts. We will see that the artificial intelligence that plays Tic Tac Toe is really just
a few lines of code.
Tic Tac Toe is a simple game to play with a paper and pencil between two people. One
player is X and the other player is O. On a simple nine square grid (which we call the
board), the players take turns placing their X or O o)n the board. If a player gets three of
their marks on the board in a row, column or one of the two diagonals, they win.
Most games of Tic Tac Toe end in a draw which happens when the board is filled up
with neither player having three marks in a row. Instead of second player, our artificial
intelligence will make moves against the user. You can learn more about Tic Tac Toe from
Wikipedia: http://en.wikipedia.org/wiki/Tic-tac-toe
While this chapter may not introduce many new programming concepts, it does make
use of our existing programming knowledge to make an intelligent Tic Tac Toe player.
Let's get started by looking at a sample run of the program.
Search WWH ::




Custom Search