Exemplo n.º 1
0
        public void Apply_Select_AreEqual()
        {
            var mapstate = new MapState(1);

            mapstate.Set(1, (ushort)PlayerType.player1, 13);
            Assert.AreEqual(PlayerType.player1, mapstate.Owner(1), "Owner, Before");
            Assert.AreEqual(13, mapstate.Armies(1), "Armies, Before");

            mapstate.Apply(Move.CreateSelect(PlayerType.player1, 1), this.TestMap);

            Assert.AreEqual(PlayerType.player1, mapstate.Owner(1), "Owner, After");
            Assert.AreEqual(2, mapstate.Armies(1), "Armies, After");
        }
Exemplo n.º 2
0
        public void GetHashCode_Transforms_AreEqual()
        {
            var exp = 16778040;

            var state0 = new MapState(2);

            state0.Set(1, 2, 13);
            state0.Set(2, 1, 53);
            state0.NextStep(2);
            state0.NextStep(2);

            var act0 = state0.GetHashCode();

            Assert.AreEqual(exp, act0, "hash act0");

            var state1 = new MapState(2);

            state1.Set(1, 2, 13);
            state1.Set(2, 1, 53);
            state1.NextStep(2);
            state1.Set(2, 0, 2);
            state1.Set(2, 2, 2);
            state1.Apply(Move.CreateStack(PlayerType.player2, 2, 13), this.TestMap);
            state1.Set(2, 1, 53);
            state1.Set(1, 2, 10);
            state1.Apply(Move.CreateStack(PlayerType.player1, 1, 3), this.TestMap);
            state1.NextStep(2);

            var act1 = state1.GetHashCode();

#if DEBUG
            DebugRegions debug0 = state0.ToDebug();
            DebugRegions debug1 = state1.ToDebug();
#endif
            Assert.AreEqual(state0.Owner(1), state1.Owner(1), "Owner[1]");
            Assert.AreEqual(state0.Armies(1), state1.Armies(1), "Armies[1]");

            Assert.AreEqual(state0.Owner(2), state1.Owner(2), "Owner[2]");
            Assert.AreEqual(state0.Armies(2), state1.Armies(2), "Armies[2]");

            //Assert.AreEqual(state0.PlayerToMove, state1.PlayerToMove, "PlayerToMove");
            Assert.AreEqual(state0.SubRound, state1.SubRound, "SubRound");


            Assert.AreEqual(exp, act1, "hash act1");
        }
Exemplo n.º 3
0
        public void Apply_Transform7_AreEqual()
        {
            var mapstate = new MapState(2);

            mapstate.Set(1, (ushort)PlayerType.player1, 13);
            mapstate.Set(2, (ushort)PlayerType.player1, 03);

            Assert.AreEqual(PlayerType.player1, mapstate.Owner(1), "Owner[1], Before");
            Assert.AreEqual(13, mapstate.Armies(1), "Armies[1], Before");

            Assert.AreEqual(PlayerType.player1, mapstate.Owner(2), "Owner[2], Before");
            Assert.AreEqual(3, mapstate.Armies(2), "Armies[2], Before");

            mapstate.Apply(Move.CreateTransfer(PlayerType.player1, 1, 2, 7), this.TestMap);

            Assert.AreEqual(PlayerType.player1, mapstate.Owner(1), "Owner[2], After");
            Assert.AreEqual(06, mapstate.Armies(1), "Armies[1], After");

            Assert.AreEqual(PlayerType.player1, mapstate.Owner(2), "Owner[2], After");
            Assert.AreEqual(10, mapstate.Armies(2), "Armies[2], After");
        }
Exemplo n.º 4
0
        public void Apply_Attack10vs20_AreEqual()
        {
            var mapstate = new MapState(2);

            mapstate.Set(1, (ushort)PlayerType.player1, 11);
            mapstate.Set(2, (ushort)PlayerType.player2, 20);

            Assert.AreEqual(PlayerType.player1, mapstate.Owner(1), "Owner[1], Before");
            Assert.AreEqual(11, mapstate.Armies(1), "Armies[1], Before");

            Assert.AreEqual(PlayerType.player2, mapstate.Owner(2), "Owner[2], Before");
            Assert.AreEqual(20, mapstate.Armies(2), "Armies[2], Before");

            mapstate.Apply(Move.CreateTransfer(PlayerType.player1, 1, 2, 10), this.TestMap);

            Assert.AreEqual(PlayerType.player1, mapstate.Owner(1), "Owner[2], After");
            Assert.AreEqual(1, mapstate.Armies(1), "Armies[1], After");

            Assert.AreEqual(PlayerType.player2, mapstate.Owner(2), "Owner[2], After");
            Assert.AreEqual(14, mapstate.Armies(2), "Armies[2], After");
        }
Exemplo n.º 5
0
        public void Armies_Region_AreEqual()
        {
            var map = UnitTestMap.InitSmall();

            var state = new MapState(map.Count);

            state.Set(1, (ushort)PlayerType.player1, 13);

            var act = state.Armies(map[1]);
            var exp = 13;

            Assert.AreEqual(exp, act);
        }
Exemplo n.º 6
0
        public static DebugRegions ToDebug(this MapState state, bool excludeNeutral2 = true)
        {
            var regions = new DebugRegions(state.Round, state.SubRound, state.PlayerToMove);

            for (int id = 1; id <= state.Count; id++)
            {
                var owner  = state.Owner(id);
                var armies = state.Armies(id);
                if (!excludeNeutral2 || owner != PlayerType.neutral || armies != 2)
                {
                    regions.Add(new DebugRegion(id, owner, armies));
                }
            }
            return(regions);
        }
Exemplo n.º 7
0
        public void UpdateRegion_Range_AreEqual()
        {
            for (int armies = 1; armies < 0x0fff; armies++)
            {
                for (ushort owner = 0; owner <= 2; owner++)
                {
                    var        mapstate = new MapState(1);
                    PlayerType player   = (PlayerType)owner;
                    mapstate.Set(1, owner, (ushort)armies);

                    Assert.AreEqual(player, mapstate.Owner(1), "Owner, Mapstate(1, {0}, {1})", player, armies);
                    Assert.AreEqual(armies, mapstate.Armies(1), "Armies, Mapstate(1, {0}, {1})", player, armies);
                }
            }
        }