Example #1
0
        public void CatBot_cannot_backtrack()
        {
            CatBot CatBot = new CatBot(new Position(0, 0));

            CatBot.Move(new Position(0, 1));

            Assert.Throws <InvalidOperationException>(() => CatBot.Move(new Position(0, 0)));
        }
Example #2
0
        public void CatBot_has_history()
        {
            CatBot CatBot = new CatBot(new Position(0, 0));

            CatBot.Move(new Position(0, 1));

            Assert.Equal(2, CatBot.History.Count());
            Assert.Contains(new Position(0, 0), CatBot.History);
            Assert.Contains(new Position(0, 1), CatBot.History);
        }
        public void Targets_valid_square(int x, int y)
        {
            // Given a grid
            var input = new string[]
            {
                ".....",
                "xxxxx",
                "x.x.x",
                "...x.",
                "....."
            };

            Grid grid = new Grid(new GridInputToBytes(), input);

            // And a bot
            CatBot bot = new CatBot(new Position(x, y));

            // When I generate a firing solution
            var       torpoedoStrategy = new TorpedoStrategy(new Random(), grid, bot);
            Stopwatch timer            = new Stopwatch();

            timer.Start();
            Position target = torpoedoStrategy.GetTarget();

            timer.Stop();

            // Then the calculation was quick
            Assert.True(timer.ElapsedMilliseconds < 10);

            // And the target is inside the grid
            Assert.True(grid.IsPositionInBounds(target), "In bounds");

            // And the target is empty
            Assert.Equal(GridContent.Empty, grid.ContentsAt(target));

            // And in targetting range
            int distance = grid.DistanceBetween(bot.Position, target);

            Assert.True(distance <= 4, "Not out of range");

            // And not my square
            Assert.NotEqual(bot.Position, target);

            // And not next to me
            Assert.True(distance >= 2, "Not next to me");
        }
Example #4
0
        public void Checks_if_move_valid(int startX, int startY, char move, bool expected)
        {
            // Given a grid
            var input = new string[]
            {
                ".....",
                "xxxxx",
                "x.x.x",
                "...x."
            };

            Grid   grid = new Grid(new GridInputToBytes(), input);
            CatBot bot  = new CatBot(new Position(startX, startY));

            // When I check move validity
            bool isValid = bot.IsValidMove(grid, (MoveDirection)move);

            // Then the player position moves
            Assert.Equal(expected, isValid);
        }
Example #5
0
        public void Selects_start_position()
        {
            // Given a grid
            var input = new string[]
            {
                ".....",
                "xxxxx",
                "x.x.x",
                ".x.x."
            };

            Grid grid = new Grid(new GridInputToBytes(), input);

            // When I set the start position
            var    position = new Position(2, 1);
            CatBot bot      = new CatBot(position);

            GridContent content = grid.ContentsAt(bot.Position);

            // Then the position is set
            Assert.Equal(position, bot.Position);
        }
Example #6
0
        public void Player_can_move()
        {
            // Given a grid
            var input = new string[]
            {
                ".....",
                "xxxxx",
                "x.x.x",
                "...x.",
                "....."
            };

            Grid grid = new Grid(new GridInputToBytes(), input);

            // And a start position
            CatBot bot = new CatBot(new Position(1, 2));

            // When I move
            bot.Move(grid, MoveDirection.South);

            // Then the player has moved
            Assert.Equal(new Position(1, 3), bot.Position);
        }
        public void Longest_path_selected(int x, int y, MoveDirection expected)
        {
            // Given a grid
            var input = new string[]
            {
                ".....",
                "xxxxx",
                "x.x.x",
                "...x.",
                "....."
            };

            Grid grid = new Grid(new GridInputToBytes(), input);

            // And a bot
            CatBot bot = new CatBot(new Position(x, y));

            // When I get the best move
            GreatestOptionsMoveStrategy moveStrategy = new GreatestOptionsMoveStrategy(5);
            var move = moveStrategy.GetMove(grid, bot, new CancellationToken());

            // Then the move is correct
            Assert.Equal(expected, move);
        }