Time for action – begin at the end
There's no shame in starting simple. Let's start writing these functions from the bottom up, until we reach the most complex ones at the top.
The GetRandomEmptySquare()
function does what our stupidest possible computer player does: finds any empty square and marks it with no thought to strategy. We can just reuse code we've already written:
function GetRandomEmptySquare():GameObject { var square:GameObject var aEmptySquares:List.<GameObject> = new List.<GameObject>(); for(var i:int = 0; i < aSquares.Length; i++) { square = aSquares[i]; if(square.GetComponent.<Square>().player == 0) aEmptySquares.Add(square); } square = aEmptySquares[Random.Range(0,aEmptySquares.Count)]; return square; }
Note
This will be our fall-through code. If all else fails and none of the other functions manage to return a square, we can count on this line to just grab an empty space in the grid.
The GetEmptySide
function needs to...