public void Test_PossibleTiles_LShapedWall_RangeOf2() { // Arrange Point startingLocation = new Point(1, 2); int height = 5; int width = 7; int range = 2; InitializeMap(width, height); // * * * ■ □ □ □ // * * * ■ □ □ □ // * S * ■ □ F □ // * * * ■ ■ □ □ // * * * * □ □ □ this.map[3, 4] = "W"; this.map[3, 3] = "W"; this.map[3, 2] = "W"; this.map[3, 1] = "W"; this.map[4, 1] = "W"; // Act List <Point> path = PossibleTiles.FindTiles(startingLocation, range, this.map); // Assert Assert.IsTrue(path.Count == 15); }
public void Test_PossibleTiles_Contained_RangeOf1_NoPath() { // Arrange Point startingLocation = new Point(2, 2); int height = 5; int width = 5; int range = 3; InitializeMap(width, height); // 4 □ □ □ □ □ // 3 □ ■ ■ ■ □ // 2 □ ■ S ■ □ // 1 □ ■ ■ ■ □ // 0 □ □ □ □ □ // 0 1 2 3 4 this.map[1, 1] = "W"; this.map[1, 2] = "W"; this.map[1, 3] = "W"; this.map[2, 1] = "W"; this.map[2, 3] = "W"; this.map[3, 1] = "W"; this.map[3, 2] = "W"; this.map[3, 3] = "W"; List <Point> path = PossibleTiles.FindTiles(startingLocation, range, this.map); // Assert Assert.IsTrue(path.Count == 0); }
public void Test_PossibleTiles_DeadspotWall_LargeMap_RangeOf3With2Actions() { // Arrange int range = 3; Point startingLocation = new Point(3, 3); int height = 10; int width = 10; InitializeMap(width, height); // 6 □ □ □ □ □ □ □ // 5 □ □ □ □ □ □ □ // 4 □ □ □ □ ■ ■ ■ // 3 □ □ □ S ■ □ ■ // 2 □ □ □ □ ■ ■ ■ // 1 □ □ □ □ □ □ □ // 0 □ □ □ □ □ □ □ // 0 1 2 3 4 5 6 x this.map[4, 2] = "W"; this.map[5, 2] = "W"; this.map[6, 2] = "W"; this.map[4, 3] = "W"; this.map[6, 3] = "W"; this.map[4, 4] = "W"; this.map[5, 4] = "W"; this.map[6, 4] = "W"; // Act List <Point> path = PossibleTiles.FindTiles(startingLocation, range, this.map); List <Point> path2 = PossibleTiles.FindTiles(startingLocation, range * 2, this.map); // Assert Assert.IsTrue(path.Count + (path2.Count - path.Count) == 80); }
public void Test_PossibleTiles_EastDoglegWall_RangeOf7() { // Arrange Point startingLocation = new Point(3, 3); int height = 7; int width = 7; int range = 7; InitializeMap(width, height); // □ □ □ □ □ ■ □ // □ □ □ □ □ ■ □ // □ □ □ □ ■ ■ □ // □ □ □ S ■ □ □ // □ □ □ □ ■ ■ □ // □ □ □ □ □ ■ □ // □ □ □ □ □ ■ □ this.map[5, 6] = "W"; this.map[5, 5] = "W"; this.map[5, 4] = "W"; this.map[4, 4] = "W"; this.map[4, 3] = "W"; this.map[4, 2] = "W"; this.map[5, 2] = "W"; this.map[5, 1] = "W"; this.map[5, 0] = "W"; // Act List <Point> path = PossibleTiles.FindTiles(startingLocation, range, this.map); // Assert Assert.IsTrue(path.Count == 31); }
public void Test_PossibleTiles_EastWall_RangeOf3() { // Arrange Point startingLocation = new Point(2, 2); int height = 5; int width = 5; int range = 3; InitializeMap(width, height); // □ □ □ ■ □ // □ □ □ ■ □ // □ □ S ■ □ // □ □ □ ■ □ // □ □ □ ■ □ this.map[3, 4] = "W"; this.map[3, 3] = "W"; this.map[3, 2] = "W"; this.map[3, 1] = "W"; this.map[3, 0] = "W"; // Act List <Point> path = PossibleTiles.FindTiles(startingLocation, range, this.map); // Assert Assert.IsTrue(path.Count == 14); }
//private SearchParameters searchParameters; private void btnGenerateMap_Click(object sender, EventArgs e) { var watch = System.Diagnostics.Stopwatch.StartNew(); txtMap.Text = ""; int range = 0; if (txtRange.Text != "") { range = int.Parse(txtRange.Text); } int actionPoints = 1; if (txtActionPoints.Text != "") { actionPoints = int.Parse(txtActionPoints.Text); } Point startingLocation = new Point(0, 0); startingLocation = AddBasicTestMap(); //startingLocation = AddWallWithGap(); //startingLocation = AddWallWithSpinningMaze(); //startingLocation = AddRandomMap(); //startingLocation = AddDeadspotWallLargeMap(); //startingLocation = AddMediumBlankMap(); //startingLocation = AddBasicTestMapStep2(); List <Point> path = PossibleTiles.FindTiles(startingLocation, range, this.map); List <Point> path2 = null; if (actionPoints == 2) { path2 = PossibleTiles.FindTiles(startingLocation, range * 2, this.map); } txtMap.Text += ShowPossibleTiles("The algorithm should find a possible tiles, ignoring obstacles:", startingLocation, path, path2); txtMap.Text += Environment.NewLine; int pathCount = path.Count; if (path2 != null && path2.Count > path.Count) { pathCount += (path2.Count - path.Count); } txtMap.Text += "Possible tile count is: " + pathCount; watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; txtMap.Text += Environment.NewLine; txtMap.Text += "Time elapsed is: " + elapsedMs + "ms"; }
public void Test_PossibleTiles_Diag_RangeOf7() { // Arrange Point startingLocation = new Point(0, 6); int height = 7; int width = 7; int range = 7; InitializeMap(width, height); // 6 S ■ ■ □ □ □ □ // 5 ■ □ ■ ■ □ □ □ // 4 ■ ■ □ ■ ■ □ □ // 3 □ ■ ■ □ ■ ■ □ // 2 □ □ ■ ■ □ ■ ■ // 1 □ □ □ ■ ■ □ ■ // 0 □ □ □ □ ■ ■ □ // 0 1 2 3 4 5 6 this.map[0, 4] = "W"; this.map[0, 5] = "W"; this.map[1, 3] = "W"; this.map[1, 4] = "W"; this.map[1, 6] = "W"; this.map[2, 2] = "W"; this.map[2, 3] = "W"; this.map[2, 5] = "W"; this.map[2, 6] = "W"; this.map[3, 1] = "W"; this.map[3, 2] = "W"; this.map[3, 4] = "W"; this.map[3, 5] = "W"; this.map[4, 0] = "W"; this.map[4, 1] = "W"; this.map[4, 3] = "W"; this.map[4, 4] = "W"; this.map[5, 0] = "W"; this.map[5, 2] = "W"; this.map[5, 3] = "W"; this.map[6, 1] = "W"; this.map[6, 2] = "W"; // Act List <Point> path = PossibleTiles.FindTiles(startingLocation, range, this.map); // Assert Assert.IsTrue(path.Count == 6); }
public void Test_PossibleTiles_StraightEast_RangeOf7() { // Arrange Point startingLocation = new Point(0, 1); int height = 9; int width = 9; int range = 7; InitializeMap(width, height); // 8 □ □ □ □ □ □ □ □ □ // 7 □ □ □ □ □ □ □ □ □ // 6 □ □ □ □ □ □ □ □ □ // 5 □ □ □ □ □ □ □ □ □ // 4 □ □ □ □ □ □ □ □ □ // 3 □ □ □ □ □ □ □ □ □ // 2 ■ ■ ■ ■ ■ ■ ■ ■ ■ // 1 S □ □ □ □ □ □ □ □ // 0 ■ ■ ■ ■ ■ ■ ■ ■ ■ // 0 1 2 3 4 5 6 7 8 this.map[0, 0] = "W"; this.map[0, 2] = "W"; this.map[1, 0] = "W"; this.map[1, 2] = "W"; this.map[2, 0] = "W"; this.map[2, 2] = "W"; this.map[3, 0] = "W"; this.map[3, 2] = "W"; this.map[4, 0] = "W"; this.map[4, 2] = "W"; this.map[5, 0] = "W"; this.map[5, 2] = "W"; this.map[6, 0] = "W"; this.map[6, 2] = "W"; this.map[7, 0] = "W"; this.map[7, 2] = "W"; this.map[8, 0] = "W"; this.map[8, 2] = "W"; List <Point> path = PossibleTiles.FindTiles(startingLocation, range, this.map); // Assert Assert.IsTrue(path.Count == 7); }
public void Test_PossibleTiles_EastWall_RangeOf1() { // Arrange int range = 1; Point startingLocation = new Point(1, 1); int height = 3; int width = 3; InitializeMap(width, height); // □ □ □ // □ S ■ // □ □ □ this.map[2, 1] = "W"; // Act List <Point> path = PossibleTiles.FindTiles(startingLocation, range, this.map); // Assert Assert.IsTrue(path.Count == 7); }
public void Test_PossibleTiles_NoWalls_RangeOf2With1Action() { // Arrange int range = 2; Point startingLocation = new Point(10, 10); int height = 20; int width = 20; InitializeMap(width, height); // □ □ □ □ □ // □ □ □ □ □ // □ □ S □ □ // □ □ □ □ □ // □ □ □ □ □ // Act List <Point> path = PossibleTiles.FindTiles(startingLocation, range, this.map); // Assert Assert.IsTrue(path.Count == 24); }
public void Test_PossibleTiles_NoWalls_RangeOf1() { // Arrange Point startingLocation = new Point(2, 2); int height = 5; int width = 5; int range = 1; InitializeMap(width, height); // □ □ □ □ □ // □ □ □ □ □ // □ □ S □ □ // □ □ □ □ □ // □ □ □ □ □ // Act List <Point> path = PossibleTiles.FindTiles(startingLocation, range, this.map); // Assert Assert.IsTrue(path.Count == 8); }
private void btnGenerateMap_Click(object sender, EventArgs e) { txtMap.Text = ""; int width = int.Parse(txtWidth.Text); int height = int.Parse(txtHeight.Text); int range = int.Parse(txtRange.Text); int startingWidth = 3; int startingHeight = 3; // Create a larger maze with custom start and end points InitializeMap(width, height, new Point(0, 0), new Point(width - 1, height - 1), false); AddRandomItems(width, height, 40); AddStartingLocation(startingWidth, startingHeight); //pathFinder = new PathFinding(searchParameters); //path = pathFinder.FindPath(); PathFinding pathFinder = new PathFinding(searchParameters); PathFindingResult pathResult = pathFinder.FindPath(); pathResult.Path.AddRange(PossibleTiles.FindTiles(new Point(0, 0), range, this.map)); txtMap.Text += ShowRoute("The algorithm should be able to find a long route around the random blocks:", pathResult.Path); txtMap.Text += Environment.NewLine; }