From: Alexander Fedotov Date: Sat, 26 Mar 2016 12:08:25 +0000 (+0100) Subject: screen shrinking done X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=59b2b66a7c7b6585ebd30e8c530b9f826bcc70e9;p=mc1516pa.git screen shrinking done --- diff --git a/modelchecker/main.c b/modelchecker/main.c index 240e3c7..d8d7e23 100644 --- a/modelchecker/main.c +++ b/modelchecker/main.c @@ -44,6 +44,7 @@ void solve(FILE *inputstream) sokoban_screen *screen = parse_screen(inputstream); if (screen == NULL) printf("Something went wrong...\n"); sokoban_print(screen); + sokoban_free(screen); //parse_screen(inputstream); time_end_read = clock(); diff --git a/modelchecker/sokoban.c b/modelchecker/sokoban.c index d5e967f..465c628 100644 --- a/modelchecker/sokoban.c +++ b/modelchecker/sokoban.c @@ -50,7 +50,24 @@ void sokoban_print(sokoban_screen *screen) } } -void sokoban_clear(sokoban_screen *screen) +sokoban_screen *sokoban_shrink(int x, int y, sokoban_screen *screen, sokoban_screen *newscreen) +{ + sokoban_screen *c, *nc = NULL; + c = get_coord(x, y, screen); + if (c) { + nc = get_coord(c->coord.x, c->coord.y, newscreen); + if (c->tile != WALL && nc == NULL) { + newscreen = add_coord(x, y, c->tile, newscreen); + newscreen = sokoban_shrink(x-1, y, screen, newscreen); + newscreen = sokoban_shrink(x+1, y, screen, newscreen); + newscreen = sokoban_shrink(x, y-1, screen, newscreen); + newscreen = sokoban_shrink(x, y+1, screen, newscreen); + } + } + return newscreen; +} + +void sokoban_free(sokoban_screen *screen) { sokoban_screen *r, *tmp = NULL; HASH_ITER(hh, screen, r, tmp) { @@ -61,9 +78,11 @@ void sokoban_clear(sokoban_screen *screen) sokoban_screen *parse_screen(FILE *stream) { - int buffer, x, y; + int buffer, x, y, agent_x, agent_y; x = 0; y = 0; + agent_x = 0; + agent_y = 0; sokoban_screen *screen = NULL; while((buffer = fgetc(stream)) != EOF){ if (buffer == '\n'){ @@ -73,7 +92,11 @@ sokoban_screen *parse_screen(FILE *stream) else { switch(buffer) { case ' ': screen = add_coord(x, y, FREE, screen); break; - case '@': screen = add_coord(x, y, AGENT, screen); break; + case '@': + screen = add_coord(x, y, AGENT, screen); + agent_x = x; + agent_y = y; + break; case '.': screen = add_coord(x, y, TARGET, screen); break; case '#': screen = add_coord(x, y, WALL, screen); break; case '$': screen = add_coord(x, y, BOX, screen); break; @@ -84,8 +107,9 @@ sokoban_screen *parse_screen(FILE *stream) x++; } } - sokoban_screen *test = NULL; - test = get_coord(0,0,screen); - if(test->tile == TARGAGENT) printf("Yuppi\n"); - return screen; + sokoban_screen *newscreen = NULL; + newscreen = sokoban_shrink(agent_x, agent_y, screen, newscreen); + //sokoban_print(screen); //unshrinked screen + sokoban_free(screen); + return newscreen; } diff --git a/modelchecker/sokoban.h b/modelchecker/sokoban.h index 414daa0..30466e3 100644 --- a/modelchecker/sokoban.h +++ b/modelchecker/sokoban.h @@ -21,6 +21,6 @@ sokoban_screen *get_coord(int x, int y, sokoban_screen *screen); void sokoban_print(sokoban_screen *screen); -void sokoban_clear(sokoban_screen *screen); +void sokoban_free(sokoban_screen *screen); #endif