11.07.2015 Views

Builders guide robot pacman.pdf

Builders guide robot pacman.pdf

Builders guide robot pacman.pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}if ( walls & SOUTH )return 0;elsereturn 1;else // dir == W{if ( walls & WEST )return 0;elsereturn 1;}}void solve( int x, int y ){// maze solving algorithm to get to point pos from current position with fast floodingint queue_x[NUM_CELLS], queue_y[NUM_CELLS]; // holds queue of cells to calculate distanceint goal_distance[NUM_CELLS]; // holds each cell's distance from point posint neigh_cell_x, neigh_cell_y;int queue_count = 0, queue_index = 0, curr_cell_dist = 0; // for solving mazeint i;int curr_pos_dist, neigh_pos_dist; // for creating roadmapint curr_cell_x, curr_cell_y;// initialize frontier arrayfor ( i = 0; i < NUM_CELLS; i++ ){goal_distance[i] = 0xFF;}goal_distance[point_to_cell_number(x,y)] = curr_cell_dist;// add target point pos to queuequeue_x[0] = x;queue_y[0] = y;queue_count++;while(queue_count > 0){queue_count--;curr_cell_x = queue_x[queue_index];curr_cell_y = queue_y[queue_index];curr_cell_dist = goal_distance[point_to_cell_number(curr_cell_x, curr_cell_y)];queue_index++;if ( curr_cell_dist != 0xFF ){// check all neighbours for accessibilityif ( is_neighbour(curr_cell_x, curr_cell_y, N) ){neigh_cell_x = curr_cell_x;neigh_cell_y = curr_cell_y - 1;curr_cell_dist + 1;}if ( goal_distance[point_to_cell_number(neigh_cell_x, neigh_cell_y)] == 0xFF ){goal_distance[point_to_cell_number(neigh_cell_x, neigh_cell_y)] =}queue_x[queue_index + queue_count] = neigh_cell_x;queue_y[queue_index + queue_count] = neigh_cell_y;queue_count++;if ( is_neighbour(curr_cell_x, curr_cell_y, E) ){neigh_cell_x = curr_cell_x + 1;neigh_cell_y = curr_cell_y;curr_cell_dist + 1;}if ( goal_distance[point_to_cell_number(neigh_cell_x, neigh_cell_y)] == 0xFF ){goal_distance[point_to_cell_number(neigh_cell_x, neigh_cell_y)] =}queue_x[queue_index + queue_count] = neigh_cell_x;queue_y[queue_index + queue_count] = neigh_cell_y;queue_count++;if ( is_neighbour(curr_cell_x, curr_cell_y, S) ){neigh_cell_x = curr_cell_x;neigh_cell_y = curr_cell_y + 1;curr_cell_dist + 1;}if ( goal_distance[point_to_cell_number(neigh_cell_x, neigh_cell_y)] == 0xFF ){goal_distance[point_to_cell_number(neigh_cell_x, neigh_cell_y)] =}queue_x[queue_index + queue_count] = neigh_cell_x;queue_y[queue_index + queue_count] = neigh_cell_y;queue_count++;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!