QVariantList Excel::getAll(int *rows, int *cols) { QVariant result; char sCell[18]; try { getRowsCols(rows, cols); memset(sCell, 0, 18); if (*cols <= 26) sprintf(sCell, "%c", 'A' + *cols - 1); else sprintf(sCell, "%c%c", 'A' + *cols / 26 - 1, 'A' + *cols % 26 - 1); QString cell = sCell; cell = cell.trimmed() + QString::number(*rows); QString srange = "Range(\"A1\",\"" + cell + "\")"; if (excelSheet) { QAxObject *range = excelSheet->querySubObject(srange.toLocal8Bit()); if (range) { result = range->property("Value"); delete range; } } } catch (...) {} QVariantList list = qVariantValue<QVariantList>(result); return list; }
void WorldMaze::createRandomMaze(WorldSize size) { clearSelection(/* redraw */ false); int rowsCols = getRowsCols(size) / 2 + 1; worldGrid.resize(rowsCols, rowsCols); worldGrid.fill(MAZE_FLOOR); graph = gridToGraph(worldGrid); // assign random weights to the edges // give each edge a 'random' weight; // put all edges into a priority queue, sorted by weight Set<Edge*> edgeSet = graph->getEdgeSet(); int edgeCount = edgeSet.size(); for (Edge* edge : edgeSet) { int weight = randomInteger(1, edgeCount * 1000); edge->cost = weight; } // run the student's Kruskal algorithm to get a minimum spanning tree (MST) Set<Edge*> mst = kruskal(*graph); // convert the MST/graph back into a maze grid // (insert a 'wall' between any neighbors that do not have a connecting edge) graph->clearEdges(); for (Edge* edge : mst) { graph->addEdge(edge->start, edge->finish); graph->addEdge(edge->finish, edge->start); } // physical <-> logical size; a maze of size MxN has 2M-1 x 2N-1 grid cells. // cells in row/col 0, 2, 4, ... are open squares (floors), and cells in // row/col 1, 3, 5, ... are blocked (walls). int digits = countDigits(rowsCols); int worldSize = rowsCols * 2 - 1; worldGrid.resize(worldSize, worldSize); worldGrid.fill(MAZE_WALL); pxPerWidth = (double) windowWidth / worldSize; pxPerHeight = (double) windowHeight / worldSize; for (int row = 0; row < worldSize; row++) { for (int col = 0; col < worldSize; col++) { if (row % 2 == 0 && col % 2 == 0) { worldGrid.set(row, col, MAZE_FLOOR); } } } for (int row = 0; row < rowsCols; row++) { int gridRow = row * 2; for (int col = 0; col < rowsCols; col++) { int gridCol = col * 2; std::string name = vertexName(row, col, digits); // decide whether to put open floor between neighbors // (if there is an edge between them) for (int dr = -1; dr <= 1; dr++) { int nr = row + dr; int gridNr = gridRow + dr; for (int dc = -1; dc <= 1; dc++) { int nc = col + dc; int gridNc = gridCol + dc; if ((nr != row && nc != col) || (nr == row && nc == col) || !worldGrid.inBounds(gridNr, gridNc)) { continue; } std::string neighborName = vertexName(nr, nc, digits); if (graph->containsEdge(name, neighborName)) { worldGrid.set(gridNr, gridNc, MAZE_FLOOR); } } } } } delete graph; graph = gridToGraph(worldGrid); }
WorldMaze::WorldMaze(GWindow* gwnd, WorldSize size) : WorldGrid(gwnd, getRowsCols(size)) { // empty }
WorldTerrain::WorldTerrain(GWindow* gwnd, WorldSize size) : WorldGrid(gwnd, getRowsCols(size)) { // empty }