X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fmaze.c;h=004c9396c92a3ab26bb68f22e2eaaf82aad377f6;hb=93f25dc6827112d98b8b855ea85c8f5eb8123086;hp=2593f235dad23be6df40b8f27a368a6dc5cfe9f3;hpb=481b95e2617b69e6fd4444432747d7e1e0c3dc85;p=xscreensaver diff --git a/hacks/maze.c b/hacks/maze.c index 2593f235..004c9396 100644 --- a/hacks/maze.c +++ b/hacks/maze.c @@ -1,6 +1,10 @@ /****************************************************************************** * [ maze ] ... * + * modified: [ 1-04-00 ] Johannes Keukelaar + * Added -ignorant option (not the default) to remove knowlege + * of the direction in which the exit lies. + * * modified: [ 6-28-98 ] Zack Weinberg * * Made the maze-solver somewhat more intelligent. There are @@ -35,7 +39,7 @@ * Added bridge option. * modified: [ 8-11-95 ] Ed James * added fill of dead-end box to solve_maze while loop. - * modified: [ 3-7-93 ] Jamie Zawinski + * modified: [ 3-7-93 ] Jamie Zawinski * added the XRoger logo, cleaned up resources, made * grid size a parameter. * modified: [ 3-3-93 ] Jim Randell @@ -159,7 +163,7 @@ static GC gc, cgc, tgc, sgc, ugc, logo_gc, erase_gc; static Pixmap logo_map; static int x = 0, y = 0, restart = 0, stop = 1, state = 1, max_length; -static int sync_p, bridge_p; +static int sync_p, bridge_p, ignorant_p; static int check_events (void) /* X event handler [ rhess ] */ @@ -201,6 +205,9 @@ check_events (void) /* X event handler [ rhess ] */ case Expose: restart = 1; break; + default: + screenhack_handle_event(dpy, &e); + break; } return(1); } @@ -1367,13 +1374,13 @@ find_dead_regions(void) } } } - XSync(dpy, 0); + XSync(dpy, False); } static void solve_maze (void) /* solve it with graphical feedback */ { - int i, dir, from, x, y, ways, bt; + int i, dir, from, x, y, ways, bt = 0; /* plug up the surrounding wall */ maze[end_x][end_y] |= (WALL_TOP >> end_dir); @@ -1431,44 +1438,60 @@ solve_maze (void) /* solve it with graphical feedback */ if(!ways) goto backtrack; - - x = path[i].x - start_x; - y = path[i].y - start_y; - /* choice one */ - if(abs(y) <= abs(x)) - dir = (x > 0) ? WALL_LEFT : WALL_RIGHT; - else - dir = (y > 0) ? WALL_TOP : WALL_BOTTOM; - - if(dir & ways) - goto found; - - /* choice two */ - switch(dir) - { - case WALL_LEFT: - case WALL_RIGHT: - dir = (y > 0) ? WALL_TOP : WALL_BOTTOM; break; - case WALL_TOP: - case WALL_BOTTOM: - dir = (x > 0) ? WALL_LEFT : WALL_RIGHT; - } - - if(dir & ways) - goto found; - - /* choice three */ - - dir = (dir << 2 & WALL_ANY) | (dir >> 2 & WALL_ANY); - if(dir & ways) - goto found; - - /* choice four */ - dir = ways; - if(!dir) - goto backtrack; - found: + if (!ignorant_p) + { + x = path[i].x - start_x; + y = path[i].y - start_y; + /* choice one */ + if(abs(y) <= abs(x)) + dir = (x > 0) ? WALL_LEFT : WALL_RIGHT; + else + dir = (y > 0) ? WALL_TOP : WALL_BOTTOM; + + if(dir & ways) + goto found; + + /* choice two */ + switch(dir) + { + case WALL_LEFT: + case WALL_RIGHT: + dir = (y > 0) ? WALL_TOP : WALL_BOTTOM; break; + case WALL_TOP: + case WALL_BOTTOM: + dir = (x > 0) ? WALL_LEFT : WALL_RIGHT; + } + + if(dir & ways) + goto found; + + /* choice three */ + + dir = (dir << 2 & WALL_ANY) | (dir >> 2 & WALL_ANY); + if(dir & ways) + goto found; + + /* choice four */ + dir = ways; + if(!dir) + goto backtrack; + + found: ; + } + else + { + if(ways&WALL_TOP) + dir = WALL_TOP; + else if(ways&WALL_LEFT) + dir = WALL_LEFT; + else if(ways&WALL_BOTTOM) + dir = WALL_BOTTOM; + else if(ways&WALL_RIGHT) + dir = WALL_RIGHT; + else + goto backtrack; + } bt = 0; ways &= ~dir; /* tried this one */ @@ -1495,7 +1518,7 @@ solve_maze (void) /* solve it with graphical feedback */ return; } - if(!bt) + if(!bt && !ignorant_p) find_dead_regions(); bt = 1; from = path[i-1].dir; @@ -1533,7 +1556,7 @@ enter_square (int n) /* move into a neighboring square */ /* - * jmr additions for Jamie Zawinski's screensaver stuff, + * jmr additions for Jamie Zawinski's screensaver stuff, * note that the code above this has probably been hacked about in some * arbitrary way. */ @@ -1562,6 +1585,8 @@ char *defaults[] = { }; XrmOptionDescRec options[] = { + { "-ignorant", ".ignorant", XrmoptionNoArg, "True" }, + { "-no-ignorant", ".ignorant", XrmoptionNoArg, "False" }, { "-grid-size", ".gridSize", XrmoptionSepArg, 0 }, { "-solve-delay", ".solveDelay", XrmoptionSepArg, 0 }, { "-pre-delay", ".preDelay", XrmoptionSepArg, 0 }, @@ -1597,6 +1622,7 @@ screenhack(Display *display, Window window) generator = get_integer_resource("generator", "Integer"); max_length = get_integer_resource("maxLength", "Integer"); bridge_p = get_boolean_resource("bridge", "Boolean"); + ignorant_p = get_boolean_resource("ignorant", "Boolean"); if (size < 2) size = 7 + (random () % 30); grid_width = grid_height = size; @@ -1612,7 +1638,13 @@ screenhack(Display *display, Window window) set_maze_sizes (xgwa.width, xgwa.height); if (! root) - XSelectInput (dpy, win, ExposureMask|ButtonPressMask|StructureNotifyMask); + { + XWindowAttributes xgwa; + XGetWindowAttributes (dpy, window, &xgwa); + XSelectInput (dpy, win, + xgwa.your_event_mask | ExposureMask | + ButtonPressMask |StructureNotifyMask); + } gc = XCreateGC(dpy, win, 0, 0); cgc = XCreateGC(dpy, win, 0, 0);