private void Awake()
    {
        if (gc == null)
        {
            gc = this;
        }
        else if (gc != this)
        {
            Destroy(gameObject);
        }

        cv = GetComponent <ConditionVerifier>();

        if (PlayerPrefs.HasKey("Victory"))
        {
            Victory = PlayerPrefs.GetInt("Victory");
        }
        if (PlayerPrefs.HasKey("Loses"))
        {
            Lose = PlayerPrefs.GetInt("Loses");
        }
        if (PlayerPrefs.HasKey("Draw"))
        {
            Draw = PlayerPrefs.GetInt("Draw");
        }
    }
Beispiel #2
0
    public void AIDecision()
    {
        cv     = GetComponent <ConditionVerifier>();
        placed = false;
        List <PotentialPieces> potentialPieces       = new List <PotentialPieces>();
        List <PotentialPieces> playerVictoryNextTurn = new List <PotentialPieces>();
        List <PotentialPieces> AIPieces = new List <PotentialPieces>();

        potentialPieces.Clear();
        playerVictoryNextTurn.Clear();
        AIPieces.Clear();

        // Verify All Player Pieces and possibilities
        FillPossibilities(true, -3, potentialPieces);

        // If the player can win in the next turn use this
        FillPossibilities(true, -4, playerVictoryNextTurn);

        // If the AI can win in this turn use this as priority
        FillPossibilities(false, 4, AIPieces);

        if (AIPieces.Count > 0)
        {
            PlacePiece(AIPieces);
        }
        else
        {
            if (potentialPieces.Count > 0)
            {
                if (playerVictoryNextTurn.Count > 0)
                {
                    PlacePiece(playerVictoryNextTurn);
                }
                else
                {
                    PlacePiece(potentialPieces);
                }
            }
            else
            {
                while (!placed)
                {
                    GameObject[] sl;

                    if (GameController.gc.PlayerPiece == 0)
                    {
                        sl = GameObject.FindGameObjectsWithTag("OPiece");
                    }
                    else
                    {
                        sl = GameObject.FindGameObjectsWithTag("XPiece");
                    }

                    if (sl.Length > 0)
                    {
                        PutPiece(sl);
                    }
                    else
                    {
                        BroadcastMessage("AIPiecePlace", Random.Range(1, 225));
                    }
                }
            }
        }
    }