AIsOfCatan.GameController.StartGame C# (CSharp) Méthode

StartGame() public méthode

Start the game. This method will run for the length of the game and returns the id of the winner
public StartGame ( IAgent agents, int boardSeed, int diceSeed, bool visual, bool logToFile ) : int
agents IAgent The competing agents (The order in which they are submitted is irrelevant)
boardSeed int The seed for the board generator, used to shuffle development cards, and for drawing a random card after moving the robber
diceSeed int The seed for the dice
visual bool True if the game should be displayed visually
logToFile bool
Résultat int
        public int StartGame(IAgent[] agents, int boardSeed, int diceSeed, bool visual, bool logToFile)
        {
            this.visual = visual;
            this.logToFile = logToFile;

            //Initialize random number generators
            diceRandom = new Random(diceSeed);
            shuffleRandom = new Random(boardSeed); //The card deck is based on the seed of the board

            //Build player list
            players = new Player[agents.Length];
            for (int i = 0; i < agents.Length; i++)
            {
                players[i] = new Player(agents[i], i);
            }

            //Set up board
            board = new Board(boardSeed);
            PopulateDevelopmentCardStack();
            resourceBank = new int[] { 19, 19, 19, 19, 19 };

            //Start the game!
            turn = 0;

            //StartGUI();
            if (visual)
            {
                Thread guiThread = new Thread(StartGUI);
                guiThread.Start();
                Thread.Sleep(5000);
            }

            PlaceStarts();
            int result = GameLoop();
            if (logToFile) System.IO.File.WriteAllLines(DateTime.Now.ToString("s").Replace(":","").Replace("-","")+" GameLog.txt", log.Select(l => l.ToString()));

            return result;
        }

Same methods

GameController::StartGame ( IAgent agents, int boardSeed, int diceSeed ) : int

Usage Example

Exemple #1
0
        static void PerformGameBenchmarking()
        {
            Dictionary<int, int> wins = new Dictionary<int, int>(4);

            for (int i = 0; i < 1000; i++)
            {
                var controller = new GameController();
                var agents = new IAgent[] { new StarterAgent(), new StarterAgent(), new StarterAgent() }; // new HumanAgent()
                int intWinner = controller.StartGame(agents, i, i, false, false);
                //var winner = agents[intWinner];

                if (wins.ContainsKey(intWinner))
                {
                    wins[intWinner] = wins[intWinner] + 1;
                }
                else
                {
                    wins.Add(intWinner, 1);
                }
                Console.WriteLine(i + ": P " + intWinner + " wins.");
            }

            Console.WriteLine();
            wins.OrderBy(w => w.Key).ForEach(kv => Console.WriteLine("Player " + kv.Key + ": " + kv.Value + " wins."));
        }
All Usage Examples Of AIsOfCatan.GameController::StartGame