Time for action – to catch a competitor
Combine these two separate function calls:
square = Win(); if(square == null) square = Block(); if(square == null) square = CreateTrap(); if(square == null) square = PreventTrap();
into this unified call:
square = Win();
if(square == null) square = Block();
if(square == null) square = PreventOrCreateTrap();
The PreventOrCreateTrap
function is very straightforward:
function PreventOrCreateTrap():GameObject { var aP1Corners:List.<GameObject> = new List.<GameObject>(); // Create an empty list to store X-controlled corners var aP2Corners:List.<GameObject> = new List.<GameObject>(); // Create an empty list to store O-controlled corners var aOpenCorners:List.<GameObject> = new List.<GameObject>(); // Create an empty list to store unoccupied corners var aCorners:GameObject[] = [aGrid[0,0],aGrid[2,0],aGrid[0,2], aGrid[2,2]]; // Create an array to store the corner coordinates ...