#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];
// putchar('\n');
}
+static void print_matches(conf c)
+{
+ printf("@@");
+ for (int i=0; i<SIZE; i++)
+ for (int j=1-i%2; j<SIZE; j+=2)
+ if (c[i][j])
+ {
+ if (i%2)
+ printf(" (%d,%d)-(%d,%d)", i/2, j/2, i/2+1, j/2);
+ else
+ printf(" (%d,%d)-(%d,%d)", i/2, j/2, i/2, j/2+1);
+ }
+ putchar('\n');
+}
+
static void norm(conf from, conf to)
{
int ii=SIZE, jj=SIZE;
struct state *t = lookup(to);
if (!t)
{
+ ASSERT(wi < MAXSTATES);
t = &states[wi++];
norm(to, t->c);
t->matches = s->matches+1;
to[i][j] = 0;
}
}
- printf("Degree: %d in, %d out, from=%d\n\n", s->indegree, s->outdegree, s->from);
+ printf("Degree: %d in, %d out, from=%d\n", s->indegree, s->outdegree, s->from);
+ print_matches(s->c);
+ putchar('\n');
+ }
+}
+
+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;
}