Unleashing CPU power

Finally it's time for the computer to make its move. At the moment it will be a random move, so you just need to check for legal columns to move, and randomly choose one of them.

The idea: Choose a random column among the possible ones and place the disc.

The development: This is computerMove function, to be inserted in disc_movieclip.as:

private function computerMove():void {
var possibleMoves:Array=par.possibleColumns();
var cpuMove:uint=Math.floor(Math.random()*possibleMoves.length)
currentColumn=possibleMoves[cpuMove];
x=35+60*currentColumn;
currentRow=par.firstFreeRow(currentColumn,currentPlayer);
fallingDestination=35+currentRow*60;
}

Apart from computer decision, it works as if the player was human.

var possibleMoves:Array=par.possibleColumns(); ...

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.