From: Alexander Fedotov Date: Thu, 24 Mar 2016 12:20:23 +0000 (+0100) Subject: simple parsing added X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=bfe9ddb4ffe22c1d8bdd16c39905b226cf122dd9;p=mc1516pa.git simple parsing added --- diff --git a/modelchecker/main.c b/modelchecker/main.c index 16dd229..409f506 100644 --- a/modelchecker/main.c +++ b/modelchecker/main.c @@ -13,7 +13,7 @@ bool DEBUG = false; strategy strat = HYBRID; void usage(char *prg){ - fprintf(stderr, + fprintf(stderr, "Usage:\n" "\t%s [opts] [FILE [FILE [...]]]\n" "\n" @@ -38,8 +38,20 @@ void solve(FILE *inputstream){ clock_t time_start_encode, time_end_encode; time_start_read = clock(); - //struct sokoban_screen *screen = parse_screen(inputstream); - parse_screen(inputstream); + struct sokoban_screen *screen = parse_screen(inputstream); + while(screen != NULL){ + switch(screen->tile){ + case FREE: printf("x = %d y = %d tile = %s\n", screen->x, screen->y, "FREE");break; + case WALL: printf("x = %d y = %d tile = %s\n", screen->x, screen->y, "WALL");break; + case BOX: printf("x = %d y = %d tile = %s\n", screen->x, screen->y, "BOX");break; + case TARGET: printf("x = %d y = %d tile = %s\n", screen->x, screen->y, "TARGET");break; + case AGENT: printf("x = %d y = %d tile = %s\n", screen->x, screen->y, "AGENT");break; + case TARGAGENT: printf("x = %d y = %d tile = %s\n", screen->x, screen->y, "TARGAGENT");break; + case TARGBOX: printf("x = %d y = %d tile = %s\n", screen->x, screen->y, "TARGBOX");break; + } + screen = screen->next; + } + //parse_screen(inputstream); time_end_read = clock(); time_start_encode = clock(); @@ -58,7 +70,7 @@ void solve(FILE *inputstream){ exit(2); } time_end_encode = clock(); - + // Future: SMC fprintf(stderr, "Reading: %fs\n", ((double) (time_end_read-time_start_read))/CLOCKS_PER_SEC); diff --git a/modelchecker/sokoban.c b/modelchecker/sokoban.c index e302670..1abda09 100644 --- a/modelchecker/sokoban.c +++ b/modelchecker/sokoban.c @@ -1,17 +1,38 @@ #include - +#include #include "sokoban.h" + +//Still need to remove outside walls struct sokoban_screen *parse_screen(FILE *stream){ - int buffer; - while((buffer = fgetc(stream)) != EOF){ - printf("%c", buffer); - } - // Alex: - // Screen reading - // - Removing outside walls - // - Bucket fill - // - [tile] - // - tile = structure {int, int, enumtile} - return NULL; -} + int buffer, x, y; + x = 0; + y = 0; + struct sokoban_screen *head, *current; + head = NULL; + while((buffer = fgetc(stream)) != EOF){ + if (buffer == '\n'){ + x = 0; + y++; + } + else { + current = (struct sokoban_screen *)malloc(sizeof(struct sokoban_screen)); + current->next = head; + switch(buffer) { + case ' ' : current->tile = FREE; break; + case '@' : current->tile = AGENT; break; + case '.' : current->tile = TARGET; break; + case '#' : current->tile = WALL; break; + case '$' : current->tile = BOX; break; + case '*' : current->tile = TARGBOX; break; + case '+' : current->tile = TARGAGENT; break; + default: return NULL; + } + current->x = x; + current->y = y; + x++; + head = current; + } + } + return head; + }