LevelGenerate.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // LevelGenerate.hpp
  3. // auto_fill_jewel_v3
  4. //
  5. // Created by Red on 2024/11/23.
  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. const bool isMovable,
  33. vector<tuple<int,vector<vector<FillResult>>>>& resultPlateFillResults,
  34. vector<ContourData::Point>& resultPlateCenterPointArr
  35. ) ;
  36. private:
  37. int _seed ;
  38. //根据难度数据和宝石总数计算需要使用的每个盘子的个数
  39. /// @param difficulty 难度:0-普通,1-难,2-极难
  40. /// @param totEquvSmallJewelCnt 全部等效小盘子数量
  41. /// @return 返回盘子和层数的组合
  42. vector<PlateIdAndLayerCnt> generatePlateTypeAndLayerCnts(const int difficulty,const int totEquvSmallJewelCnt);
  43. //考虑可移动关卡的条件
  44. vector<PlateIdAndLayerCnt> generatePlateTypeAndLayerCnts2(const bool isMovable,const int difficulty,const int totEquvSmallJewelCnt);
  45. //判断一个组合是否恰恰装入宝石个数,规则是如果少一个盘就恰好装不下.
  46. bool isJustFilledAll2(
  47. const vector<int>& plateCaps,//每个盘子的容量
  48. const vector<int> eachPlateLyrCnt,//对应盘子的层数
  49. const int totSmlJewCnt) ;
  50. vector<int> randIndices(const int count0 ) ;
  51. /// 随机从库存中取出needEquvSmlCnt个等效小宝石,取出的宝石从库存减掉
  52. /// @param needEquvSmlCnt 需要取出的等价小宝石数量
  53. /// @param unsolvedPercent 取出宝石的不可解百分比
  54. /// @param jewStorages 库存数据,取出数据要从库存减去,key:jewId value:tuple<Sz,Cnt>
  55. /// @return 返回宝石ID和对应的数量
  56. unordered_map<int, int> randPickJewels( const int needEquvSmlCnt,const float solvedPercent, unordered_map<int,tuple<int,int>>& jewStorages ) ;
  57. /// 填充一个盘子,用掉的宝石从库存减掉
  58. vector<FillResult> fillPlateOneLayer(RandomGridFiller& filler,const int plateId, unordered_map<int,int>& jewStoragesForUse ) ;
  59. /// 宝石尺寸转等效小宝石数量
  60. int jewSz2SmlCnt(int sz) ;
  61. /// 查找库存剩余的宝石,返回 jewId,Cnt,并扣除库存数量
  62. unordered_map<int, int> findUnfilledInStorages(unordered_map<int,tuple<int,int>>& jewStorages);
  63. /// 整理结果数据为 关卡-盘子-层-宝石的层次结构
  64. void regroupPlateLyrFillResults( vector<tuple<int,int,vector<FillResult>>>& pidlyrFillArray, vector<tuple<int,vector<vector<FillResult>>>>& results ) ;
  65. /// 摆放盘子
  66. void placePlates(const bool movable, const vector<int>& plateIdArr, vector<ContourData::Point>& resultPlateCenterPointArr ) ;
  67. } ;
  68. #endif /* LevelGenerate_hpp */