+struct tracks_neighbour_ctx {
+ game_state *state;
+ int i, n, neighbours[4];
+};
+static int tracks_neighbour(int vertex, void *vctx)
+{
+ struct tracks_neighbour_ctx *ctx = (struct tracks_neighbour_ctx *)vctx;
+ if (vertex >= 0) {
+ game_state *state = ctx->state;
+ int w = state->p.w, x = vertex % w, y = vertex / w;
+ int dirs = S_E_DIRS(state, x, y, E_TRACK);
+ int j;
+
+ ctx->i = ctx->n = 0;
+
+ for (j = 0; j < 4; j++) {
+ int dir = 1<<j;
+ if (dirs & dir) {
+ int nx = x + DX(dir), ny = y + DY(dir);
+ if (INGRID(state, nx, ny))
+ ctx->neighbours[ctx->n++] = ny * w + nx;
+ }
+ }