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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Flash</strong> <strong>MX</strong> <strong>2004</strong> <strong>Games</strong><br />

The function can operate either on the ‘board’ array if the value for ‘piece’ is COMPUTER, or<br />

the ‘cBoard’ array if the value for ‘piece’ is PLAYER. Again when scanning a row the first square<br />

must be empty, the next must contain an opponent piece and the final must be a player piece. If<br />

all the conditions are passed then true is returned; otherwise false is returned.<br />

1 function scanArray(i, piece, incX, incY){<br />

2<br />

3<br />

var name, n, inc;<br />

4 inc = incY*8 + incX;<br />

5<br />

6<br />

n = i + inc;<br />

7 //Must be at least one<br />

8 switch (piece){<br />

9 case PLAYER:<br />

10 if (cBoard[i]!=1 || cBoard[n]!=COMPUTER) return false;<br />

11 do{<br />

12 n += inc;<br />

13 }while(cBoard[n] == COMPUTER);<br />

14 //Next piece must be a PLAYER piece<br />

15 if (cBoard[n] == PLAYER) return true;<br />

16<br />

17<br />

break;<br />

18 case COMPUTER:<br />

19 if (board[i]!=1 || board[n]!=PLAYER) return false;<br />

20 do{<br />

21 n += inc;<br />

22 }while(board[n] == PLAYER);<br />

23 //Next piece must be a COMPUTER piece<br />

24 if (board[n] == COMPUTER) return true;<br />

25 break;<br />

26<br />

27<br />

}<br />

28 return false;<br />

29 }<br />

Listing 16.12<br />

Once the best computer score is evaluated the function ‘adjustArray’ is called:<br />

1 function adjustArray(i, piece){<br />

2 if (flip[0]) flipArrayLine(i, piece, 1, 0);<br />

3 if (flip[1]) flipArrayLine(i, piece, 0, 1);<br />

4 if (flip[2]) flipArrayLine(i, piece, -1, 0);<br />

5 if (flip[3]) flipArrayLine(i, piece, 0, -1);<br />

6 if (flip[4]) flipArrayLine(i, piece, -1, -1);<br />

7 if (flip[5]) flipArrayLine(i, piece, 1, -1);<br />

256

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

Saved successfully!

Ooh no, something went wrong!