Playing with AI: defensive play

While the creation of an algorithm to make the computer play perfectly is beyond the scope of this book, we'll see the basics of artificial intelligence making the CPU player at least trying not to let the human player win that easily.

The idea: When it's time to choose the column, don't pick it randomly among all possible columns, but among the columns that can give the highest number of connected discs if played by the opponent. Look at this picture:

Playing with AI: defensive play

The same board configuration, on the left the possible red moves with the number of possible yellow streaks. The third column from the left is the best move, as it ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.