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 )}."); } }
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); }
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); }
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); }
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); }
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); }
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); }