int main( int argc, char **argv ) { t_maze maze; if (argc != 5) puts("usage: -width -height -density -solid"); else { init_maze(&maze, atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), atoi(argv[4])); if (build_maze(&maze)) print_maze(&maze); } return 0; }
int main(int ac, char **av) { t_maze *maze; if (ac != 2) return (my_putstr_err(USAGE)); if ((maze = init_maze()) == NULL) return (my_putstr_err(ERR_MALLOC)); if (open_file(maze, av[1]) == 0) return (my_putstr_err(WRONG_FORMAT)); if (solve_maze(maze) == 1) display_maze(maze); else printf("%s\n", NOTHING); free_all(maze); return (0); }
void mouse(int btn, int state, int x, int y) { /* create a new maze */ if ((btn==GLUT_LEFT_BUTTON) && (state==GLUT_DOWN)) { done = 0; init_maze(w, h); while (!done) { step_maze(); } display(); } /* exit */ if ((btn==GLUT_RIGHT_BUTTON) && (state==GLUT_DOWN)) { exit(1); } }
int save_princess(int M, int N, char* maze_data, int time) { struct room_info* maze = NULL; struct room_info* prince = NULL; int time_need = 0; if (M <= 1 || N <= 1 || NULL == maze_data || 0 == time) { return 0; } maze = (struct room_info*)malloc(M * N * sizeof(struct room_info)); if (NULL == maze) { return 0; } prince = init_maze(maze, M, N, maze_data); if (NULL == prince) { /*输入数据有误*/ return 0; } time_need = find_princess(maze, prince); if (-1 == time_need) { return 0; } else if (time_need > time) { return 0; } else { return 1; } }
int main(int argc, char *argv[]) { algorithm carvers[] = { carve_aldous_broder, carve_binary_tree }; int size = argc > 1 ? atoi(argv[1]) : 8; // rudimentary CLI srandom((int) &size); // An address is sufficiently random. (+1 Recycling) Maze test_maze = init_maze(size, size, 15); carve_maze(&test_maze, carvers[BINARY_TREE], SW); // display_maze(&test_maze); puts(""); reset_maze(&test_maze, 15); carve_maze(&test_maze, carvers[ALDOUS_BRODER], 0); display_maze(&test_maze); destroy_maze(&test_maze); return 0; }
void MazePlugin::syscall(State *s, int status, int syscallNo, int valueOfa0) { Q_UNUSED(status); switch(syscallNo) { case S_MAZE_INIT: s->setRegister(v0, init_maze(s)); break; case S_MAZE_DEFEAT: defeat(); break; case S_MAZE_VICTORY: victory(); break; case S_MAZE_IS_GOAL: s->setRegister(v0, is_goal(s, valueOfa0)); break; case S_MAZE_NEIGHBOR: { int results[4]; get_neighbors(s, valueOfa0, results); unsigned int addr = s->getRegister(a1); for(int i = 0; i < 4; ++i) s->setMemoryWord(addr + (i << 2), results[i]); } break; case S_MAZE_DRAW_ARROW: draw_arrow(s, status, valueOfa0, s->getRegister(a1)); break; case S_MAZE_IS_SEARCHED: s->setRegister(v0, is_searched(s, valueOfa0)); break; default: break; } }
void myinit() { printf("Move around with WASD. Press t for a top down view.\n"); GLfloat light0_ambient[]={0.0, 0.0, 0.0, 1.0}; GLfloat light0_diffuse[]={0.5, 0.5, 0.5, 1.0}; GLfloat light0_specular[]={1.0, 1.0, .0, 1.0}; GLfloat light0_position[4]; light0_position[0] = 0.0; light0_position[1] = 0.0; light0_position[2] = 15.0; light0_position[3] = 1.0; /* set up ambient, diffuse, and specular components for light 0 */ glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular); GLfloat light1_ambient[] = {1.0, 0.0, 0.0, 1.0}; GLfloat light1_diffuse[] = {0.5, 0.2, 0.2, 1.0}; GLfloat light1_specular[] = {1.0, 0.0, 0.2, 1.0}; GLfloat light1_position[] = {(GLfloat)(eyeX), (GLfloat)(eyeY), (GLfloat)(eyeZ)/3, 1.0}; GLfloat light1_direction[] = {(GLfloat)(cos(theta)), (GLfloat)(sin(theta)), (eyeZ)/3, 1.0}; glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular); glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, light1_direction); glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 10); lightingMaterialReset(); glEnable(GL_LIGHTING); /* enable lighting */ glEnable(GL_LIGHT0); /* enable light 0 */ glEnable(GL_LIGHT1); /* enable light 1 */ glEnable(GL_DEPTH_TEST); /* enable z buffer */ glClearColor (0.0, 0.0, 0.0, 1.0); // initialize the projection stack glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, 1.0, 0.1, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0, 0.0, 15.0, 0.0, 0.0, 9.0, 0.0, 1.0, 0.0); glLightfv(GL_LIGHT0, GL_POSITION, light0_position); glLightfv(GL_LIGHT1, GL_POSITION, light1_position); //glRotatef(-45,1,0,0); /* build maze */ init_maze(w, h); while (!done) { /* remove one edge */ step_maze(); } //printEdges(); eyeX = col0*wall_spacing+xoff + wall_spacing/2; eyeY = row0*wall_spacing+yoff + wall_spacing/2; lookX = eyeX + 1; lookY = eyeY; }