AIsOfCatan.DebugAgent.PerformTurn C# (CSharp) Method

PerformTurn() public method

public PerformTurn ( IGameState state, IGameActions actions ) : void
state IGameState
actions IGameActions
return void
        public void PerformTurn(IGameState state, IGameActions actions)
        {
            if (!silent)
                Console.WriteLine(id + ": Performing main turn");
            var resources = ((GameState)state).GetOwnResources();
            int[] resCount = new int[5];
            foreach (var r in resources)
                resCount[(int)r]++;
            if (!silent)
                Console.Write(id + ": Resources: ( ");
            foreach (var i in resCount)
                if (!silent)
                    Console.Write(i + " ");
            if (!silent)
                Console.WriteLine(")");

            if (hasDevcardToPlay)
            {
                hasDevcardToPlay = false;
                if (!silent)
                    Console.WriteLine("-----------");
                if (!silent)
                    Console.WriteLine("Has a dev card to play: " + nextToPlay);
                switch (nextToPlay)
                {
                    case DevelopmentCard.Knight:
                        if (!silent)
                            Console.WriteLine("Play knight");
                        state = ((MainActions) actions).PlayKnight();
                        break;

                    case DevelopmentCard.Monopoly:
                        if (!silent)
                            Console.WriteLine("Play monopoly");
                        state = ((MainActions)actions).PlayMonopoly(Resource.Ore);
                        break;

                    case DevelopmentCard.RoadBuilding:
                        if (!silent)
                            Console.WriteLine("Play road building");
                        state = ((MainActions)actions).PlayRoadBuilding(new Edge(27,28), new Edge(28, 34));
                        break;

                    case DevelopmentCard.YearOfPlenty:
                        if (!silent)
                            Console.WriteLine("Play year of plenty");
                        state = ((MainActions)actions).PlayYearOfPlenty(Resource.Grain, Resource.Wool);
                        break;
                }
                if (!silent)
                    Console.WriteLine("-----------");
            }
            resources = ((GameState)state).GetOwnResources();

            if (resources.Contains(Resource.Grain) && resources.Contains(Resource.Ore) &&
                resources.Contains(Resource.Wool))
            {
                var prevCards = ((GameState) state).GetOwnDevelopmentCards();
                state = actions.DrawDevelopmentCard();
                if (!silent)
                    Console.WriteLine("Drawn developmentcard successfully");
                hasDevcardToPlay = true;
                var cards = ((GameState) state).GetOwnDevelopmentCards().ToList();
                foreach (var developmentCard in prevCards)
                {
                    cards.Remove(developmentCard);
                }
                nextToPlay = cards.ToArray()[0];
            }
            else
            {
                try
                {
                    actions.DrawDevelopmentCard();
                    if (!silent)
                        Console.WriteLine("WARNING! Was able to buy a development card with not enough resources");
                }
                catch (InsufficientResourcesException e)
                {
                    if (!silent)
                        Console.WriteLine("exceptions was thrown as excpected");
                }
            }
        }