예제 #1
0
        public void Integration_CamelRunner_Valid()
        {
            var runner = new CamelRunner(seed: 1);

            runner.AddPlayer(new RandomBot(1, seed: 2));
            runner.AddPlayer(new RandomBot(2, seed: 3));
            var game    = runner.ComputeSeededGame(1, 2, 3);
            var players = runner.GetPlayers();

            var gameState = game.GameState;

            Assert.AreEqual(87, runner.Step, "game step");

            Assert.AreEqual(1, game.StartingPlayer, "starting player");
            Assert.AreEqual(1, game.CurrentPlayer, "current player");
            Assert.AreEqual(5, gameState.Round, "round");

            Assert.AreEqual(29, gameState.Money[0], "player 0 money");
            Assert.AreEqual(24, gameState.Money[1], "player 1 money");

            Assert.AreEqual(1, players[0].Wins, "player 0 wins");
            Assert.AreEqual(0, players[1].Wins, "player 1 wins");

            Assert.AreEqual("16,4 12,0 13,1 16,3 13,2", gameState.CamelPositionToString(), "camel positions");
        }
예제 #2
0
        private static void RunBenchmark(string[] args)
        {
            var runner = new CamelRunner(timeScalingFactor: TimeScalingFactor);

            runner.AddPlayer(new DiceThrower());
            runner.AddPlayer(new IllegalBot());
            runner.AddPlayer(new RandomBot());

            var history = runner.GetPlayers().ToDictionary(x => x, x => new List <TimeSpan>());

            for (var i = 0; i < 250; i++)
            {
                runner.ComputeNewGame();
                Console.WriteLine($"Game #{i} finished");

                foreach (var player in runner.GetPlayers())
                {
                    history[player].Add(player.ComputationTime);
                }
            }

            runner.Save();

            var players = runner.GetPlayers();

            var title = "Player";

            Console.WriteLine($"{title,-32} Wins");
            foreach (var player in players.OrderByDescending(x => x.Wins))
            {
                var avgTime = history[player].Average(x => x.TotalSeconds);
                Console.WriteLine($"{player.Name,-32} {player.Wins, -6} {avgTime:0.000}s");
            }
        }
예제 #3
0
        public void Integration_CamelRunner_Step_0()
        {
            var runner = new CamelRunner(seed: 1);

            runner.AddPlayer(new RandomBot(1, seed: 2));
            runner.AddPlayer(new RandomBot(2, seed: 3));
            var game      = runner.ComputeNewGame(steps: 0);
            var players   = runner.GetPlayers();
            var gameState = game.GameState;

            Assert.AreEqual(2, runner.GetPlayers().Count(), "players");
            Assert.AreEqual(16, gameState.BoardSize, "board");
            Assert.AreEqual(5, gameState.Camels.Count, "camels");

            Assert.AreEqual("0,0 0,1 1,2 1,3 1,4", gameState.CamelPositionToString(), "Camel positions");

            var camelOrder = gameState.GetLeadingOrder();

            Assert.AreEqual(CamelColor.Yellow, camelOrder.Skip(0).First(), "camel 0");
            Assert.AreEqual(CamelColor.Red, camelOrder.Skip(1).First(), "camel 1");
            Assert.AreEqual(CamelColor.Green, camelOrder.Skip(2).First(), "camel 2");
            Assert.AreEqual(CamelColor.White, camelOrder.Skip(3).First(), "camel 3");
            Assert.AreEqual(CamelColor.Blue, camelOrder.Skip(4).First(), "camel 4");

            Assert.AreEqual(0, game.StartingPlayer, "starting player");
            Assert.AreEqual(0, game.CurrentPlayer, "current player");

            Assert.AreEqual(3, gameState.Money[0], "player 0 money");
            Assert.AreEqual(3, gameState.Money[1], "player 1 money");

            Assert.AreEqual(1, players[0].Wins, "player 0 wins");
            Assert.AreEqual(1, players[1].Wins, "player 1 wins");
        }
예제 #4
0
        public CamelService(Guid?cupId = null, bool ignoreTime = false, int totalGames = 1000)
        {
            TotalGames = totalGames;
            CupId      = cupId ?? Guid.NewGuid();
            var seed = CupId.GetHashCode();

            Runner        = new CamelRunner(seed: seed, timeScalingFactor: ignoreTime ? 1000 : 1);
            GameIdHistory = new List <Guid>();
        }
예제 #5
0
        public void Interface_Call_Save()
        {
            var bot = GetTestBot();

            var runner = new CamelRunner(seed: 1);

            runner.AddPlayer(new RandomBot(1, seed: 2));
            runner.AddPlayer(bot);

            runner.ComputeNewGame(steps: 0);
            runner.Save();

            Assert.AreEqual(1, bot.CalledSave, "save");
        }
예제 #6
0
        public void Integration_Determination_9()
        {
            var runner = new CamelRunner();

            runner.AddPlayer(new RandomBot());
            runner.AddPlayer(new RandomBot());

            for (int i = 0; i < 3; i++)
            {
                var game = runner.ComputeSeededGame(startPosSeed: 1412629303, playerOrderSeed: 1986369960, gameSeed: 1248783280);

                Assert.AreEqual("30 44", game.GameState.MoneyToString(), "player money");
                Assert.AreEqual("5,0 14,3 12,1 16,4 14,2", game.GameState.CamelPositionToString(), "camel positions");
            }
        }
