예제 #1
0
파일: maze.cpp 프로젝트: gottcode/cutemaze
void StackMaze::generate()
{
	// Generate cell lists
	m_visited = QVector< QVector<bool> >(columns(), QVector<bool>(rows()));
	QList<QPoint> active;

	// Start maze
	QPoint start(0, randomInt(rows()));
	m_visited[start.x()][start.y()] = true;
	active.append(start);

	// Loop through active list
	QPoint cell, neighbor;
	int pos;
	while (!active.isEmpty()) {
		pos = nextActive(active.size());
		cell = active.at(pos);
		neighbor = randomNeighbor(m_visited, cell);
		if (neighbor.x() != -1) {
			mergeCells(cell, neighbor);
			active.append(neighbor);
		} else {
			active.takeAt(pos);
		}
	}

	m_visited.clear();
}
예제 #2
0
파일: maze.cpp 프로젝트: gottcode/cutemaze
void RecursiveBacktrackerMaze::makePath(const QPoint& current)
{
	QPoint neighbor;
	while ( (neighbor = randomNeighbor(m_visited, current)).x() != -1 ) {
		mergeCells(current, neighbor);
		makePath(neighbor);
	}
}
/*!
    \overload
    \since 4.1

    Merges the cells selected by the provided \a cursor.

    \sa splitCell()
*/
void QTextTable::mergeCells(const QTextCursor &cursor)
{
    if (!cursor.hasComplexSelection())
        return;

    int firstRow, numRows, firstColumn, numColumns;
    cursor.selectedTableCells(&firstRow, &numRows, &firstColumn, &numColumns);
    mergeCells(firstRow, firstColumn, numRows, numColumns);
}
예제 #4
0
파일: maze.cpp 프로젝트: gottcode/cutemaze
void PrimMaze::mergeRandomNeighbor(const QPoint& cell)
{
	QList<QPoint> cells;

	QList<QPoint> n = neighbors(cell);
	for (int i = 0; i < n.size(); ++i) {
		const QPoint& current = n.at(i);
		if (m_regions.at(current.x()).at(current.y()) == 2) {
			cells.append(current);
		}
	}

	mergeCells( cell, cells.at(randomInt(cells.size())) );
}
예제 #5
0
파일: maze.cpp 프로젝트: gottcode/cutemaze
void KruskalMaze::generate()
{
	// Generate sets
	m_set_ids = QVector< QVector<Set*> >(columns(), QVector<Set*>(rows()));
	for (int c = 0; c < columns(); ++c) {
		for (int r = 0; r < rows(); ++r) {
			m_sets.append(QList<QPoint>() << QPoint(c, r));
			m_set_ids[c][r] = &m_sets.last();
		}
	}

	while (m_sets.size() > 1) {
		Set* set1 = &m_sets.first();

		// Find random cell
		const QPoint& cell = set1->at(randomInt(set1->size()));

		// Find random neighbor of cell
		QPoint cell2(cell);
		if (randomInt(2)) {
			cell2.rx()++;
		} else {
			cell2.ry()++;
		}
		if (cell2.x() >= columns() || cell2.y() >= rows()) {
			continue;
		}

		// Find set containing second cell
		Set* set2 = m_set_ids.at(cell2.x()).at(cell2.y());

		// Merge sets if they are different
		if (set1 != set2) {
			mergeCells(cell, cell2);
			int size = set1->size();
			for (int i = 0; i < size; ++i) {
				const QPoint& cell3 = set1->at(i);
				m_set_ids[cell3.x()][cell3.y()] = set2;
			}
			*set2 += *set1;
			m_sets.removeFirst();
		}
	}

	m_sets.clear();
	m_set_ids.clear();
}
예제 #6
0
파일: maze.cpp 프로젝트: gottcode/cutemaze
void HuntAndKillMaze::generate()
{
	m_visited = QVector< QVector<bool> >(columns(), QVector<bool>(rows()));
	m_unvisited = columns() * rows();

	QPoint current(0, randomInt(rows()));
	m_visited[current.x()][current.y()] = true;
	m_unvisited--;

	QPoint neighbor;
	while (m_unvisited) {
		neighbor = randomNeighbor(m_visited, current);
		if (neighbor.x() != -1) {
			mergeCells(current, neighbor);
			current = neighbor;
			m_unvisited--;
		} else {
			current = hunt();
		}
	}

	m_visited.clear();
}
예제 #7
0
void QEXCEL::mergeSerialSameCellsInAColumn(int column, int topRow)
{
    int a,b,c,rowsCount;
    getUsedRange(&a, &b, &rowsCount, &c);

    int aMergeStart = topRow, aMergeEnd = topRow + 1;

    QString value;
    while(aMergeEnd <= rowsCount)
    {
        value = getCellValue(aMergeStart, column).toString();
        while(value == getCellValue(aMergeEnd, column).toString())
        {
            clearCell(aMergeEnd, column);
            aMergeEnd++;
        }
        aMergeEnd--;
        mergeCells(aMergeStart, column, aMergeEnd, column);

        aMergeStart = aMergeEnd + 1;
        aMergeEnd = aMergeStart + 1;
    }
}
예제 #8
0
파일: maze.cpp 프로젝트: gottcode/cutemaze
QPoint HuntAndKillMaze::hunt()
{
	static QPoint direction[4] = {
		QPoint(1, 0),
		QPoint(0, 1),
		QPoint(-1, 0),
		QPoint(0, -1)
	};

	QPoint cell, next;
	for (int c = 0; c < columns(); ++c) {
		cell.setX(c);
		for (int r = 0; r < rows(); ++r) {
			cell.setY(r);
			if (m_visited.at(c).at(r)) {
				continue;
			}
			for (int d = 0; d < 4; ++d) {
				next = cell + direction[d];
				if (next.x() < 0 ||
					next.x() >= columns() ||
					next.y() < 0 ||
					next.y() >= rows()) {
					continue;
				}
				if (m_visited.at(next.x()).at(next.y())) {
					mergeCells(cell, next);
					m_visited[c][r] = true;
					m_unvisited--;
					return cell;
				}
			}
		}
	}
	return QPoint(-1, -1);
}