X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=modelchecker%2Fcoord.c;h=f5774a6b66ec6f3dbc07771696fd46f82e9ef133;hb=03c6e2f515f6516448ec39aa40a439b9fc20c4c8;hp=8905a17d897df2adab106da2cbfaf840c64b756c;hpb=51e07babc1030560dcaff28e68d2fd3c33e504b6;p=mc1516pa.git diff --git a/modelchecker/coord.c b/modelchecker/coord.c index 8905a17..f5774a6 100644 --- a/modelchecker/coord.c +++ b/modelchecker/coord.c @@ -157,6 +157,24 @@ bimap *create_bimap_helper(sokoban_screen *screen) return bm; } +int check_xy_exists(int x, int y, bimap *bm) +{ + int res = 0; + if (getxy(x, y, bm->f) != NULL) res = 1; + return res; +} + +int check_space(int x, int y, direction d, int delta, bimap *bm) +{ + switch(d){ + case LEFT: x = x - delta; break; + case UP: y = y - delta; break; + case RIGHT: x = x + delta; break; + case DOWN: y = y + delta; break; + } + return check_xy_exists(x, y, bm); +} + /* * Each coordinate has three related boolean variables. The combination of those boolean variables * defines tiles: @@ -173,143 +191,86 @@ bimap *create_bimap_helper(sokoban_screen *screen) * directly in transition relations. */ -BDD encode_screen(sokoban_screen *screen) +state *encode_screen(sokoban_screen *screen) { - BDD state = sylvan_false; + LACE_ME; + + BDDVAR vars[HASH_COUNT(screen) * 3]; + for (uint8_t i = 0; i < HASH_COUNT(screen) * 3; i++){ + vars[i] = i; + } + + uint8_t st_enc[HASH_COUNT(screen) * 3]; + + BDDSET varset = sylvan_set_fromarray(vars, HASH_COUNT(screen) * 3); + BDD s; + state *fullState = NULL; + fullState = (state *)malloc(sizeof(state)); + fullState->vars.varset = varset; + fullState->vars.size = HASH_COUNT(screen) * 3; int tile_index = 0; sokoban_screen *r; - LACE_ME; for(r=screen; r != NULL; r = (sokoban_screen *)(r->hh.next)){ switch(r->tile){ - case FREE: - if (state == sylvan_false){ - state = sylvan_not(sylvan_ithvar(tile_index)); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - } - else { - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - } + case FREE: //001 + st_enc[tile_index] = 0; + tile_index++; + st_enc[tile_index] = 0; + tile_index++; + st_enc[tile_index] = 1; + tile_index++; break; - case WALL: - if (state == sylvan_false){ - state = sylvan_not(sylvan_ithvar(tile_index)); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - } - else { - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - } + case WALL: //000 + st_enc[tile_index] = 0; + tile_index++; + st_enc[tile_index] = 0; + tile_index++; + st_enc[tile_index] = 0; + tile_index++; break; - case BOX: - if (state == sylvan_false){ - state = sylvan_not(sylvan_ithvar(tile_index)); - tile_index++; - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - } - else { - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - } + case BOX: //010 + st_enc[tile_index] = 0; + tile_index++; + st_enc[tile_index] = 1; + tile_index++; + st_enc[tile_index] = 0; + tile_index++; break; - case TARGET: - if (state == sylvan_false){ - state = sylvan_not(sylvan_ithvar(tile_index)); - tile_index++; - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - } - else { - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - } + case TARGET: //011 + st_enc[tile_index] = 0; + tile_index++; + st_enc[tile_index] = 1; + tile_index++; + st_enc[tile_index] = 1; + tile_index++; break; - case AGENT: - if (state == sylvan_false){ - state = sylvan_ithvar(tile_index); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - } - else { - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - } + case AGENT: //101 + st_enc[tile_index] = 1; + tile_index++; + st_enc[tile_index] = 0; + tile_index++; + st_enc[tile_index] = 1; + tile_index++; break; - case TARGAGENT: - if (state == sylvan_false){ - state = sylvan_ithvar(tile_index); - tile_index++; - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - } - else { - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - } + case TARGAGENT: //110 + st_enc[tile_index] = 1; + tile_index++; + st_enc[tile_index] = 1; + tile_index++; + st_enc[tile_index] = 0; + tile_index++; break; - case TARGBOX: - if (state == sylvan_false){ - state = sylvan_ithvar(tile_index); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - } - else { - state = sylvan_and(state, sylvan_ithvar(tile_index)); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - state = sylvan_and(state, sylvan_not(sylvan_ithvar(tile_index))); - tile_index++; - } + case TARGBOX: //100 + st_enc[tile_index] = 1; + tile_index++; + st_enc[tile_index] = 0; + tile_index++; + st_enc[tile_index] = 0; + tile_index++; break; } } - /* + /* some testing... xy_bddvar_map *map = NULL; map = create_xy_bddvar_map(screen); xy_bddvar_map *m = getxy(1, 1, map); @@ -319,7 +280,7 @@ BDD encode_screen(sokoban_screen *screen) printf("Test1: %d %d\n", m->value.var[0], m->value.var[1]); printf("Test2: %d %d\n", m2->value.x, m2->value.y); */ - /* + /* some more testing... bimap *bm = NULL; bm = create_bimap_helper(screen); xy_bddvar_map *m = getxy(1, 1, bm->f); @@ -329,7 +290,10 @@ BDD encode_screen(sokoban_screen *screen) printf("%d tiles were encoded\n", tile_index); if (bm != NULL) printf ("WORKS!\n"); */ - return state; + s = sylvan_cube(varset, st_enc); + fullState->bdd = s; + printf("Initial state encoded\n"); + return fullState; } BDD encode_rel(sokoban_screen *screen) @@ -337,22 +301,14 @@ BDD encode_rel(sokoban_screen *screen) int num_tiles; num_tiles = HASH_COUNT(screen); printf("Number of tiles: %d\n", num_tiles); - return sylvan_true; -} -void test() -{ + //left relation - printf("Test!\n"); - BDD a = sylvan_true; - BDD b = sylvan_not(a); - if (b == sylvan_false){ - printf("BDD works!\n"); - } else { - printf("BDD does not work!\n"); - } - LACE_ME; - BDD c = sylvan_ithvar(1); - if (sylvan_high(c) == sylvan_true && sylvan_low(c) == sylvan_false) printf("VAR works 1\n"); - if (sylvan_var(c) == 1) printf("Var works 2\n"); + //up relation + + //right relation + + //down relation + + return sylvan_true; }