Example #1
0
    public void makeMove()
    {
        if (currentTries >= maxTriesTilGiveUp)
        {
            Debug.LogError("i give up");
            gaveUp = true;
        }
        if (gaveUp)
        {
            return;
        }
        Vector2 gridPos = getGridPos();

        if (gridPos == new Vector2(999, 999))
        {
            return;
        }
        GameObject     gridObj      = grid.gridTiles[System.Array.IndexOf(grid.gridPositions, gridPos)];
        clickDetection gridPosClick = gridObj.GetComponent <clickDetection>();

        if (gridPosClick.isAnO || gridPosClick.isAnX)
        {
            if (!gaveUp)
            {
                Debug.Log("try again, dipshit");
                currentTries += 1;
                makeMove();
            }
        }
        else
        {
            grid.gridTiles[System.Array.IndexOf(grid.gridPositions, gridPos)].GetComponent <clickDetection>().placeO();
        }
    }
Example #2
0
    public void makeRandomMove()
    {
        clickDetection randomPosClick = grid.gridTiles[Random.Range(0, grid.gridTiles.Length - 1)].GetComponent <clickDetection>();

        if (randomPosClick.isAnO || randomPosClick.isAnX)
        {
            makeRandomMove();
            return;
        }
        else
        {
            randomPosClick.placeO();
        }
    }
Example #3
0
    public void makeHardMove()
    {
        int            oppositeIndexNumber = (grid.gridPositions.Length - 1) - grid.lastXPlaced.GetComponent <clickDetection>().indexInArray;
        clickDetection hardDecision        = grid.gridTiles[oppositeIndexNumber].GetComponent <clickDetection>();

        if (hardDecision.isAnO || hardDecision.isAnX)
        {
            makeRandomMove();
            return;
        }
        else
        {
            hardDecision.placeO();
        }
    }
Example #4
0
 public void initiateGrid(int sizeOfGrid)
 {
     for (int x = 0; x < sizeOfGrid; x++)
     {
         for (int y = 0; y < sizeOfGrid; y++)
         {
             int arrayIndex = sizeOfGrid * x + y;
             gridPositions[arrayIndex]  = new Vector2(x, y);
             worldPositions[arrayIndex] = new Vector2(x + x * gridSpacing, y + y * gridSpacing);
             GameObject newClickDetector = Instantiate(ClickDetector, worldPositions[arrayIndex], Quaternion.identity, transform);
             newClickDetector.name = arrayIndex.ToString();
             gridTiles[arrayIndex] = newClickDetector;
             clickDetection M_clickDetection = newClickDetector.GetComponent <clickDetection>();
             M_clickDetection.indexInArray       = arrayIndex;
             M_clickDetection.tilePositionToGrid = gridPositions[arrayIndex];
         }
     }
 }