public List <FloorTile> condenseList(List <FloorTile> path) { List <FloorTile> condensedList = new List <FloorTile>(); FloorTile lastTile = path[0]; condensedList.Add(path[0]); for (int i = 1; i < path.Count; i++) { if (path[i].Position.Y == lastTile.Position.Y) // moving vertically { while (i < path.Count && path[i].Position.Y == lastTile.Position.Y && i < path.Count - 1) // walk until the next turn { i++; } } else // moving horizontally { while (i < path.Count && path[i].Position.X == lastTile.Position.X) // walk until the next turn { i++; } } lastTile = path[i - 1]; condensedList.Add(path[i - 1]); // add the turning point to the new list; } return(condensedList); }
public void createArray() { //height and width of the original image file int image_width = m_myImage.Width; int image_height = m_myImage.Height; //height and width of the floor plan (in tiles) m_height = (int)(image_height / this.m_pixelsperfoot); m_width = (int)(image_width / this.m_pixelsperfoot); m_floorPlanArray = new FloorTile[m_height, m_width]; // height and width of the array representation of the new array to be created // each cell represent the walkable or non-walkable block defined earlier for (int row = 0; row < m_height; row++) { for (int column = 0; column < m_width; column++) { if (getWalkableValue(column, row) == 0) { m_floorPlanArray[row, column] = new FloorTile(column, row, true, this); } else { m_floorPlanArray[row, column] = new FloorTile(column, row, false, this); } } } }
public void Connect() { for (int row = 0; row < m_height; row++) { for (int column = 0; column < m_width; column++) { FloorTile tile = getTile(column, row); tile.ResetWalkableNeighbors(); } } }
public Boolean setStartTile(int x, int y) { FloorTile start_tile; start_tile = getTile(x, y); if (m_start_tile != null) { m_start_tile.SetStart(false); } if (start_tile != null && start_tile.Iswalkable()) { m_start_tile = start_tile; m_start_tile.SetStart(true); return(true); } return(false); }
public Boolean setTargetTile(int x, int y) { FloorTile target_tile; if (m_target_tile != null) { m_target_tile.SetTarget(false); } { target_tile = getTile(x, y); if (target_tile.Iswalkable()) { m_target_tile = target_tile; m_target_tile.SetTarget(true); return(true); } } return(false); }
public void ResetWalkableNeighbors() { FloorTile tile1 = m_floorPlan.getTile(this.m_location.X - 1, this.m_location.Y); if ((tile1 != null) && (tile1.Iswalkable())) { m_neighbours.Add(tile1); } tile1 = m_floorPlan.getTile(this.m_location.X + 1, this.m_location.Y); if ((tile1 != null) && (tile1.Iswalkable())) { m_neighbours.Add(tile1); } tile1 = m_floorPlan.getTile(this.m_location.X, this.m_location.Y - 1); if ((tile1 != null) && (tile1.Iswalkable())) { m_neighbours.Add(tile1); } tile1 = m_floorPlan.getTile(this.m_location.X, this.m_location.Y + 1); if ((tile1 != null) && (tile1.Iswalkable())) { m_neighbours.Add(tile1); } }
public void createArray() { //height and width of the original image file int image_width = m_myImage.Width; int image_height = m_myImage.Height; //height and width of the floor plan (in tiles) m_height = (int)(image_height / this.m_pixelsperfoot); m_width = (int)(image_width / this.m_pixelsperfoot); m_floorPlanArray = new FloorTile[m_height, m_width]; // height and width of the array representation of the new array to be created // each cell represent the walkable or non-walkable block defined earlier for (int row = 0; row < m_height; row++) { for (int column = 0; column < m_width; column++) { if (getWalkableValue(column, row) == 0) m_floorPlanArray[row, column] = new FloorTile(column, row, true, this); else m_floorPlanArray[row, column] = new FloorTile(column, row, false, this); } } }
public Boolean setTargetTile(int x, int y) { FloorTile target_tile; if (m_target_tile != null) m_target_tile.SetTarget(false); { target_tile = getTile(x, y); if (target_tile.Iswalkable()) { m_target_tile = target_tile; m_target_tile.SetTarget(true); return true; } } return false; }
public Boolean setStartTile(int x, int y) { FloorTile start_tile; start_tile = getTile(x, y); if (m_start_tile != null) m_start_tile.SetStart(false); if (start_tile!= null && start_tile.Iswalkable()) { m_start_tile = start_tile; m_start_tile.SetStart(true); return true; } return false; }
private void drawTile(FloorTile ft, bool IsOnPath) { int PixelOfSide = 10; System.Drawing.SolidBrush myBrush; System.Drawing.SolidBrush myBrushS = new System.Drawing.SolidBrush(System.Drawing.Color.Green); System.Drawing.SolidBrush myBrushT = new System.Drawing.SolidBrush(System.Drawing.Color.Red); System.Drawing.SolidBrush myBrushW = new System.Drawing.SolidBrush(System.Drawing.Color.White); System.Drawing.SolidBrush myBrushB = new System.Drawing.SolidBrush(System.Drawing.Color.Black); System.Drawing.SolidBrush myBrushP = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow); System.Drawing.Graphics formGraphics = this.CreateGraphics(); int TopLeftX = ft.Position.X * PixelOfSide; int TopLeftY = ft.Position.Y * PixelOfSide; int BottomRightX = TopLeftX + PixelOfSide; int BottomRightY = TopLeftY + PixelOfSide; //MessageBox.Show(TopLeftX + "," + TopLeftY + ";" + BottomRightX + "," + BottomRightY); if (ft.Iswalkable()) { myBrush = myBrushW; } else { myBrush = myBrushB; } if (ft.IsStart()) { myBrush = myBrushS; } else if (ft.IsTarget()) { myBrush = myBrushT; } if (IsOnPath) { myBrush = myBrushP; } formGraphics.FillRectangle(myBrush, TopLeftX, TopLeftY, PixelOfSide, PixelOfSide); //draw bolder System.Drawing.Pen myPen; System.Drawing.Pen myPenB = new System.Drawing.Pen(System.Drawing.Color.Black); System.Drawing.Pen myPenW = new System.Drawing.Pen(System.Drawing.Color.White); if (ft.Iswalkable()) { myPen = myPenB; } else { myPen = myPenW; } formGraphics.DrawRectangle(myPen, TopLeftX, TopLeftY, PixelOfSide, PixelOfSide); myBrush.Dispose(); formGraphics.Dispose(); }
private void drawTile(FloorTile ft) { drawTile(ft, false); }
public void getPathTest() { TextWriter tw = new StreamWriter("../../getPathResult.txt"); Image myimage = new Bitmap("../../floorplan.bmp"); FloorPlan floorPlan = new FloorPlan(myimage, 3); // TODO: Initialize to an appropriate value int StartX = 106; int StartY = 74; int TargetX = 107; int TargetY = 43; floorPlan.setStartTile(StartX, StartY); floorPlan.setTargetTile(TargetX, TargetY); String TargetString = TargetX + "_" + TargetY; QGPathFinder qgpf = new QGPathFinder(floorPlan); //show neighbors List<FloorTile> TargetNeighbors = floorPlan.getTargetTile().getNeighbours(); String neighborString = ""; for (int i = 0; i < TargetNeighbors.Count; i++) { neighborString = TargetNeighbors[i].Position.X + "_" + TargetNeighbors[i].Position.Y; //tw.WriteLine("Target Neighbors: " + neighborString + ": " + isContainEdge); } List<FloorTile> actual; actual = qgpf.getPath(); tw.WriteLine(qgpf.GetMessages()); tw.Close(); visualizeFloorPlan(floorPlan, StartX, StartY, TargetX, TargetY); List<FloorTile> expected = new List<FloorTile>(); FloorTile t1 = new FloorTile(0, 0, true, floorPlan); FloorTile t2 = new FloorTile(0, 1, true, floorPlan); FloorTile t3 = new FloorTile(0, 2, true, floorPlan); expected.Add(t1); expected.Add(t2); expected.Add(t3); //String actualString = actual[1].Position.X + "," + actual[1].Position.Y; //String expectedString = expected[1].Position.X + "," + expected[1].Position.Y; //Assert.AreEqual(expectedString, actualString); }