Beispiel #1
0
    //when this coroutine ends, the ai's turn is over
    public IEnumerator AITurn()
    {
        yield return(null);

        yield return(new WaitForSeconds(0.5f));

        while (turnManager.MovesThisTurn < turnManager.MovesPerTurn)
        {
            Constituent.Party currentParty  = turnManager.GetPartyforPlayer(turnManager.CurrentPlayer);
            Constituent.Party opponentParty = turnManager.GetPartyforPlayer(turnManager.NextPlayer);


            MoveManager.Move move;

            //first, try to convert neutral districts
            if (!TacticConvertNeutral(out move))
            {
                //if we're here, there are no neutral districts. if we're losing, convert enemy districts, otherwise try to consolidate the opponent
                int ourScore      = cityGenerator.Districts.Count((c) => c.CurrentMajority == currentParty);
                int opponentScore = cityGenerator.Districts.Count((c) => c.CurrentMajority == opponentParty);

                if (ourScore <= opponentScore + 1)
                {
                    TacticConvertWeakOpponents(out move);
                }
                else
                {
                    if (Utils.Chance(0.5f))
                    {
                        if (TacticConsolidateOpponent(out move))
                        {
                        }
                        else if (TacticDeconsolidateUs(out move))
                        {
                        }
                    }
                    else
                    {
                        if (TacticDeconsolidateUs(out move))
                        {
                        }
                        else if (TacticConsolidateOpponent(out move))
                        {
                        }
                    }
                }
            }

            //if we actually found a beneficial move
            if (move.constituent != null)
            {
                moveManager.MoveConstituent(move.constituent, move.newDistrict);
            }
            else
            {
                break;
            }
            yield return(new WaitForSeconds(0.5f));
        }
    }