コード例 #1
0
void MazeGenerator::generateMaze(int cx, int cy)
{
//JAVA TO C++ CONVERTER WARNING: Since the array size is not known in this declaration, Java to C++ Converter has converted this array to a pointer.  You will need to call 'delete[]' where appropriate:
//ORIGINAL LINE: DIR[] dirs = DIR.values();
	DIR *dirs = DIR::values();
	Collections::shuffle(Arrays::asList(dirs));
	for (auto dir : dirs)
	{
		int nx = cx + dir->dx;
		int ny = cy + dir->dy;
		//System.out.println("maze[nx][ny]"+maze[cx][cy]);
		//System.out.println("dx"+dir.dx+" "+dir.dy);
		if (between(nx, x) && between(ny, y) && (maze[nx][ny] == 0))
		{
			//System.out.println(maze[nx][ny]);
			maze[cx][cy] |= dir->bit;
			maze[nx][ny] |= dir->opposite.bit;
			generateMaze(nx, ny);
			k++;
		}

	}
	/*for(int t=1;t<x;t++) {
		for(int u=1;u<y;u++) {
			System.out.print(maze[t][u]+" ");
		}
		System.out.println("");
	}*/
}
コード例 #2
0
ファイル: maze.c プロジェクト: GNOME/gcompris
static void generateMaze(int x, int y)
{
  int *po;
  Maze[x][y]= Maze[x][y] + SET;
  po = isPossible(x,y);
  while (*po>0)
    {
      int nr = *po;
      int ran, in;
      in=(g_random_int()%nr)+1;
      //printf("random: %d en %d mogelijkheden\n", in, *po);
      ran=*(po + in);
      if (nr>=1)
	switch (ran)
	  {
	  case EAST:
	    Maze[x][y]&=~EAST;
	    Maze[x+1][y]&=~WEST;
	    generateMaze(x+1,y);
	    break;
	  case SOUTH:
	    Maze[x][y]&=~SOUTH;
	    Maze[x][y+1]&=~NORTH;
	    generateMaze(x,y+1);
	    break;
	  case WEST:
	    Maze[x][y]&=~WEST;
	    Maze[x-1][y]&=~EAST;
	    generateMaze(x-1,y);
	    break;
	  case NORTH:
	    Maze[x][y]&=~NORTH;
	    Maze[x][y-1]&=~SOUTH;
	    generateMaze(x,y-1);
	    break;

	  }
      po=isPossible(x,y);
    }

}
コード例 #3
0
// Generates a new Maze with current size
void Labyrinth::generateNewMaze()
{
	initMaze();

	int *backX = new int[size * size];
	int *backY = new int[size * size];

	int stepIndex = 0;
	backX[stepIndex] = backY[stepIndex] = 1;
	generateMaze(stepIndex, backX, backY, Point2d(1, 1), 1);
	
	delete[] backX;
	delete[] backY;
}
コード例 #4
0
ファイル: testAStar.c プロジェクト: dcollien/Alcubierre
int main(int argc, char *argv[]) {
   maze_t maze;

   maze.start.x = 1;
   maze.start.y = 1;

   maze.end.x = 15;
   maze.end.y = 15;

   path_t path;
   int pathLength;

   generateMaze(&maze);

   pathLength = aStar_shortestPath(
      (location_t)&(maze.start),
      isGoal,
      &path,
      expandCoord,
      coordHeuristic,
      coordHash,
      isEqualCoord,
      (void *)&maze
   );

   if (pathLength == NO_PATH) {
      printf("No Path Found\n");
   } else {
      printf("Path Length: %d\n", pathLength);
   }

   drawPath(&maze, path, pathLength);

   printMaze(&maze);

   assert(pathLength == 32);

   printf("All Tests Passed\n");

   return EXIT_SUCCESS;
}
コード例 #5
0
int main()
{

    srand(time(NULL));
    Matrix maze = {NULL, 0, 0};
    Matrix fog = {NULL, 0, 0};
    int width = 50, height = 40;
    Position hero, exit;


    allocateMatrix(&maze, width, height);
    allocateMatrix(&fog, width, height);

    generateMaze(maze, &hero, &exit);
    generateFog(fog, hero);
    runGame(maze, fog, exit, hero);
    freeMatrix(&fog);
    freeMatrix(&maze);

    return 0;
}
コード例 #6
0
ファイル: MainWindow.cpp プロジェクト: orestv/CMazer
void MainWindow::initComponents() {
    QVBoxLayout *pMainLayout = new QVBoxLayout();
    QGridLayout *pControlsLayout = new QGridLayout();
    QGridLayout *pSizeLayout = new QGridLayout();

    pSizePicker = new QSizePicker(250, sqrt(2.));
    pSizePicker->setValue(QSize(90, 75));

    pSizeLayout->addWidget(pSizePicker, 0, 0, 2, 1);

    pControlsLayout->addLayout(pSizeLayout, 0, 0, 2, 1);

    pbtnGenerate = new QPushButton("&Generate");
    pControlsLayout->addWidget(pbtnGenerate, 0, 1);

    pbtnPrint = new QPushButton("&Print");
    pbtnPrint->setEnabled(false);
    pControlsLayout->addWidget(pbtnPrint, 1, 1);

    pbtnQuit = new QPushButton("&Quit");
    pControlsLayout->addWidget(pbtnQuit, 0, 2, 2, 1);


    pMainLayout->addLayout(pControlsLayout);

    pMazeWidget = new MazeWidget(this);
    pMainLayout->addWidget(pMazeWidget);

    this->setLayout(pMainLayout);

    pMazeModel = new MazeModel();
    pMazeWidget->setModel(pMazeModel);


    connect(pbtnQuit, SIGNAL(clicked()), qApp, SLOT(quit()));
    connect(pbtnGenerate, SIGNAL(clicked()), this, SLOT(generateMaze()));
    connect(pbtnPrint, SIGNAL(clicked()), this, SLOT(showPrintDialog()));
}
コード例 #7
0
void Labyrinth::generateMaze(int stepIndex, int *backX, int *backY, Point2d p, int visited)
{
    if(visited < size * size)
    {
        int neighbourValid = -1;
        int neighbourX[4];
        int neighbourY[4];
        int step[4];

        int nextX;
        int nextY;

		int dim = size * 2 + 1;

        if(p.x - 2 > 0 && isMazeClosed(Point2d(p.x - 2, p.y)))  // up side of point
        {
            neighbourValid++;
            neighbourX[neighbourValid] = p.x - 2;
            neighbourY[neighbourValid] = p.y;
            step[neighbourValid] = 1;
        }

        if(p.y - 2 > 0 && isMazeClosed(Point2d(p.x, p.y - 2)))  // left side of point
        {
            neighbourValid++;
            neighbourX[neighbourValid] = p.x;
            neighbourY[neighbourValid]= p.y - 2;
            step[neighbourValid] = 2;
        }

        if(p.y + 2 < dim && isMazeClosed(Point2d(p.x, p.y + 2)))  // right side of point
        {
            neighbourValid++;
            neighbourX[neighbourValid] = p.x;
            neighbourY[neighbourValid] = p.y + 2;
            step[neighbourValid] = 3;

        }

		if(p.x + 2 < dim && isMazeClosed(Point2d(p.x + 2, p.y)))  // down side of point
        {
            neighbourValid++;
            neighbourX[neighbourValid] = p.x + 2;
            neighbourY[neighbourValid] = p.y;
            step[neighbourValid] = 4;
        }

        if(neighbourValid == -1)
        {
            // backtrack
            nextX = backX[stepIndex];
            nextY = backY[stepIndex];
            stepIndex--;
        }

        if(neighbourValid != -1)
        {
            int randomization = neighbourValid + 1;
            int random = rand() % randomization;
            nextX = neighbourX[random];
            nextY = neighbourY[random];
            stepIndex++;
            backX[stepIndex] = nextX;
            backY[stepIndex] = nextY;

            int rstep = step[random];

            if(rstep == 1)
                maze[(nextX + 1) * (dim) + nextY] = PATH;
            else if(rstep == 2)
                maze[nextX * (dim) + nextY + 1] = PATH;
            else if(rstep == 3)
                maze[nextX * (dim) + nextY - 1] = PATH;
            else if(rstep == 4)
                maze[(nextX - 1) * (dim) + nextY] = PATH;
            visited++;
        }

        generateMaze(stepIndex, backX, backY, Point2d(nextX, nextY), visited);
    }
}
コード例 #8
0
ファイル: maze.c プロジェクト: GNOME/gcompris
/* =====================================================================
 * set initial values for the next level
 * =====================================================================*/
