#include <iostream>
using GNode = Graph::GraphNode;
void constructTorus(Graph& g, int height, int width) {
int numNodes = height * width;
std::vector<GNode> nodes(numNodes);
for (int i = 0; i < numNodes; ++i) {
GNode n = g.createNode(
0);
g.addNode(n);
nodes[i] = n;
}
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
GNode c = nodes[x * height + y];
GNode n = nodes[x * height + ((y + 1) % height)];
GNode s = nodes[x * height + ((y - 1 + height) % height)];
GNode e = nodes[((x + 1) % width) * height + y];
GNode w = nodes[((x - 1 + width) % width) * height + y];
g.addEdge(c, n);
g.addEdge(c, s);
g.addEdge(c, e);
g.addEdge(c, w);
}
}
}
int main(int argc, char** argv) {
if (argc < 2) {
std::cerr << "<sqrt grid size>\n";
return 1;
}
int N = atoi(argv[1]);
Graph graph;
constructTorus(graph, N, N);
std::cout << "Constructed a " << N << " x " << N << " torus." << std::endl;
return 0;
}