private bool Ydirect(Grid start, Grid end, LinkedList path) { if (start.GetXpos() != end.GetXpos()) { return(false); } int direct = 1; if (start.GetYpos() > end.GetYpos()) { direct = -1; } path.Clear(); for (int y = start.GetYpos() + direct; y != end.GetYpos() && y < yBound && y >= 0; y += direct) { if (grid[y][start.GetXpos()].IsVisible()) { return(false); } path.Add(grid[y][start.GetXpos()]); } path.Add(end); return(true); }
private bool Xdirect(Grid start, Grid end, LinkedList path) { if (start.GetYpos() != end.GetYpos()) { return(false); } int direct = 1; if (start.GetXpos() > end.GetXpos()) { direct = -1; } path.Clear(); for (int x = start.GetXpos() + direct; x != end.GetXpos() && x < xBound && x >= 0; x += direct) { if (grid[start.GetYpos()][x].IsVisible()) { return(false); } path.Add(grid[start.GetYpos()][x]); } path.Add(end); return(true); }
private int FindPath(Grid start, Grid end) { if (Xdirect(start, end, path[0])) { return 1; } if (Ydirect(start, end, path[0])) { return 1; } Grid xy = grid[start.GetYpos()][end.GetXpos()]; if (!xy.IsVisible() && Xdirect(start, xy, path[0]) && Ydirect(xy, end, path[1])) { return 2; } Grid yx = grid[end.GetYpos()][start.GetXpos()]; if (!yx.IsVisible() && Ydirect(start, yx, path[0]) && Xdirect(yx, end, path[1])) { return 2; } path[0].Clear(); for (int y = start.GetYpos() - 1; y >= 0; y--) { xy = grid[y][start.GetXpos()]; yx = grid[y][end.GetXpos()]; if (xy.IsVisible()) { break; } path[0].Add(xy); if (!yx.IsVisible() && Xdirect(xy, yx, path[1]) && Ydirect(yx, end, path[2])) { return 3; } } path[0].Clear(); for (int y = start.GetYpos() + 1; y < yBound; y++) { xy = grid[y][start.GetXpos()]; yx = grid[y][end.GetXpos()]; if (xy.IsVisible()) { break; } path[0].Add(xy); if (!yx.IsVisible() && Xdirect(xy, yx, path[1]) && Ydirect(yx, end, path[2])) { return 3; } } path[0].Clear(); for (int x = start.GetXpos() - 1; x >= 0; x--) { yx = grid[start.GetYpos()][x]; xy = grid[end.GetYpos()][x]; if (yx.IsVisible()) { break; } path[0].Add(yx); if (!xy.IsVisible() && Ydirect(yx, xy, path[1]) && Xdirect(xy, end, path[2])) { return 3; } } path[0].Clear(); for (int x = start.GetXpos() + 1; x < xBound; x++) { yx = grid[start.GetYpos()][x]; xy = grid[end.GetYpos()][x]; if (yx.IsVisible()) { break; } path[0].Add(yx); if (!xy.IsVisible() && Ydirect(yx, xy, path[1]) && Xdirect(xy, end, path[2])) { return 3; } } return 0; }
private bool Ydirect(Grid start, Grid end, LinkedList path) { if (start.GetXpos() != end.GetXpos()) { return false; } int direct = 1; if (start.GetYpos() > end.GetYpos()) { direct = -1; } path.Clear(); for (int y = start.GetYpos() + direct; y != end.GetYpos() && y < yBound && y >= 0; y += direct) { if (grid[y][start.GetXpos()].IsVisible()) { return false; } path.Add(grid[y][start.GetXpos()]); } path.Add(end); return true; }
private bool Xdirect(Grid start, Grid end, LinkedList path) { if (start.GetYpos() != end.GetYpos()) return false; int direct = 1; if (start.GetXpos() > end.GetXpos()) { direct = -1; } path.Clear(); for (int x = start.GetXpos() + direct; x != end.GetXpos() && x < xBound && x >= 0; x += direct) { if (grid[start.GetYpos()][x].IsVisible()) { return false; } path.Add(grid[start.GetYpos()][x]); } path.Add(end); return true; }
private int FindPath(Grid start, Grid end) { if (Xdirect(start, end, path[0])) { return(1); } if (Ydirect(start, end, path[0])) { return(1); } Grid xy = grid[start.GetYpos()][end.GetXpos()]; if (!xy.IsVisible() && Xdirect(start, xy, path[0]) && Ydirect(xy, end, path[1])) { return(2); } Grid yx = grid[end.GetYpos()][start.GetXpos()]; if (!yx.IsVisible() && Ydirect(start, yx, path[0]) && Xdirect(yx, end, path[1])) { return(2); } path[0].Clear(); for (int y = start.GetYpos() - 1; y >= 0; y--) { xy = grid[y][start.GetXpos()]; yx = grid[y][end.GetXpos()]; if (xy.IsVisible()) { break; } path[0].Add(xy); if (!yx.IsVisible() && Xdirect(xy, yx, path[1]) && Ydirect(yx, end, path[2])) { return(3); } } path[0].Clear(); for (int y = start.GetYpos() + 1; y < yBound; y++) { xy = grid[y][start.GetXpos()]; yx = grid[y][end.GetXpos()]; if (xy.IsVisible()) { break; } path[0].Add(xy); if (!yx.IsVisible() && Xdirect(xy, yx, path[1]) && Ydirect(yx, end, path[2])) { return(3); } } path[0].Clear(); for (int x = start.GetXpos() - 1; x >= 0; x--) { yx = grid[start.GetYpos()][x]; xy = grid[end.GetYpos()][x]; if (yx.IsVisible()) { break; } path[0].Add(yx); if (!xy.IsVisible() && Ydirect(yx, xy, path[1]) && Xdirect(xy, end, path[2])) { return(3); } } path[0].Clear(); for (int x = start.GetXpos() + 1; x < xBound; x++) { yx = grid[start.GetYpos()][x]; xy = grid[end.GetYpos()][x]; if (yx.IsVisible()) { break; } path[0].Add(yx); if (!xy.IsVisible() && Ydirect(yx, xy, path[1]) && Xdirect(xy, end, path[2])) { return(3); } } return(0); }