#include #include #include "position.h" #include "pie/dib24.h" void print_dirs(direction_t dirs) { printf("[ "); if ( dirs == DIR_NONE ) printf("NONE "); if ( dirs & DIR_UP ) printf("UP "); if ( dirs & DIR_DOWN ) printf("DOWN "); if ( dirs & DIR_LEFT ) printf("LEFT "); if ( dirs & DIR_RIGHT ) printf("RIGHT "); printf("]\n"); } direction_t dir_invert(direction_t dir) { switch( dir ) { case DIR_UP: return DIR_DOWN; case DIR_DOWN: return DIR_UP; case DIR_LEFT: return DIR_RIGHT; case DIR_RIGHT: return DIR_LEFT; default: assert(!"should never happen"); } } /** * We assume there are only horizontal tunnels */ unsigned int move_safe(Dib24 *xi, unsigned int xy, direction_t dir, unsigned int distance) { int next_xy; switch ( dir ) { case DIR_LEFT: next_xy = xy - distance; /* Handle tunnel */ if ( next_xy < 0 ) next_xy = xi->getWidth() - (1 + next_xy + 1); break; case DIR_RIGHT: next_xy = xy + distance; /* Handle tunnel */ if ( next_xy >= xi->getWidth() ) next_xy = 0 + (next_xy - xi->getWidth()); break; case DIR_UP: next_xy = xy - distance; break; case DIR_DOWN: next_xy = xy + distance; break; default: assert(!"Should never land here!"); } return next_xy; }