Example #1
0
        public void Move_KillHeroAndGetMines_Hero1HasMine()
        {
            var map = MapTest.Map06;

            var mines = MineOwnership.Create(1, 1, 1, 4);
            var hero1 = new Hero(18, 3, 3, 3, 100);
            var hero2 = new Hero(80, 2, 3, 0, 101);
            var hero3 = new Hero(81, 4, 4, 0, 102);
            var hero4 = new Hero(82, 1, 5, 1, 103);

            var act0 = State.Create(16, hero1, hero2, hero3, hero4, mines);
            var exp0 = @"Hero[3,3] Health: 18, Mines: 3, Gold: 100
Hero[2,3] Health: 80, Mines: 0, Gold: 101
Hero[4,4] Health: 81, Mines: 0, Gold: 102
Hero[1,5] Health: 82, Mines: 1, Gold: 103
Turn: 16
Mines: 1114................";

            AreEqual(exp0, act0);

            var act1 = act0.Move(map, MoveDirection.E, PlayerType.Hero2);
            var exp1 = @"Hero[0,0] Health: 100, Mines: 0, Gold: 100
Hero[2,3] Health: 79, Mines: 3, Gold: 104
Hero[4,4] Health: 81, Mines: 0, Gold: 102
Hero[1,5] Health: 82, Mines: 1, Gold: 103
Turn: 17
Mines: 2224................";

            AreEqual(exp1, act1);
        }
Example #2
0
        public void Process_21ply_()
        {
            var map   = MapTest.Map18;
            var state = State.Create(1,
                                     Hero.Create(90, map[2, 3], 0, 0),
                                     Hero.Create(90, map[5, 6], 0, 0),
                                     Hero.Create(90, map[9, 9], 0, 0),
                                     Hero.Create(90, map[1, 9], 0, 0),
                                     MineOwnership.Create(map));

            var root = new RootNode(map, state);

            root.InitializeMoveMappings(map);

            var sw = new Stopwatch();

            sw.Start();
            for (int i = 1; i < 21; i++)
            {
                root.Process(map, i, PotentialScore.EmptyCollection);
            }
            sw.Stop();

            Console.WriteLine("Ellapsed: {0:0.0}", sw.Elapsed.TotalMilliseconds);

            Console.WriteLine(Node.Lookup.DebuggerDisplay);

            Console.WriteLine(Node.Lookup.LogNodeCounts());

            var act = root.BestMove;
            var exp = MoveDirection.S;

            Assert.AreEqual(exp, act);
        }
Example #3
0
        public void Move_TakeMineAndKillOpponent_MinesMatchesMinePerHero()
        {
            var map = MapTest.Map18;

            var hero1 = Hero.Create(100, map[04, 02], 0, 266);
            var hero2 = Hero.Create(008, map[02, 03], 1, 210);
            var hero3 = Hero.Create(001, map[14, 15], 2, 336);
            var hero4 = Hero.Create(001, map[04, 03], 5, 630);
            var mines = MineOwnership.Create(0, 0, 0, 0, 0, 4, 4, 0, 4, 4, 4, 0, 0, 0, 0, 0, 2, 3, 0, 3);
            var state = State.Create(789, hero1, hero2, hero3, hero4, mines);

            Console.WriteLine(state.ToUnitTestString());

            var source = map[4, 2];
            var target = map[4, 1];

            var act = state.Move(map, hero1, PlayerType.Hero1, source, target);
            var exp = @"Hero[4,2] Health: 79, Mines: 6, Gold: 272
Hero[2,3] Health: 8, Mines: 1, Gold: 210
Hero[14,15] Health: 1, Mines: 2, Gold: 336
Hero[14,2] Health: 100, Mines: 0, Gold: 630
Turn: 790
Mines: ..1..11.111.....23.3";

            AreEqual(exp, act);
        }
