public static IntPair[] FindPath(GridDelegate grid, int gridSizeX, int gridSizeY, IntPair start, IntPair end) { AStar <IntPair> .NeighborDelegate neighborDelegate = node => astarNeighbors(node, grid, gridSizeX, gridSizeY); Func <IntPair, float> heuristic = node => (float)taxicab(node, end); return(AStar <IntPair> .Solve(neighborDelegate, heuristic, start, end)); }
void changeGrid1(DataTable dt) { if (dataGridView1.InvokeRequired) { GridDelegate grid = new GridDelegate(changeGrid1); dataGridView1.BeginInvoke(grid, new object[] { dt }); } else { GetView.GetGridView(dt, dataGridView1); } }
void changeGrid2(DataTable dt) { if (dataGridView2.InvokeRequired) { GridDelegate grid = new GridDelegate(changeGrid2); dataGridView2.BeginInvoke(grid, new object[] { dt }); } else { dataGridView2.DataSource = null; dataGridView2.DataSource = dt; } }
public static void RenderGrid(GridDelegate grid, int xSize, int ySize, Matrix4x4 localToWorld, Vector3 xvec, Vector3 yvec, Color color = default(Color)) { CreateLineMaterial(); lineMaterial.SetPass(0); GL.PushMatrix(); GL.MultMatrix(localToWorld); GL.Begin(GL.LINES); GL.Color(color); // Draw grid squares for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { if (grid(x, y)) { GL.Vertex(x * xvec + y * yvec); GL.Vertex(x * xvec + (y + 1) * yvec); GL.Vertex(x * xvec + y * yvec); GL.Vertex((x + 1) * xvec + y * yvec); GL.Vertex((x + 1) * xvec + y * yvec); GL.Vertex((x + 1) * xvec + (y + 1) * yvec); GL.Vertex(x * xvec + (y + 1) * yvec); GL.Vertex((x + 1) * xvec + (y + 1) * yvec); } } } GL.End(); GL.PopMatrix(); }
private static IEnumerable <AStar <IntPair> .EdgeType> astarNeighbors(IntPair node, GridDelegate grid, int maxX, int maxY) { foreach (IntPair neighbor in neighborsOf(node, maxX, maxY)) { if (!grid(neighbor.x, neighbor.y)) { yield return(new AStar <IntPair> .EdgeType(node, neighbor, 1)); } } }