예제 #7
0
        public void Integration_Determination_7()
        {
            var runner = new CamelRunner();

            runner.AddPlayer(new RandomBot());
            runner.AddPlayer(new RandomBot());
            runner.AddPlayer(new RandomBot());

            for (int i = 0; i < 3; i++)
            {
                var game = runner.ComputeSeededGame(startPosSeed: 997538913, playerOrderSeed: 1893693153, gameSeed: 1620525773);

                Assert.AreEqual("19 23 25", game.GameState.MoneyToString(), "player money");
                Assert.AreEqual("12,2 11,1 15,3 6,0 16,4", game.GameState.CamelPositionToString(), "camel positions");
            }
        }
예제 #8
0
        public void Integration_Determination_6()
        {
            var runner = new CamelRunner();

            runner.AddPlayer(new RandomBot());
            runner.AddPlayer(new RandomBot());
            runner.AddPlayer(new RandomBot());

            for (int i = 0; i < 3; i++)
            {
                var game = runner.ComputeSeededGame(startPosSeed: 169572456, playerOrderSeed: 1271470828, gameSeed: 677344959);

                Assert.AreEqual("11 23 20", game.GameState.MoneyToString(), "player money");
                Assert.AreEqual("13,0 16,2 16,4 13,1 16,3", game.GameState.CamelPositionToString(), "camel positions");
            }
        }
예제 #9
0
        public void Integration_Determination_5()
        {
            var runner = new CamelRunner();

            runner.AddPlayer(new RandomBot());
            runner.AddPlayer(new SmartMartinPlayer());
            runner.AddPlayer(new DiceThrower());
            runner.AddPlayer(new IllegalBot());

            for (int i = 0; i < 2; i++)
            {
                var game = runner.ComputeSeededGame(startPosSeed: 1989079677, playerOrderSeed: 1448447844, gameSeed: 2101643186);

                Assert.AreEqual("33 18 15 23", game.GameState.MoneyToString(), "player money");
                Assert.AreEqual("17,4 14,1 11,0 14,3 14,2", game.GameState.CamelPositionToString(), "camel positions");
            }
        }
예제 #10
0
        public void Integration_Determination_4()
        {
            var runner = new CamelRunner();

            runner.AddPlayer(new RandomBot());
            runner.AddPlayer(new SmartMartinPlayer());
            runner.AddPlayer(new DiceThrower());
            runner.AddPlayer(new IllegalBot());

            for (int i = 0; i < 2; i++)
            {
                var game = runner.ComputeSeededGame(startPosSeed: 462229339, playerOrderSeed: 1329827054, gameSeed: 1471678946);

                Assert.AreEqual("41 0 21 29", game.GameState.MoneyToString(), "player money");
                Assert.AreEqual("10,1 17,4 13,3 13,2 10,0", game.GameState.CamelPositionToString(), "camel positions");
            }
        }
예제 #11
0
        public void Integration_Determination_10()
        {
            var runner = new CamelRunner();

            runner.AddPlayer(new RandomBot());
            runner.AddPlayer(new DiceThrower());
            runner.AddPlayer(new HeatmapMinus());
            runner.AddPlayer(new HeatmapPluss());

            for (int i = 0; i < 3; i++)
            {
                var game = runner.ComputeSeededGame(startPosSeed: 1349774550, playerOrderSeed: 673427446, gameSeed: 67328921);

                Assert.AreEqual("11 10 12 11", game.GameState.MoneyToString(), "player money");
                Assert.AreEqual("16,4 9,0 14,1 16,3 14,2", game.GameState.CamelPositionToString(), "camel positions");
            }
        }
예제 #12
0
        public void Integration_Determination_1()
        {
            var runner = new CamelRunner();

            runner.AddPlayer(new RandomBot());
            runner.AddPlayer(new SmartMartinPlayer());
            runner.AddPlayer(new DiceThrower());

            for (int i = 0; i < 2; i++)
            {
                var game = runner.ComputeSeededGame(startPosSeed: 1159066037, playerOrderSeed: 1561971233, gameSeed: 778305510);

                Assert.AreEqual("97089d38-319b-5841-5671-da55998a82d2", game.GameId.ToString(), "game id");
                Assert.AreEqual("34 3 17", game.GameState.MoneyToString(), "player money");
                Assert.AreEqual("18,4 11,0 11,1 18,3 18,2", game.GameState.CamelPositionToString(), "camel positions");
            }
        }
