Exemple #1
0
    private int [] GetBoardAsInts()
    {
        // The next two counters are used to keep track of how many of each piece are on the board.
        // We use this to work out which piece is playing next, so we know how to calculate the AI scoreboard.
        int xCount = 0;
        int oCount = 0;

        int [] cells;
        int    i = 0;

        cells = new int[BOARDDIMENSIONS];

        foreach (GridCellScript gcs in gridCells)
        {
            if (gcs.state == GridCellScript.CellStates.empty)
            {
                cells [i] = EMPTYCELL;
            }
            if (gcs.state == GridCellScript.CellStates.O)
            {
                cells [i] = O_CELL;
                ++oCount;
            }
            if (gcs.state == GridCellScript.CellStates.X)
            {
                cells [i] = X_CELL;
                ++xCount;
            }

            ++i;
        }

        // Work out which piece we need to recalculate board for: X or O...

        // Let's ask the GUIHandler script for the current player.
        // BUT!!!
        // We actually prepare the scores for the next player BEFORE
        // the GUIHandler calls "NextTurn()"!
        // So we swap the result -- if it's 'X', the next piece will be 'O', and vice-versa...

        pieceToPlayNext = (gHandler.GetCurrentPlayerPieceAsInt()) == X_CELL ? O_CELL : X_CELL;

        return(cells);
    }