示例#1
0
        private void Recalibrate()
        {
            // Recalculate preferences when there are more than 1 Direction that can be taken from the current Coordinates.
            var moves = 0;

            if (CanMove(Direction.North))
            {
                moves++;
            }
            if (CanMove(Direction.South))
            {
                moves++;
            }
            if (CanMove(Direction.East))
            {
                moves++;
            }
            if (CanMove(Direction.West))
            {
                moves++;
            }
            var needsCalibration = moves > 1;

            if (NavigationMode == CrawlerNavigationMode.Scout && needsCalibration)
            {
                _preference = DirectionHelper.GetPreferences(_current, _destination);
                Trace($"Recalibrated preference: {string.Join(',', _preference )}.");
            }
        }
示例#2
0
        public void GetPreferences_Should_Prefer_Horizontal_Component_If_Distance_Is_The_Same()
        {
            var start       = new Coordinates(5, 5);
            var destination = new Coordinates(1, 1);

            var actual = DirectionHelper.GetPreferences(start, destination);

            actual[0].Should().Be(Direction.West);
            actual[1].Should().Be(Direction.North);
        }
示例#3
0
        public void GetPreferences_Should_Make_Preferences_Based_On_Distance(int destinationX, int destinationY, Direction first, Direction second)
        {
            var start       = new Coordinates(2, 2);
            var destination = new Coordinates(destinationX, destinationY);

            var actual = DirectionHelper.GetPreferences(start, destination);

            actual[0].Should().Be(first);
            actual[1].Should().Be(second);
        }
示例#4
0
        public void GetPreferences_Should_Prefer_North_If_Vertical_Component_Is_The_Same()
        {
            var start       = new Coordinates(1, 1);
            var destination = new Coordinates(5, 1);

            var actual = DirectionHelper.GetPreferences(start, destination);

            actual[1].Should().Be(Direction.North);
            actual[2].Should().Be(Direction.South);
        }
示例#5
0
        public void GetPreferences_Should_Make_Preferences_Based_On_Vertical_Component(int startY, int destinationY, Direction first, Direction last)
        {
            var start       = new Coordinates(0, startY);
            var destination = new Coordinates(0, destinationY);

            var actual = DirectionHelper.GetPreferences(start, destination);

            actual.First().Should().Be(first);
            actual.Last().Should().Be(last);
        }
示例#6
0
        public void GetPreferences_Should_Make_Preferences_Based_On_Horizontal_Component(int startX, int destinationX, Direction first, Direction last)
        {
            var start       = new Coordinates(startX, 0);
            var destination = new Coordinates(destinationX, 0);

            var actual = DirectionHelper.GetPreferences(start, destination);

            actual.First().Should().Be(first);
            actual.Last().Should().Be(last);
        }
示例#7
0
        public MazeCrawler(MazeCrawlerContext context)
        {
            Id             = Guid.NewGuid().ToString();
            CrawlerMap     = context.NavigationMap;
            NavigationMode = context.NavigationMode;

            _coordinator = context.Coordinator;
            _start       = _current = context.Start;
            _destination = context.Destination;

            _stepsTaken = new Queue <char>();
            _preference = DirectionHelper.GetPreferences(_start, _destination);
        }