Maze* loadMazeFromFile(const char* filename) { FILE* file = NULL; Maze* maze = NULL; SDL_Point c; // Open file file = fopen(filename,"r"); if (file == NULL) { error("Load Maze"); return NULL; } // Get size fscanf(file,"%d %d",&c.x,&c.y); // Make the maze with the size maze = createMaze(c.x,c.y); // Load it for (c.y = 0; c.y < maze->size.y; c.y++) { for (c.x = 0; c.x < maze->size.x; c.x++) { fscanf(file,"%d",&maze->tab[c.x][c.y]); } } fclose(file); return maze; }
int main() { int x, y; WINDOW *win; win = initscr(); curs_set(0); getmaxyx(win, y, x); width = x / 2 - 1; height = y / 2 - 1; createMaze(); do { clear(); refresh(); initMaze(); buildMaze(0, 0); printMaze(); solveMaze(); move(height * 2 + 1, 0); printw("Press 'q' to quit or any other key to run again."); refresh(); } while (getchar() != 'q'); clear(); refresh(); endwin(); return EXIT_SUCCESS; }
//create the pathways as well as start and end cells for the maze void Maze::setupMaze() { bool done = false; while (!done) { createMaze(); done = checkMaze(); } }
int main() { int choice; char direction; int maze[ROWS][COLS]; int end = 1;//Stores game continue true/false createMaze(maze); placeHag(maze); placeStart(maze); // don't remove the next line afterRedirect(); // don't remove the above line // NOTE: stdout has been mangled from the redirection // so after you do a printf without a \n execute the command fflush(stdout); printf("\n \n"); printf("Maze initialized, and ready to play!\n"); printf("Starting position [%d][%d]\n",playerRow, playerCol); do { choice = menu(); if(choice == 1) { direction = readDirection(); move(maze, direction); }// end choice else if(choice ==2) displayMaze(maze); else if(choice ==3) peek(maze); else { printf("Game exit\n"); end = 0;//Game end } moveHag(maze);//Moves hag every third turn }while(endGame(maze) && end); return 0; }// end main
int main(int argc, char **argv) { if (argc < 2) { printf("You need a valid input maze file.\n"); return -1; } printf("Creating maze with file %s\n", argv[1]); maze_t * maze = createMaze(argv[1]); printf("\nUnsolved maze:\n"); printMaze(maze); if(solveMazeManhattanDFS(maze, maze->startColumn, maze->startRow)) { printf("\nSolved maze:\n"); printMaze(maze); if(checkMaze(maze)) { printf("Solution to maze is valid\n"); } else { printf("Incorrect solution to maze\n"); } } else { printf("\nMaze is unsolvable\n"); } printf("\nDestroying maze\n"); destroyMaze(maze); return 0; }
void Maze::load() { std::vector<std::string> map; map.push_back("BBBBBBBBBBBBBBBBBBBBBBBBBBBB"); map.push_back("BGGGGGGGGGGGGBBGGGGGGGGGGGGB"); map.push_back("BGBBBBGBBBBBGBBGBBBBBGBBBBGB"); map.push_back("BRBZZBGBZZZBGBBGBZZZBGBZZBRB"); map.push_back("BGBBBBGBBBBBGBBGBBBBBGBBBBGB"); map.push_back("BGGGGGGGGGGGGGGGGGGGGGGGGGGB"); map.push_back("BGBBBBGBBGBBBBBBBBGBBGBBBBGB"); map.push_back("BGBBBBGBBGBBBBBBBBGBBGBBBBGB"); map.push_back("BGGGGGGBBGGGGBBGGGGBBGBBBBBB"); map.push_back("BBBBBBGBBBBBWBBWBBBBBGBBBBBB"); map.push_back("ZZZZZBGBBBBBWBBWBBBBBGBZZZZZ"); map.push_back("ZZZZZBGBBWWWWWWWWWWBBGBZZZZZ"); map.push_back("ZZZZZBGBBWBBBWWBBBWBBGBZZZZZ"); map.push_back("BBBBBBGBBWBWWWWWWBWBBGBBBBBB"); map.push_back("WWWWWWGWWWBWWWWWWBWWWGWWWWWW"); map.push_back("BBBBBBGBBWBWWWWWWBWBBGBBBBBB"); map.push_back("ZZZZZBGBBWBBBBBBBBWBBGBZZZZZ"); map.push_back("ZZZZZBGBBWWWWWWWWWWBBGBZZZZZ"); map.push_back("ZZZZZBGBBWBBBBBBBBWBBGBZZZZZ"); map.push_back("BBBBBBGBBWBBBBBBBBWBBGBBBBBB"); map.push_back("BGGGGGGGGGGGGBBGGGGGGGGGGGGB"); map.push_back("BGBBBBGBBBBBGBBGBBBBBGBBBBGB"); map.push_back("BRBBBBGBBBBBGBBGBBBBBGBBBBRB"); map.push_back("BGGGBBGGGGGGGGGGGGGGGGBBGGGB"); map.push_back("BBBGBBGBBGBBBBBBBBGBBGBBGBBB"); map.push_back("BBBGBBGBBGBBBBBBBBGBBGBBGBBB"); map.push_back("BGGGGGGBBGGGGBBGGGGBBGGGGGGB"); map.push_back("BGBBBBBBBBBBGBBGBBBBBBBBBBGB"); map.push_back("BGBBBBBBBBBBGBBGBBBBBBBBBBGB"); map.push_back("BGGGGGGGGGGGGGGGGGGGGGGGGGGB"); map.push_back("BBBBBBBBBBBBBBBBBBBBBBBBBBBB"); mazeDisplayList = glGenLists(1); width = 28; height = 31; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { char character = map[y][x]; float *color; color = new float[3]; color[0] = 0.0; color[1] = 0.0; color[2] = 0.0; switch (character) { case 'B': color[2] = 1.0; break; case 'W': color[0] = 1.0; color[1] = 1.0; color[2] = 1.0; break; case 'R': color[0] = 1.0; break; case 'G': color[0] = 1.0; color[1] = 1.0; break; } pixels[x][height - (y + 1)] = color; } } createMaze(); }
int main(int argc, char** argv) { maze m1; node * stack=NULL; // stack pointer node * temp; //temporary node int px, py; // previous x and y positions int x, y; //x and y positions int i,j; int debugMode = false; char *file; /* verify the proper number of command line arguments were given */ if( argc > 3 ) { printf("Usage: %s [-d] <maze data file>\n", argv[0]); exit(-1); } if( 2 == argc ) {//2 arguements, no debug file = argv[1]; } if( 3 == argc ) { //three arguements provided with debug if( argv[1][0] == '-' && argv[1][1] == 'd' ) { debugMode = true; // ./a.out -d mazeInput.txt file = argv[2]; } else if(argv[2][0] == '-' && argv[2][1] == 'd') { debugMode = true; // ./a.out mazeInput.txt -d file = argv[1]; } } m1 = createMaze(file); //initialize maze printf("Input Maze\n"); printf ("size: %d, %d\n", m1.xsize, m1.ysize); printf ("start: %d, %d\n", m1.xstart, m1.ystart); printf ("end: %d, %d\n", m1.xend, m1.yend); printMaze(m1); stack = solve(m1, debugMode); if(stack == NULL) { //nothing on stack printf("\n This maze is unsolvable!!!\n"); } else { px= -1; //previous x and y set to -1 as to not be in maze py= -1; temp = stack; while(temp != NULL) { x = temp->x; y = temp->y; if(m1.array[x][y] != 'e' && m1.array[x][y] != 's') { if(px == x+1) m1.array[x][y] = 'V'; //down else if (px == x-1) m1.array[x][y] = '^'; //up else if(py == y+1) m1.array[x][y] = '>'; //right else if(py == y-1) m1.array[x][y] = '<'; //left else { printf("\nValue not available in stack (%d, %d)\n", x,y); } } px = x; //set previous x and y to the node's values py = y; temp = temp->next; //move along stack } } printMaze(m1); // reprint maze with solution printf("\nSolution coordinates: \n"); printSt( stack); printf("\n"); rmStack(&stack); rmMaze(m1); return(0); }