Example #4
0
        public void Process_MoveToFreeMineDistance1_GoNorth()
        {
            var map = Map.Parse(
                "@1[]  $-$-  []@2\r\n" +
                "                \r\n" +
                "                \r\n" +
                "                \r\n" +
                "                \r\n" +
                "                \r\n" +
                "                \r\n" +
                "@3[]  $-$-  []@4\r\n");

            var state = State.Create(0,
                                     Hero.Create(44, map[3, 1], 0, 6),
                                     Hero.Create(90, map[2, 6], 2, 4),
                                     Hero.Create(90, map[7, 0], 0, 0, true),
                                     Hero.Create(90, map[7, 7], 0, 0, true),
                                     MineOwnership.Create(0, 0, 2, 2));

            var root      = new RootNode(state);
            var evaluator = Evaluator.Get(map);
            var data      = new ProcessData(root.Lookup, map, evaluator);

            var act = root.GetMove(data, TimeSpan.FromSeconds(2));

            Console.WriteLine(root.Lookup.LogNodeCounts());
            var exp = MoveDirection.N;

            Assert.AreEqual(exp, act.Direction);
        }
        public void Process_Health50BesideATavern_1Paths()
        {
            var map   = MapTest.Map10Mines8;
            var state = State.Create(0,
                                     new Hero(50, 1, 0, 0, 0),
                                     new Hero(100, 8, 0, 0, 0),
                                     new Hero(100, 8, 9, 0, 0),
                                     new Hero(100, 1, 9, 0, 0),
                                     MineOwnership.Create(map));

            var source = map[state.Hero1];
            var mines  = state.Mines;

            var collection = SafePathCollection.Create(map, state);
            var processor  = new DrinkBeerProcessor();

            processor.Initialize(map, state);

            var path = PotentialPath.Initial(source, map, state);

            processor.Process(path, collection);

            var act = collection.GetPotentialPaths();

            Assert.AreEqual(1, act.Count);
            PotentialPathAssert.AreEqual(1, source, 99, mines, MoveDirections.E, -2, act[0]);
        }
Example #6
0
        public void GetMove()
        {
            var map   = MapTest.Map18;
            var state = State.Create(1,
                                     Hero.Create(90, map[2, 3], 0, 0),
                                     Hero.Create(90, map[5, 6], 0, 0),
                                     Hero.Create(90, map[9, 9], 0, 0),
                                     Hero.Create(90, map[1, 9], 0, 0),
                                     MineOwnership.Create(map));

            var root = new RootNode(map, state);

            root.GetMove(map, TimeSpan.FromMilliseconds(1900));
            var act = root.BestMove;
        }
Example #7
0
        public void Process_MoveToFreeMineDistance3_GoNorth()
        {
            var map = Map.Parse(
                "@1[]  $-$-  []@2\r\n" +
                "                \r\n" +
                "                \r\n" +
                "                \r\n" +
                "                \r\n" +
                "                \r\n" +
                "                \r\n" +
                "@3[]  $-$-  []@4\r\n");

            var state = State.Create(1200 - 16,
                                     Hero.Create(44, map[3, 2], 0, 9),
                                     Hero.Create(90, map[2, 6], 2, 4, true),
                                     Hero.Create(90, map[7, 0], 0, 0, true),
                                     Hero.Create(90, map[7, 7], 0, 0, true),
                                     MineOwnership.Create(0, 0, 2, 2));

            var root = new RootNode(map, state);

            root.InitializeMoveMappings(map);

            var sw = new Stopwatch();

            sw.Start();
            for (var depth = state.Turn + 1; depth < 1220; depth++)
            {
                root.Process(map, depth, PotentialScore.EmptyCollection);
            }
            sw.Stop();

            foreach (var score in root.Scores)
            {
                Console.WriteLine("{0} {1}", score.Item1, score.Item2.ToConsoleDisplay(state.PlayerToMove));
            }

            Console.WriteLine("Ellapsed: {0:0.0}", sw.Elapsed.TotalMilliseconds);

            Console.WriteLine(Node.Lookup.DebuggerDisplay);

            Console.WriteLine(Node.Lookup.LogNodeCounts());

            var act = root.BestMove;
            var exp = MoveDirection.N;

            Assert.AreEqual(exp, act);
        }
