I have n x n `GridGraph` (or n x m), I trying to add diagonal edges for each square box automatically and then assign same weights to the diagonals, same weights to horizontal edges and same weights to Vertical edges.

[![9 X9 grid graph with cross edges](https://i.stack.imgur.com/bkZXS.jpg)](https://i.stack.imgur.com/bkZXS.jpg)

I am using 

```
n = 3;
G = GridGraph[{n, n}, VertexLabels -> "Name"];
ce = {1 <-> 5, 2 <-> 6, 4 <-> 8, 5 <-> 9, 2 <-> 4, 3 <-> 5, 5 <-> 7, 6 <-> 8};
ea = EdgeAdd[G, ce]
GG = Normal[AdjacencyMatrix[ea]];

```

Is there any way i can do this for any n x n grid without manually adding edges.

for 3x3 graph the upward edge is (n -> n + 4) until n - 4 (5th node is the last to have this edge). And for downward edge its (n -> n + 2) until (n - 3).

I found one more code here which was adding the diagonal edges but the edges are added randomly.

```
n = 20;
G = GridGraph[{n, n}];
adjMgg = Normal[AdjacencyMatrix[G]];
ind = RandomVariate[BernoulliDistribution[1/2], {n - 1, n - 1}] + 1;
crossedges = 
  Table[
    {(i - 1) n + j <-> (i - 1) n + j + n + 1,
     (i - 1) n + j + 1 <-> (i - 1) n + j + n}[[ind[[i, j]]]], 
    {i, 1, n - 1}, {j, 1, n - 1}] // Flatten;
adjMdg = Normal[AdjacencyMatrix[EdgeAdd[G, crossedges]]];
adjWeight = 300*adjMgg + (adjMdg - adjMgg) /. {0 -> ∞};
dg = 
  WeightedAdjacencyGraph[adjWeight, 
    GraphLayout -> {"GridEmbedding", "Dimension" -> {n, n}}, 
    VertexLabels -> "Name", EdgeLabels -> "EdgeWeight", 
    VertexLabelStyle -> Directive[RGBColor[0.08, 0.35, 0.65], Bold, 10], 
    EdgeStyle -> Directive[GrayLevel[.7]], 
    VertexStyle -> RGBColor[0.08, 0.35, 0.65], 
    VertexSize -> 0.15, 
    ImagePadding -> 10, 
    ImageSize -> Scaled[0.8]];
Module[{i = 1, j = n^2, path}, 
  path = FindShortestPath[dg, i, 381];
  HighlightGraph[dg, PathGraph @ path, GraphHighlightStyle -> "Thick"]]

```