Making computer play

Playing Connect Four against yourself is not the best gaming experience ever. What about making CPU play against you?

The idea: At the very beginning, the computer will randomly choose a move among the possible columns and place the disc, without caring whether it is a good move or not. This will help us to focus on the other things to fix to let the computer play. Obviously, when the computer plays, the player cannot place discs, so we have to remove some listeners when it's player two's turn.

The development: The first thing to change is onAdded function, because we want the player to take control over the disc only when it's player one's turn.

Rewrite the function this way:

private function onAdded(e:Event) { par=this.parent.parent ...

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.