Example #8
0
        public void Process_12ply_Profiling()
        {
            var map   = MapTest.Map18;
            var state = State.Create(1,
                                     Hero.Create(90, map[2, 3], 0, 0),
                                     Hero.Create(90, map[5, 6], 0, 0),
                                     Hero.Create(90, map[9, 9], 0, 0),
                                     Hero.Create(90, map[1, 9], 0, 0),
                                     MineOwnership.Create(map));

            var root = new RootNode(map, state);

            root.InitializeMoveMappings(map);

            var sw = new Stopwatch();

            sw.Start();
            root.Process(map, 12, PotentialScore.EmptyCollection);
            sw.Stop();

            Console.WriteLine("Ellapsed: {0:0.0}", sw.Elapsed.TotalMilliseconds);
        }
        public void Process_Get1MineAfterDrinkingTwice_4Mines15Turns42Profit()
        {
            var map   = MapTest.Map10Mines8;
            var state = State.Create(1,
                                     new Hero(99, 8, 9, 0, 2),
                                     new Hero(01, 1, 0, 0, 0),
                                     new Hero(50, 3, 2, 0, 0),
                                     new Hero(99, 8, 8, 0, 0),
                                     MineOwnership.Parse(".22......"));

            var collection = SafePathCollection.Create(map, state);

            collection.Procces();
            foreach (var item in collection)
            {
                Console.WriteLine(item.DebuggerDisplay);
            }

            var act = collection.BestPath;
            var exp = new SafePath(3, 7, 13, MoveDirection.E);

            Assert.AreEqual(exp, act);
        }
        public void Process_Get4Mines_4Mines15Turns42Profit()
        {
            var map   = MapTest.Map10Mines8;
            var state = State.Create(0,
                                     new Hero(100, 3, 4, 0, 0),
                                     new Hero(100, 8, 0, 0, 0, true),
                                     new Hero(100, 8, 9, 0, 0, true),
                                     new Hero(100, 1, 9, 0, 0, true),
                                     MineOwnership.Create(map));

            var collection = SafePathCollection.Create(map, state);

            collection.Procces();
            foreach (var item in collection)
            {
                Console.WriteLine(item.DebuggerDisplay);
            }

            var act = collection.BestPath;
            var exp = new SafePath(4, 15, 42, MoveDirection.E);

            Assert.AreEqual(exp, act);
        }
        public void Process_Get1Mine1Mine4Turns4Profit()
        {
            var map   = MapTest.Map10;
            var state = State.Create(0,
                                     new Hero(23, 0, 0, 0, 0),
                                     new Hero(99, 9, 0, 0, 0),
                                     new Hero(99, 9, 9, 0, 0),
                                     new Hero(99, 0, 9, 0, 0),
                                     MineOwnership.Create(map));

            var collection = SafePathCollection.Create(map, state);

            collection.Procces();
            foreach (var item in collection)
            {
                Console.WriteLine(item.DebuggerDisplay);
            }

            var act = collection.BestPath;
            var exp = new SafePath(1, 4, 4, MoveDirection.S);

            Assert.AreEqual(exp, act);
        }
        public void Process_Health99BesideATavern_NoPaths()
        {
            var map   = MapTest.Map10Mines8;
            var state = State.Create(0,
                                     new Hero(100, 1, 0, 0, 0),
                                     new Hero(100, 8, 0, 0, 0),
                                     new Hero(100, 8, 9, 0, 0),
                                     new Hero(100, 1, 9, 0, 0),
                                     MineOwnership.Create(map));

            var collection = SafePathCollection.Create(map, state);
            var processor  = new DrinkBeerProcessor();

            processor.Initialize(map, state);

            var path = PotentialPath.Initial(map[state.Hero1], map, state);

            processor.Process(path, collection);

            var act = collection.GetPotentialPaths();

            Assert.AreEqual(0, act.Count);
        }