// // LevelGenerate.hpp // auto_fill_jewel_v3 // // Created by Red on 2024/11/23. // 关卡生成类,包含生成盘子组合,然后填充宝石。 #ifndef LevelGenerate_hpp #define LevelGenerate_hpp #include #include using std::string; #include "contourdata.h" #include "FillGlobalConfig.hpp" #include "FillResult.hpp" #include "RandomGridFiller.hpp" #include using std::tuple; struct LevelGenerate { public: //盘子ID和层数 struct PlateIdAndLayerCnt { PlateIdAndLayerCnt():_plateId(-1),_layerCnt(0){} int _plateId ; int _layerCnt ; } ; public: LevelGenerate():_seed(11231627){} void setSeed(int s) { _seed = s ;} int getSeed() { return _seed ; } //盘子和宝石的组合有解返回true,反之返回false bool generate( FillGlobalConfig::LevelData levelData, const bool isMovable, vector>>>& resultPlateFillResults, vector& resultPlateCenterPointArr ) ; private: int _seed ; //根据难度数据和宝石总数计算需要使用的每个盘子的个数 /// @param difficulty 难度:0-普通,1-难,2-极难 /// @param totEquvSmallJewelCnt 全部等效小盘子数量 /// @return 返回盘子和层数的组合 vector generatePlateTypeAndLayerCnts(const int difficulty,const int totEquvSmallJewelCnt); //考虑可移动关卡的条件 vector generatePlateTypeAndLayerCnts2(const bool isMovable,const int difficulty,const int totEquvSmallJewelCnt); //判断一个组合是否恰恰装入宝石个数,规则是如果少一个盘就恰好装不下. bool isJustFilledAll2( const vector& plateCaps,//每个盘子的容量 const vector eachPlateLyrCnt,//对应盘子的层数 const int totSmlJewCnt) ; vector randIndices(const int count0 ) ; /// 随机从库存中取出needEquvSmlCnt个等效小宝石,取出的宝石从库存减掉 /// @param needEquvSmlCnt 需要取出的等价小宝石数量 /// @param unsolvedPercent 取出宝石的不可解百分比 /// @param jewStorages 库存数据,取出数据要从库存减去,key:jewId value:tuple /// @return 返回宝石ID和对应的数量 unordered_map randPickJewels( const int needEquvSmlCnt,const float solvedPercent, unordered_map>& jewStorages ) ; /// 填充一个盘子,用掉的宝石从库存减掉 vector fillPlateOneLayer(RandomGridFiller& filler,const int plateId, unordered_map& jewStoragesForUse ) ; /// 宝石尺寸转等效小宝石数量 int jewSz2SmlCnt(int sz) ; /// 查找库存剩余的宝石,返回 jewId,Cnt,并扣除库存数量 unordered_map findUnfilledInStorages(unordered_map>& jewStorages); /// 整理结果数据为 关卡-盘子-层-宝石的层次结构 void regroupPlateLyrFillResults( vector>>& pidlyrFillArray, vector>>>& results ) ; /// 摆放盘子 void placePlates(const bool movable, const vector& plateIdArr, vector& resultPlateCenterPointArr ) ; } ; #endif /* LevelGenerate_hpp */