int DifficultyAnalyser::furtherCalculations(SokoGenerator::Level level){ int neighbourBoxes = 0; int neighbourWalls = 0; int neighbourPlayer = 0; int neighbourGoals = 0; for(int y = 0; y < level.grid.size(); y++){ for(int x = 0; x < level.grid[0].size(); x++){ if(level.grid[y][x] == BOX){ if(neighbourCheck(level, x, y, BOX, BOXONGOAL) > 0){ neighbourBoxes++; } if(neighbourCheck(level, x, y, WALL) > 0){ neighbourWalls++; } if(neighbourCheck(level, x, y, PLAYER, PONGOAL) > 0){ neighbourPlayer++; } } if(level.grid[y][x] == GOAL){ if(neighbourCheck(level, x, y, GOAL, PONGOAL) > 0){ neighbourGoals++; } } } } return (neighbourBoxes * 30) + (neighbourWalls * -150) + (neighbourPlayer * 50) + (neighbourGoals * 30); }
void Fill::leftPress(BrushArea& brush, QMouseEvent* e) { if(!model_.levelEditorModel()->selectedEntity()) { visited_.clear(); auto it = model_.levelEditorModel()->selectedTiles().begin(); if(it == model_.levelEditorModel()->selectedTiles().end()) return; selectedTile_ = &(it->second); auto pos = brush.position; fillTile_ = lvl_->getTile(pos.x(), pos.y(), lvl_->currentLayer()); startPos_ = pos; if(fillTile_) neighbourCheck(pos); else emptyNeighbourCheck(pos); if(!urTiles_.empty()) { model_.levelURManager()->add<AddTileCommand>(true,lvl_,urTiles_); urTiles_.clear(); lvl_->setUnsaved(true); } } }
void Fill::neighbourCheck(QVector2D pos) { int lw = lvl_->levelDimensions().x(); int lh = lvl_->levelDimensions().y(); int sx = startPos_.x()-30; if(sx <= 0) sx = 0; int sy = startPos_.y()-30; if(sy <= 0) sy = 0; int ex = startPos_.x()+30; if(ex >= lw) ex = lw; int ey = startPos_.y()+30; if(ey >= lh) ey = lh; if(!(int(pos.x()) >= sx && int(pos.x()) < ex && int(pos.y()) >= sy && int(pos.y()) < ey)) return; if(Util::List::findElement(visited_, pos)) return; std::vector<QVector2D> neighbours; auto leftPos = QVector2D(int(pos.x())-1, int(pos.y())); auto left = lvl_->getTile(leftPos.x(), leftPos.y(), lvl_->currentLayer()); if(left && int(left->setLocation.x()) == int(fillTile_->setLocation.x()) && int(left->setLocation.y()) == int(fillTile_->setLocation.y())) if(!Util::List::findElement(visited_, leftPos)) neighbours.push_back(leftPos); auto topPos = QVector2D(int(pos.x()), int(pos.y())-1); auto top = lvl_->getTile(topPos.x(), topPos.y(), lvl_->currentLayer()); if(top && int(top->setLocation.x()) == int(fillTile_->setLocation.x()) && int(top->setLocation.y()) == int(fillTile_->setLocation.y())) if(!Util::List::findElement(visited_, topPos)) neighbours.push_back(topPos); auto rightPos = QVector2D(int(pos.x())+1, int(pos.y())); auto right = lvl_->getTile(rightPos.x(), rightPos.y(), lvl_->currentLayer()); if(right && int(right->setLocation.x()) == int(fillTile_->setLocation.x()) && int(right->setLocation.y()) == int(fillTile_->setLocation.y())) if(!Util::List::findElement(visited_, rightPos)) neighbours.push_back(rightPos); auto downPos = QVector2D(int(pos.x()), int(pos.y())+1); auto down = lvl_->getTile(downPos.x(), downPos.y(), lvl_->currentLayer()); if(down && int(down->setLocation.x()) == int(fillTile_->setLocation.x()) && int(down->setLocation.y()) == int(fillTile_->setLocation.y())) if(!Util::List::findElement(visited_, downPos)) neighbours.push_back(downPos); std::pair<int,int> pair = std::make_pair(int(pos.x()), int(pos.y())); if(!Util::Map::findKey(urTiles_,pair)) { auto prevTile = lvl_->getTile(pair.first, pair.second, lvl_->currentLayer()); URTile prev; if(prevTile) { prev = {*prevTile, pos, lvl_->currentLayer()}; } else prev = {Tile(), QVector2D(-1,-1), lvl_->currentLayer()}; std::pair<URTile,URTile> urPair = std::pair<URTile,URTile>(prev,{*selectedTile_,pos, lvl_->currentLayer()}); urTiles_[pair] = urPair; } visited_.push_back(pos); for(auto &n : neighbours) neighbourCheck(n); }