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