LevelGenerate.hpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // LevelGenerate.hpp
  3. // Test
  4. //
  5. // Created by 高慕白 on 2024/12/3.
  6. //
  7. #ifndef LevelGenerate_hpp
  8. #define LevelGenerate_hpp
  9. #include <stdio.h>
  10. #include <string>
  11. using std::string;
  12. #include "contourdata.h"
  13. #include "FillGlobalConfig.hpp"
  14. #include "FillResult.hpp"
  15. #include "RandomGridFiller.hpp"
  16. #include <tuple>
  17. using std::tuple;
  18. struct LevelGenerate {
  19. public:
  20. //盘子ID和层数
  21. struct PlateIdAndLayerCnt {
  22. PlateIdAndLayerCnt():_plateId(-1),_layerCnt(0){}
  23. int _plateId ;
  24. int _layerCnt ;
  25. } ;
  26. public:
  27. LevelGenerate():_seed(11231627){}
  28. void setSeed(int s) { _seed = s ;}
  29. int getSeed() { return _seed ; }
  30. //盘子和宝石的组合有解返回true,反之返回false
  31. bool generate( FillGlobalConfig::LevelData levelData,
  32. vector<tuple<int,vector<vector<FillResult>>>>& resultPlateFillResults,
  33. vector<ContourData::Point>& resultPlateCenterPointArr
  34. ) ;
  35. private:
  36. int _seed ;
  37. //根据难度数据和宝石总数计算需要使用的每个盘子的个数
  38. vector<PlateIdAndLayerCnt> generatePlateTypeAndLayerCnts(const int difficulty,const int totEquvSmallJewelCnt);
  39. //判断一个组合是否恰恰装入宝石个数,规则是如果少一个盘就恰好装不下.
  40. bool isJustFilledAll2(
  41. const vector<int>& plateCaps,//每个盘子的容量
  42. const vector<int> eachPlateLyrCnt,//对应盘子的层数
  43. const int totSmlJewCnt) ;
  44. vector<int> randIndices(const int count0 ) ;
  45. /// 随机从库存中取出needEquvSmlCnt个等效小宝石,取出的宝石从库存减掉
  46. /// @param needEquvSmlCnt 需要取出的等价小宝石数量
  47. /// @param unsolvedPercent 取出宝石的不可解百分比
  48. /// @param jewStorages 库存数据,取出数据要从库存减去,key:jewId value:tuple<Sz,Cnt>
  49. /// @return 返回宝石ID和对应的数量
  50. unordered_map<int, int> randPickJewels( const int needEquvSmlCnt,const float solvedPercent, unordered_map<int,tuple<int,int>>& jewStorages ) ;
  51. /// 填充一个盘子,用掉的宝石从库存减掉
  52. vector<FillResult> fillPlateOneLayer(RandomGridFiller& filler,const int plateId, unordered_map<int,int>& jewStoragesForUse ) ;
  53. /// 宝石尺寸转等效小宝石数量
  54. int jewSz2SmlCnt(int sz) ;
  55. /// 查找库存剩余的宝石,返回 jewId,Cnt,并扣除库存数量
  56. unordered_map<int, int> findUnfilledInStorages(unordered_map<int,tuple<int,int>>& jewStorages);
  57. /// 整理结果数据为 关卡-盘子-层-宝石的层次结构
  58. void regroupPlateLyrFillResults( vector<tuple<int,int,vector<FillResult>>>& pidlyrFillArray, vector<tuple<int,vector<vector<FillResult>>>>& results ) ;
  59. /// 摆放盘子
  60. void placePlates( const vector<int>& plateIdArr, vector<ContourData::Point>& resultPlateCenterPointArr ) ;
  61. } ;
  62. #endif /* LevelGenerate_hpp */