#include <string.h>
#define MATCHES 5
-#define SIZE (2*MATCHES+3)
+#define SIZE (2*MATCHES+5)
+/* +5, because possible_moves() sometimes needs to represent a disconnected 5-match configuration with 1 gap */
typedef char conf[SIZE][SIZE];
struct state *t = lookup(to);
if (!t)
{
+ ASSERT(wi < MAXSTATES);
t = &states[wi++];
norm(to, t->c);
t->matches = s->matches+1;
}
}
+static void possible_moves(void)
+{
+ puts("\n=== POSSIBLE MOVES ===\n\n");
+
+ for (int i=0; i<wi; i++)
+ states[i].from = 0;
+
+ for (int i=0; i<wi; i++)
+ {
+ struct state *s = &states[i];
+ if (s->matches < MATCHES)
+ continue;
+ conf c;
+ memcpy(c, s->c, sizeof(conf));
+
+ printf("### State %d ###\n", s->id);
+ print(s->c);
+
+ int neighbors = 0;
+ for (int j=0; j<SIZE; j++)
+ for (int k=0; k<SIZE; k++)
+ if (s->c[j][k])
+ {
+ c[j][k] = 0;
+ for (int p=0; p<SIZE; p++)
+ for (int q=0; q<SIZE; q++)
+ if (!c[p][q] && (p != j || q != k) && has_neighbor(c, p, q))
+ {
+ c[p][q] = 1;
+ struct state *t = lookup(c);
+ if (t && t != s && t->from != s->id)
+ {
+ t->from = s->id;
+ // printf("-> state %d\n", t->id);
+ // print(t->c);
+ neighbors++;
+ }
+ c[p][q] = 0;
+ }
+ c[j][k] = 1;
+ }
+
+ printf("=> %d neighbors\n\n", neighbors);
+ }
+}
+
int main(void)
{
generate();
+ possible_moves();
return 0;
}