Developing the Concept for an AI

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 ...

Get Learning Swift™ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.