02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 16: Board games<br />

Here ‘row’ is the integer value after dividing the index ‘best’ by 8, which will place ‘row’ between<br />

0 and 7. The value of ‘col’ is determined using the modulus opera<strong>to</strong>r ‘%’. This opera<strong>to</strong>r returns<br />

the remainder, after dividing the left of the opera<strong>to</strong>r by the right. Again this will return a value<br />

between 0 and 7. We update the ‘flip’ array by calling ‘legalMove’ again and set the current square<br />

directly, and it only then remains <strong>to</strong> update the on-screen display using the ‘adjustBoard’ function<br />

we looked at earlier.<br />

1 function doComputerMove(){<br />

2 var diff=-100000, c, p, i, row, col, best=-1, count=0, name;<br />

3<br />

4 //Get current board<br />

5 for (row=0; row

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!