예제 #13
0
        public void Integration_Determination_3()
        {
            var runner = new CamelRunner();

            runner.AddPlayer(new RandomBot());
            runner.AddPlayer(new SmartMartinPlayer());
            runner.AddPlayer(new DiceThrower());
            runner.AddPlayer(new IllegalBot());

            for (int i = 0; i < 2; i++)
            {
                var game = runner.ComputeSeededGame(startPosSeed: 1756550859, playerOrderSeed: 1594470206, gameSeed: 825977671);

                Assert.AreEqual("a4142202-c7b4-de85-7f63-e71282ec28dc", game.GameId.ToString(), "game id");
                Assert.AreEqual("38 0 19 4", game.GameState.MoneyToString(), "player money");
                Assert.AreEqual("10,0 15,3 10,1 13,2 16,4", game.GameState.CamelPositionToString(), "camel positions");
            }
        }
예제 #14
0
        public void Integration_Determination_2()
        {
            var runner = new CamelRunner();

            runner.AddPlayer(new RandomBot());
            runner.AddPlayer(new SmartMartinPlayer());
            runner.AddPlayer(new DiceThrower());
            runner.AddPlayer(new IllegalBot());

            for (int i = 0; i < 2; i++)
            {
                var game = runner.ComputeSeededGame(startPosSeed: 648398875, playerOrderSeed: 1276980857, gameSeed: 701934574);

                Assert.AreEqual("f5ec7765-86da-5cae-15d2-4f7add46ea6f", game.GameId.ToString(), "game id");
                Assert.AreEqual("4 19 31 40", game.GameState.MoneyToString(), "player money");
                Assert.AreEqual("9,1 14,2 9,0 16,4 15,3", game.GameState.CamelPositionToString(), "camel positions");
            }
        }
예제 #15
0
        public void Integration_Determination_8()
        {
            var runner = new CamelRunner();

            runner.AddPlayer(new IllegalBot());
            runner.AddPlayer(new IllegalBot());
            runner.AddPlayer(new IllegalBot());
            runner.AddPlayer(new IllegalBot());
            runner.AddPlayer(new IllegalBot());

            for (int i = 0; i < 3; i++)
            {
                var game = runner.ComputeSeededGame(startPosSeed: 713137502, playerOrderSeed: 791917098, gameSeed: 1673969849);

                Assert.AreEqual("0 0 25 0 0", game.GameState.MoneyToString(), "player money");
                Assert.AreEqual("8,0 13,4 11,2 11,1 11,3", game.GameState.CamelPositionToString(), "camel positions");
            }
        }
예제 #16
0
        public void Interface_Call_Twice()
        {
            var bot = GetTestBot();

            var runner = new CamelRunner(seed: 1);

            runner.AddPlayer(new RandomBot(1, seed: 2));
            runner.AddPlayer(bot);

            var game = runner.ComputeNewGame(steps: 2);

            Assert.AreEqual(1, bot.CalledPlayerName, "player name");
            Assert.AreEqual(1, bot.CalledLoad, "load");
            Assert.AreEqual(1, bot.CalledStart, "start");
            Assert.AreEqual(1, bot.CalledAction, "action");
            Assert.AreEqual(2, bot.CalledInform, "inform");

            Assert.AreEqual(0, bot.CalledSave, "save");
            Assert.AreEqual(0, bot.CalledWinners, "winners");
        }
예제 #17
0
        public void Integration_CamelRunner_Step_50()
        {
            var runner = new CamelRunner(seed: 1);

            runner.AddPlayer(new RandomBot(1, seed: 2));
            runner.AddPlayer(new RandomBot(2, seed: 3));
            var game    = runner.ComputeSeededGame(1, 2, 3, steps: 50);
            var players = runner.GetPlayers();

            var gameState = game.GameState;

            Assert.AreEqual(1, game.StartingPlayer, "starting player");
            Assert.AreEqual(0, game.CurrentPlayer, "current player");
            Assert.AreEqual(3, gameState.Round, "round");

            Assert.AreEqual(19, gameState.Money[0], "player 0 money");
            Assert.AreEqual(14, gameState.Money[1], "player 1 money");

            Assert.AreEqual(1, players[0].Wins, "player 0 wins");
            Assert.AreEqual(0, players[1].Wins, "player 1 wins");

            Assert.AreEqual("10,3 10,1 10,2 10,4 6,0", gameState.CamelPositionToString(), "camel positions");
        }
예제 #18
0
        public void Interface_Call_OnceReverse()
        {
            var bot = GetTestBot();

            var runner = new CamelRunner(seed: 2);

            runner.AddPlayer(new RandomBot(1, seed: 2));
            runner.AddPlayer(bot);

            var game = runner.ComputeSeededGame(1, 3, 3, steps: 1);

            Assert.AreEqual("RandomBot #1", bot.GameInfo.Players[0], "name");
            Assert.AreEqual("TestBot", bot.GameInfo.Players[1], "name");

            Assert.AreEqual(1, bot.PlayerNum, "testbot order");
            Assert.AreEqual(1, bot.CalledPlayerName, "player name");
            Assert.AreEqual(1, bot.CalledLoad, "load");
            Assert.AreEqual(1, bot.CalledStart, "start");
            Assert.AreEqual(1, bot.CalledInform, "inform");

            Assert.AreEqual(0, bot.CalledAction, "action");
            Assert.AreEqual(0, bot.CalledSave, "save");
            Assert.AreEqual(0, bot.CalledWinners, "winners");
        }