From 1c299059bca4b411d944bb9626f23b5d428ae548 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 2 Sep 2011 18:19:58 +0200 Subject: [PATCH] Digit: Calculating possible moves... --- ucw/digit.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/ucw/digit.c b/ucw/digit.c index 6331782..7cc9867 100644 --- a/ucw/digit.c +++ b/ucw/digit.c @@ -10,7 +10,8 @@ #include #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]; @@ -191,6 +192,7 @@ static void generate(void) struct state *t = lookup(to); if (!t) { + ASSERT(wi < MAXSTATES); t = &states[wi++]; norm(to, t->c); t->matches = s->matches+1; @@ -212,8 +214,55 @@ static void generate(void) } } +static void possible_moves(void) +{ + puts("\n=== POSSIBLE MOVES ===\n\n"); + + for (int i=0; imatches < 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; jc[j][k]) + { + c[j][k] = 0; + for (int p=0; pfrom != 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; } -- 2.39.2