static void maze_next_level() {
  GdkPixbuf *pixmap = NULL;

  maze_destroy_all_items();
  gc_bar_set_level(gcomprisBoard);
  setlevelproperties();

  mapActive = FALSE;

  ind = 0;
  gamewon = FALSE;
  initMaze();
  generateMaze((g_random_int()%breedte),(g_random_int()%hoogte));
  removeSet();
  /* Try the next level */
  maze_create_item(goo_canvas_get_root_item(gcomprisBoard->canvas));
  draw_background(wallgroup);

  if(modeIsInvisible) {
    g_object_set (wallgroup, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL);
  }

  /* make a new group for the items */
  begin=g_random_int()%hoogte;
  end=g_random_int()%hoogte;

  /* Draw the tux */
  RsvgHandle *svg_handle = gc_rsvg_load("maze/tux_top_south.svg");
  tuxitem = goo_canvas_svg_new (tuxgroup, svg_handle,
				NULL);
  g_object_unref (svg_handle);

  goo_canvas_item_translate(tuxgroup,
			    cellsize*(0)-breedte + board_border_x,
			    cellsize*(begin)-hoogte + board_border_y);

  g_signal_connect(tuxitem,
		   "button_press_event",
		   (GCallback) tux_event, NULL);

  if(run_fast_possible) {
	  /* Load the tux shoes */
	  svg_handle = gc_rsvg_load("maze/tux_shoes_top_south.svgz");
	  tuxshoes = goo_canvas_svg_new (tuxgroup, svg_handle,
					"pointer-events", GOO_CANVAS_EVENTS_NONE, NULL);
	  g_object_unref (svg_handle);

	  /* Load fast-mode switch button */
	  svg_handle = gc_rsvg_load("maze/fast-mode-button.svgz");
	  fast_mode_button = goo_canvas_svg_new (boardRootItem, svg_handle,
					NULL);
	  g_object_unref (svg_handle);
	  goo_canvas_item_translate(fast_mode_button, 10, 10);
	  g_signal_connect(fast_mode_button,
			   "button_press_event",
			   (GCallback) on_fast_mode_button_press, NULL);
	  gc_item_focus_init(fast_mode_button, NULL);
  }

  /* Draw the target */
  pixmap = gc_pixmap_load("maze/door.png");
  if(pixmap)
    {
      draw_image(mazegroup,breedte-1,end,pixmap);
#if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24
      gdk_pixbuf_unref(pixmap);
#else
      g_object_unref(pixmap);
#endif
    }

  position[ind][0]=0;
  position[ind][1]=begin;
  Maze[0][begin]=Maze[0][begin]+SET;
  viewing_direction=EAST;
  threeDactive=FALSE;

  if(run_fast_possible) {
	  // run_fast-mode should be initialized at every level, whether TRUE or FALSE
	  if (gcomprisBoard->level < 14) set_run_fast(FALSE);
	  if (gcomprisBoard->level >= 14) set_run_fast(TRUE);
  }

  update_tux(viewing_direction);

  if(!modeIs2D)
    threeDdisplay();

}
コード例 #9
0
//JAVA TO C++ CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: public MazeGenerator(int x, int y)
MazeGenerator::MazeGenerator(int x, int y) : x(x), y(y), maze(RectangularArrays::ReturnRectangularIntArray(this->x, this->y))
{
	generateMaze(0, 0);
}