December 2014
Beginner
300 pages
8h 9m
English
The AI in this game involves more lines of code than any of the previous examples in this book. That’s because you’ve learned a lot about Swift, and you’re ready to put your knowledge to the test! Still, you might find it helpful to step back from the code and look at the big picture.
Even though tic-tac-toe is simple and well known, we’ll briefly summarize the game’s rules. A player makes a move by marking a tile with an X or an O. A player wins by covering three tiles in a row, in any direction, with his or her mark. In other words, a smart AI is one that covers three tiles before its human opponent. Specifically, there are five steps the algorithm must take, based on five things the computer player needs to ...
Read now
Unlock full access