From: Martin Mares Date: Fri, 2 Sep 2011 16:19:58 +0000 (+0200) Subject: Digit: Calculating possible moves... X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=1c299059bca4b411d944bb9626f23b5d428ae548;p=misc.git Digit: Calculating possible moves... --- 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; }