示例#1
0
            public void BinaryOrTest()
            {
                string[] shape1 =
                {
                    "x..............",
                    ".x.............",
                    "..x............",
                    "...x...........",
                };
                string[] shape2 =
                {
                    "..............x",
                    ".............x.",
                    "............x..",
                    "...........x...",
                };
                var t1 = BinaryTrack.FromString(_gameProps, shape1);
                var t2 = BinaryTrack.FromString(_gameProps, shape2);

                var result = t1.BinaryOr(t2);

                string[] resultShape =
                {
                    "x.............x",
                    ".x...........x.",
                    "..x.........x..",
                    "...x.......x...",
                };
                MapAssert.MatchesShape(_gameProps, result, resultShape);
            }
示例#2
0
            public void Move_Initial()
            {
                BinaryTrack sut = BinaryTrack.StartEmptyTrack(_gameProps);

                Assert.AreEqual((0, 0), sut.Head);
                var map = sut.ToCartesian();

                MapAssert.AllCoordinatesAreZeroExcept(map, (0, 0));
            }
示例#3
0
 public void FromAllZero()
 {
     var gameProps = new GameProps {
         Height = 4, Width = 15, MyId = 0
     };
     var position = (1, 1);
     var actual   = BinaryTrack.FromAllZeroExcept(gameProps, new List <(int, int)> {
         position
     }, position);
示例#4
0
            public void Move_East()
            {
                _sut.OnMove(Direction.East);

                BinaryTrack result = _sut.FirstPossibleTrack();
                var         map    = result.ToCartesian();

                Assert.AreEqual((1, 0), result.Head);
                MapAssert.AllCoordinatesAreZeroExcept(map, (0, 0), (1, 0));
            }
示例#5
0
            public void Move_South()
            {
                BinaryTrack sut = BinaryTrack.StartEmptyTrack(_gameProps);

                var output = sut.MoveSouth();

                Assert.AreEqual((0, 1), output.Head);
                var map = output.ToCartesian();

                MapAssert.AllCoordinatesAreZeroExcept(map, (0, 0), (0, 1));
            }
示例#6
0
 public void FromAllOneExcept()
 {
     string[] expected =
     {
         "xx.xxxxxxxxxxxx",
         "..xxxxxxxxxxxxx",
         "xxxxxxxxxxxxxxx",
         "xxxxxxxxxxxxxxx",
     };
     var result = BinaryTrack.FromAllOneExcept(_gameProps, new List <(int, int)> {
         (0, 1), (1, 1), (2, 0)
     });
示例#7
0
            public void Move_West_ShiftNeeded()
            {
                var shape = new[]
                {
                    ".xx............",
                    "Xxx............",
                    "...............",
                    "...............",
                };
                BinaryTrack sut = BinaryTrack.FromString(_gameProps, shape);

                var output = sut.MoveWest();

                Assert.AreEqual((0, 1), output.Head);
                var map = output.ToCartesian();

                MapAssert.AllCoordinatesAreZeroExcept(map, (2, 0), (3, 0), (0, 1), (1, 1), (2, 1), (3, 1));
            }
示例#8
0
            public void Move_North()
            {
                var shape = new[]
                {
                    "xx.............",
                    ".xX............",
                    "...............",
                    "...............",
                };
                BinaryTrack sut = BinaryTrack.FromString(_gameProps, shape);

                var output = sut.MoveNorth();

                Assert.AreEqual((2, 0), output.Head);
                var map = output.ToCartesian();

                MapAssert.AllCoordinatesAreZeroExcept(map, (0, 0), (1, 0), (1, 1), (2, 1), (2, 0));
            }
示例#9
0
            public void Move_South_NoShiftNeeded()
            {
                var shape = new[]
                {
                    "...............",
                    ".............xx",
                    ".............Xx",
                    "..............x",
                };
                BinaryTrack sut = BinaryTrack.FromString(_gameProps, shape);

                var output = sut.MoveSouth();

                Assert.AreEqual((13, 3), output.Head);
                var map = output.ToCartesian();

                MapAssert.AllCoordinatesAreZeroExcept(map, (13, 1), (14, 1), (13, 2), (14, 2), (13, 3), (14, 3));
            }
示例#10
0
            public void Move_West_NoShiftNeeded_CanMove()
            {
                var shape = new[]
                {
                    "...............",
                    "...............",
                    "x.X............",
                    "xxx............",
                };
                BinaryTrack sut = BinaryTrack.FromString(_gameProps, shape);

                var output = sut.MoveWest();

                Assert.AreEqual((1, 2), output.Head);
                var map = output.ToCartesian();

                MapAssert.AllCoordinatesAreZeroExcept(map, (0, 2), (0, 3), (1, 2), (1, 3), (2, 2), (2, 3));
            }
示例#11
0
            public void Move_East_NoShiftNeeded_CanMove()
            {
                var shape = new[]
                {
                    "............X.x",
                    "............xxx",
                    "...............",
                    "...............",
                };
                BinaryTrack sut = BinaryTrack.FromString(_gameProps, shape);

                var output = sut.MoveEast();

                Assert.AreEqual((13, 0), output.Head);
                var map = output.ToCartesian();

                MapAssert.AllCoordinatesAreZeroExcept(map, (12, 0), (13, 0), (14, 0), (12, 1), (13, 1), (14, 1));
            }
示例#12
0
        public void CanRepresentAllEmptyCells()
        {
            var gameProps = new GameProps {
                Width = 4, Height = 4, MyId = 0
            };

            string[] shape =
            {
                "....",
                "....",
                "....",
                "...."
            };

            BinaryTrack sut = BinaryTrack.FromString(gameProps, shape);

            int[,] map = sut.ToCartesian();
            MapAssert.AllCoordinatesAreZero(map);
        }
示例#13
0
            public void Shift_South_edge()
            {
                var gameProps = new GameProps {
                    Width = 15, Height = 4, MyId = 0
                };

                string[] shape =
                {
                    "...............",
                    "...............",
                    ".x.............",
                    ".....x........."
                };

                BinaryTrack sut          = BinaryTrack.FromString(gameProps, shape);
                bool        canMoveSouth = sut.TryShiftSouth(out var output);

                Console.WriteLine(output);
                Assert.IsFalse(canMoveSouth);
                Assert.IsNull(output);
            }
示例#14
0
        public void CanRepresentMixedFreeAndIslandCells()
        {
            var gameProps = new GameProps {
                Width = 4, Height = 4, MyId = 0
            };

            string[] shape =
            {
                "x..x",
                ".xx.",
                "....",
                "...."
            };

            BinaryTrack sut = BinaryTrack.FromString(gameProps, shape);

            int[,] map = sut.ToCartesian();
            Assert.AreEqual(gameProps.Width, map.GetLength(0));
            Assert.AreEqual(gameProps.Height, map.GetLength(1));

            MapAssert.AllCoordinatesAreZeroExcept(map, (0, 0), (3, 0), (1, 1), (2, 1));
        }
示例#15
0
            public void FetchPossibleMatches_StartFromDifferentPath()
            {
                var shape = new[]
                {
                    "xxxxxxxxxxX....",
                    "x..............",
                    "x..............",
                    "..............."
                };

                BinaryTrack trackBinary     = BinaryTrack.FromString(_gameProps, shape);
                var         possibleMatches = _sut.PossibleTracksWithHeadFilter(trackBinary, BinaryTrack.FromEmpty(_gameProps)).ToList();

                Console.WriteLine($"Total number of matches: {possibleMatches.Count}");
                foreach (var possibleMatch in possibleMatches)
                {
                    Console.WriteLine();
                    Console.WriteLine(possibleMatch);
                }

                Assert.AreEqual(6, possibleMatches.Count);
                CollectionAssert.AreEquivalent(possibleMatches.Select(x => x.Head),
                                               new [] { (10, 0), (11, 0), (12, 0), (10, 1), (11, 1), (12, 1) });
示例#16
0
            public void Shift_East()
            {
                var gameProps = new GameProps {
                    Width = 15, Height = 4, MyId = 0
                };

                string[] shape =
                {
                    ".x.............",
                    "x..............",
                    "...............",
                    "..............."
                };

                BinaryTrack sut = BinaryTrack.FromString(gameProps, shape);

                sut.TryShiftEast(out var output);
                Console.WriteLine(output);

                var map = output.ToCartesian();

                MapAssert.AllCoordinatesAreZeroExcept(map, (1, 1), (2, 0));
            }
示例#17
0
        public void Setup()
        {
            _console   = new ConsoleMock();
            _gameProps = new GameProps {
                Width = 15, Height = 15, MyId = 0
            };

            var mapData = new short[]
            { 0, 3867, 3867, 7680, 7168, 7168, 30720, 30720, 28672, 25008, 25008, 1, 1, 24576, 24576, };
            BinaryTrack binaryMap = BinaryTrack.FromDebug(_gameProps, mapData, null);

            var         currentData  = new short[] { 16384, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
            BinaryTrack currentTrack = BinaryTrack.FromDebug(_gameProps, currentData, (0, 0));

            var filterData = new short[]
            { 32767, 32767, 32767, 32767, 32767, 31775, 31775, 31775, 31775, 32191, 32767, 32767, 32767, 32767, 32767, };
            BinaryTrack filterTrack         = BinaryTrack.FromDebug(_gameProps, filterData, null);
            var         headPositionReducer = new HeadPositionReducer(_gameProps, binaryMap.ToCartesian(), filterTrack);

            _sut = EnemyTracker.FromDebug(_gameProps, binaryMap, currentTrack, null, _console, headPositionReducer, Direction.South);

            var moveProps = new MoveProps {
                OpponentOrders = "SILENCE|SURFACE 5", OpponentLife = 5, MyPosition = (2, 11), TorpedoCooldown = 0, MineCooldown = 3, SilenceCooldown = 5
            };

            _sut.Next(moveProps);



            var nextMoveProps = new MoveProps {
                OpponentOrders = "MOVE S", OpponentLife = 5, MyPosition = (2, 11), TorpedoCooldown = 0, SilenceCooldown = 2, MineCooldown = 1
            };

            _sut.Next(nextMoveProps);
        }
    }
}
示例#18
0
            public void Move_SeveralDirection()
            {
                _sut.OnMove(Direction.East);
                _sut.OnMove(Direction.South);
                _sut.OnMove(Direction.East);
                _sut.OnMove(Direction.North);
                _sut.OnMove(Direction.East);
                _sut.OnMove(Direction.East);
                _sut.OnMove(Direction.East);
                _sut.OnMove(Direction.East);
                _sut.OnMove(Direction.East);
                _sut.OnMove(Direction.East);
                _sut.OnMove(Direction.East);
                _sut.OnMove(Direction.South);


                BinaryTrack result = _sut.FirstPossibleTrack();
                var         map    = result.ToCartesian();

                Assert.AreEqual((9, 1), result.Head);
                MapAssert.AllCoordinatesAreZeroExcept(map, (0, 0), (1, 0), (1, 1), (2, 1), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0), (7, 0), (8, 0), (9, 0), (9, 1));

                Console.WriteLine(_sut.Debug());
            }