Exemple #1
0
/*
 * this function makes a random maze with exactly one path between
 * any two points in the maze
 *
 * If you're curious about the algorithm, come talk to me.  It's not very
 * complicated (although the code might be confusing)
 */
void makeMaze() {
	int num_visited = 1;
	int first;
	int finish_col;
	makeAllWalls();
	markCell(0, 0);  // mark the first cell as visited
	
	/* add the first cell (row 0, col 0) to the linked list of visited cells */
	first = cellID(0, 0);
	annotateCell(0, 0, 0);
	
	while(num_visited < MAZE_SIZE * MAZE_SIZE) {
		int visit = rand() % num_visited;
		int cell = first; 
		int row, col;
		int d;
		int nrow, ncol;

		findCell(cell, &row, &col);
		while (visit > 0) {
			cell = annotation(row, col);
			findCell(cell, &row, &col);
			visit -= 1;
		}
		d = rand() % 4;
		nrow = row; // row of neighbor cell
		ncol = col; // col of neighbor cell
		interpretDir(&nrow, &ncol, d);
		if (nrow >= 0 && nrow < MAZE_SIZE
			&& ncol >= 0 && ncol < MAZE_SIZE
			&& !isMarked(nrow, ncol)) {
			clearWall(row, col, d);
			num_visited += 1;
			markCell(nrow, ncol);
			annotateCell(nrow, ncol, first);
			first = cellID(nrow, ncol);	
		}
	}
	
	start_col = rand() % MAZE_SIZE;
	start_col = 2 * start_col + 1;
	maze[0][start_col] &= ~WALL;
	finish_col = rand() % MAZE_SIZE;
	maze[MATRIX_SIZE - 1][2 * finish_col + 1] &= ~WALL;
	//maze[MATRIX_SIZE - 1][0] &= ~WALL;
}
Exemple #2
0
void ClsBaseQStateArrayView::markCell(int iColor, list<int> lstIndex){
#ifdef DEBUG_CLSBASEQSTATEARRAYVIEW
    cout << "ClsBaseQStateArrayView::markCell(int iColor, list<int> lstIndex)" << endl;
#endif

    list<int>::iterator it;
    for(it=lstIndex.begin();it!=lstIndex.end();it++){
	int iIndex = (*it);
//	cout << "iIndex: " << iIndex << endl;
	pair<int, int> pPoint = clsBaseTopologyGroup->index2pos(iIndex);
//	cout << "pPoint.first, pPoint.second: " << pPoint.first << ", " <<  pPoint.second << endl;
	markCell(iColor, pPoint.first, pPoint.second);
    }
}