FillGlobalConfig.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. //
  2. // FillGlobalConfig.cpp
  3. // auto_fill_jewel_v3
  4. //
  5. // Created by Red on 2024/11/25.
  6. //
  7. #include "FillGlobalConfig.hpp"
  8. using namespace ArduinoJson;
  9. #include <fstream>
  10. using std::ifstream;
  11. #include <boost/algorithm/string.hpp>
  12. FillGlobalConfig* FillGlobalConfig::_s_instance = nullptr ;
  13. bool FillGlobalConfig::init(string filename)
  14. {
  15. // _plateContours.clear();
  16. // _jewelContours.clear() ;
  17. // ifstream ifs( filename.c_str() );
  18. // if( ifs.good()==false ) return false ;
  19. // DynamicJsonBuffer buffer ;
  20. // JsonObject& root = buffer.parse(ifs) ;
  21. // string platedir = root["plate_contour_dir"].as<char*>() ;
  22. // string jeweldir = root["jewel_contour_dir"].as<char*>() ;
  23. // JsonArray& parr =root["plate_names"].as<JsonArray>() ;
  24. // JsonArray& jarr =root["jewel_names"].as<JsonArray>() ;
  25. // _plateContours.resize(parr.size());
  26. // _jewelContours.resize(jarr.size());
  27. //
  28. // for(int i=0;i<parr.size();++i ) {
  29. // string name1 = parr[i].as<char*>() ;
  30. // string fullname1 = platedir + name1 ;
  31. // _plateContours[i]._name = name1 ;
  32. // _plateContours[i]._contour.readFromJsonFile(fullname1) ;
  33. // }
  34. // for(int i=0;i<jarr.size();++i ) {
  35. // string name1 = jarr[i].as<char*>() ;
  36. // string fullname1 = jeweldir + name1 ;
  37. // _jewelContours[i]._name = name1 ;
  38. // _jewelContours[i]._contour.readFromJsonFile(fullname1) ;
  39. // }
  40. return true;
  41. }
  42. FillGlobalConfig* FillGlobalConfig::getInstance()
  43. {
  44. if( _s_instance == nullptr ) {
  45. _s_instance = new FillGlobalConfig ;
  46. //_s_instance->init("config.json") ;
  47. _s_instance->initJewelItems("sg_jewel_items.csv") ;
  48. _s_instance->initLevelDatas("sg_level_data.csv") ;
  49. _s_instance->initPlateItems("sg_plate_items.csv") ;
  50. _s_instance->initMoveConfigDatas("sg_move_config_data.csv") ;
  51. _s_instance->initGridBoxDatas("sg_gridbox_positions.csv") ;
  52. }
  53. return _s_instance ;
  54. }
  55. ContourData* FillGlobalConfig::getContourDataByPngName(string& pngname)
  56. {
  57. for(auto it = _jewelContours.begin(); it!=_jewelContours.end();++it ) {
  58. if( it->_name.find(pngname) != string::npos ) {
  59. return &(it->_contour) ;
  60. }
  61. }
  62. return nullptr ;
  63. }
  64. bool FillGlobalConfig::initJewelItems( string filename )
  65. {
  66. _mapJewelItems.clear() ;
  67. ifstream ifs( filename.c_str() ) ;
  68. if( ifs.good()==false ) return false ;
  69. string line ;
  70. //跳过第一行
  71. std::getline(ifs, line) ;
  72. vector<string> tokens ;
  73. while( std::getline(ifs, line) ) {
  74. if( line.length() > 2 ) {
  75. tokens.clear() ;
  76. boost::split(tokens, line, boost::is_any_of(","));
  77. if( tokens.size()>=13 ) {
  78. JewelItem ji ;
  79. ji._id = atof(tokens[0].c_str()) ;
  80. ji._category = tokens[1] ;
  81. ji._jewelName = tokens[2] ;
  82. ji._code1 = tokens[3] ;
  83. ji._code2 = tokens[4] ;
  84. ji._size = (tokens[5].compare("SM")==0)?FILLGLOBALCONFIG_JEWELSIZE_SM:((tokens[5].compare("MD")==0)?FILLGLOBALCONFIG_JEWELSIZE_MD:FILLGLOBALCONFIG_JEWELSIZE_LG) ;
  85. ji._scale = atof( tokens[6].c_str() ) ;
  86. ji._pngName = tokens[7] ;
  87. ji._yzName = tokens[8] ;
  88. ji._contourName = tokens[9] ;
  89. ji._bbWidth = atof( tokens[10].c_str() ) ;
  90. ji._bbHeight = atof( tokens[11].c_str() ) ;
  91. ji._etc = tokens[12] ;
  92. _mapJewelItems[ji._id] = ji ;
  93. }
  94. }
  95. }
  96. return true ;
  97. }
  98. bool FillGlobalConfig::initLevelDatas( string filename )
  99. {
  100. _mapLevelDatas.clear() ;
  101. ifstream ifs( filename.c_str() ) ;
  102. if( ifs.good()==false ) return false ;
  103. string line ;
  104. //跳过第一行
  105. std::getline(ifs, line) ;
  106. LevelData tempLevelData ;
  107. tempLevelData._id = -1 ;//初始化
  108. vector<string> tokens ;
  109. while( std::getline(ifs, line) ) {
  110. bool isDataLine = false;
  111. if( line.length() > 2 ) {
  112. tokens.clear() ;
  113. boost::split(tokens, line, boost::is_any_of(","));
  114. if( tokens.size()>=6 ) {
  115. isDataLine = true ;
  116. int lid = atof(tokens[0].c_str()) ;
  117. int subid = atof(tokens[1].c_str()) ;
  118. int difficulty = atof(tokens[2].c_str()) ;
  119. int jewId = atof(tokens[3].c_str()) ;
  120. string jewSz = tokens[4]; //ignored
  121. int grpcnt = atof( tokens[5].c_str() ) ;
  122. if( tempLevelData._id == -1 ) {
  123. tempLevelData._id = lid ;
  124. tempLevelData._subId = subid ;
  125. tempLevelData._difficulty = difficulty ;
  126. }
  127. tempLevelData._jewelIds.push_back(jewId) ;
  128. tempLevelData._cnts.push_back(grpcnt*3) ;
  129. }
  130. }
  131. if( isDataLine==false )
  132. {
  133. //出现空行, 记录临时关卡
  134. if( tempLevelData._id>0 ) {
  135. _mapLevelDatas[tempLevelData._id].push_back(tempLevelData) ;
  136. }
  137. //清空临时关卡数据
  138. tempLevelData._id = -1 ;
  139. tempLevelData._subId = -1 ;
  140. tempLevelData._difficulty = -1;
  141. tempLevelData._cnts.clear() ;
  142. tempLevelData._jewelIds.clear() ;
  143. }
  144. }
  145. //最后一个临时对象是否是有效关卡数据
  146. if( tempLevelData._id>0 ) {
  147. _mapLevelDatas[tempLevelData._id].push_back(tempLevelData) ;
  148. tempLevelData._id = -1 ;
  149. tempLevelData._cnts.clear() ;
  150. tempLevelData._jewelIds.clear() ;
  151. }
  152. return true ;
  153. }
  154. bool FillGlobalConfig::initPlateItems( string filename )
  155. {
  156. _mapPlateItems.clear() ;
  157. _mapPlateIdArray.clear() ;
  158. ifstream ifs( filename.c_str() ) ;
  159. if( ifs.good()==false ) return false ;
  160. string line ;
  161. //跳过第一行
  162. std::getline(ifs, line) ;
  163. vector<string> tokens ;
  164. while( std::getline(ifs, line) ) {
  165. if( line.length() > 2 ) {
  166. tokens.clear() ;
  167. boost::split(tokens, line, boost::is_any_of(","));
  168. if( tokens.size()>=13 ) {
  169. PlateItem pi ;
  170. pi._id = atof(tokens[0].c_str()) ;
  171. pi._name = tokens[1] ;
  172. int sz = 0 ;
  173. string szStr = tokens[2] ;
  174. //if( szStr.compare("SM")==0 ) sz = FILLGLOBALCONFIG_PLATESIZE_SM ;
  175. if( szStr.compare("MD")==0 ) sz = FILLGLOBALCONFIG_PLATESIZE_MD;
  176. else if( szStr.compare("LG")==0 ) sz = FILLGLOBALCONFIG_PLATESIZE_LG;
  177. else continue; //无效盘子跳过
  178. pi._size = sz ;
  179. pi._pngName = tokens[3] ;
  180. pi._contourName = tokens[4] ;
  181. pi._blx = atof( tokens[5].c_str() ) ;//bottom left
  182. pi._bly = atof( tokens[6].c_str() ) ;
  183. pi._trx = atof( tokens[7].c_str() ) ;//top right
  184. pi._try = atof( tokens[8].c_str() ) ;
  185. pi._bigJewCap = atof( tokens[9].c_str() ) ;
  186. pi._bbwid = atof( tokens[10].c_str()) ;
  187. pi._bbhei = atof( tokens[11].c_str()) ;
  188. pi._heng = atof( tokens[12].c_str()) ;
  189. _mapPlateItems[pi._id] = pi ;
  190. _mapPlateIdArray[sz].push_back(pi._id) ;
  191. }
  192. }
  193. }
  194. return true ;
  195. }
  196. bool FillGlobalConfig::initMoveConfigDatas( string filename )
  197. {
  198. _mapMoveConfigDatas.clear() ;
  199. ifstream ifs( filename.c_str() ) ;
  200. if( ifs.good()==false ) return false ;
  201. string line ;
  202. //跳过第一行
  203. std::getline(ifs, line) ;
  204. vector<string> tokens ;
  205. while( std::getline(ifs, line) ) {
  206. if( line.length() > 2 ) {
  207. tokens.clear() ;
  208. boost::split(tokens, line, boost::is_any_of(","));
  209. if( tokens.size()>=9 ) {
  210. MoveConfig mhc ;
  211. mhc._id = atof( tokens[0].c_str() ) ;
  212. mhc._type = tokens[1] ;
  213. mhc._lowestEquvSmlJewelCnt = atof( tokens[2].c_str() ) ;
  214. mhc._nLayer = atof( tokens[3].c_str() ) ;
  215. mhc._midPlateCntH = atof( tokens[4].c_str() ) ;
  216. mhc._midPlateCntV = atof( tokens[5].c_str() ) ;
  217. mhc._bigPlateCntH = atof( tokens[6].c_str() ) ;
  218. mhc._bigPlateCntV = atof( tokens[7].c_str() ) ;
  219. mhc._hard = atof( tokens[8].c_str() ) ;
  220. _mapMoveConfigDatas[mhc._id] = mhc ;
  221. }
  222. }
  223. }
  224. return true ;
  225. }
  226. bool FillGlobalConfig::initGridBoxDatas(string filename)
  227. {
  228. _mapGridBoxDatas.clear() ;
  229. ifstream ifs( filename.c_str() ) ;
  230. if( ifs.good()==false ) return false ;
  231. string line ;
  232. //跳过第一行
  233. std::getline(ifs, line) ;
  234. vector<string> tokens ;
  235. while( std::getline(ifs, line) ) {
  236. if( line.length() > 2 ) {
  237. tokens.clear() ;
  238. boost::split(tokens, line, boost::is_any_of(","));
  239. if( tokens.size()>=11 ) {
  240. GridBoxCell gbc ;
  241. gbc._name = tokens[0] ;
  242. gbc._move = atof( tokens[1].c_str() ) ;
  243. gbc._bigIndex = atof( tokens[2].c_str() ) ;
  244. gbc._mid1Index = atof( tokens[3].c_str() ) ;
  245. gbc._mid2Index = atof( tokens[4].c_str() ) ;
  246. gbc._bigllx = atof( tokens[5].c_str() ) ;
  247. gbc._biglly = atof( tokens[6].c_str() ) ;
  248. gbc._mid1llx = atof( tokens[7].c_str() ) ;
  249. gbc._mid1lly = atof( tokens[8].c_str() ) ;
  250. gbc._mid2llx = atof( tokens[9].c_str() ) ;
  251. gbc._mid2lly = atof( tokens[10].c_str() ) ;
  252. gbc._bigFilled = false;
  253. gbc._mid1Filled = false;
  254. gbc._mid2Filled = false ;
  255. _mapGridBoxDatas[gbc._name].push_back(gbc);
  256. }
  257. }
  258. }
  259. return true ;
  260. }
  261. vector<FillGlobalConfig::MoveConfig*> FillGlobalConfig::getSecondRoundMoveConfigDatas(int equvSmCnt)
  262. {
  263. vector<FillGlobalConfig::MoveConfig*> res ;
  264. FillGlobalConfig* fgc = FillGlobalConfig::getInstance() ;
  265. if( 96 <= equvSmCnt && equvSmCnt < 144 ) {
  266. vector<MoveConfig*> tarr = getMoveConfigDatasByTypeAndNLayers("A", 2) ;
  267. for(auto m:tarr) res.push_back(m) ;
  268. }else if( 144<= equvSmCnt && equvSmCnt < 192 ) {
  269. vector<MoveConfig*> tarr = getMoveConfigDatasByTypeAndNLayers("A", 2) ;
  270. for(auto m:tarr) res.push_back(m) ;
  271. vector<MoveConfig*> tarr1 = getMoveConfigDatasByTypeAndNLayers("A", 3) ;
  272. for(auto m:tarr1) res.push_back(m) ;
  273. vector<MoveConfig*> tarr2 = getMoveConfigDatasByTypeAndNLayers("B", 2) ;
  274. for(auto m:tarr2) res.push_back(m) ;
  275. }else if( 192<=equvSmCnt && equvSmCnt < 216 ) {
  276. vector<MoveConfig*> tarr = getMoveConfigDatasByTypeAndNLayers("A", 2) ;
  277. for(auto m:tarr) res.push_back(m) ;
  278. vector<MoveConfig*> tarr1 = getMoveConfigDatasByTypeAndNLayers("A", 3) ;
  279. for(auto m:tarr1) res.push_back(m) ;
  280. vector<MoveConfig*> tarr2 = getMoveConfigDatasByTypeAndNLayers("B", 2) ;
  281. for(auto m:tarr2) res.push_back(m) ;
  282. vector<MoveConfig*> tarr3 = getMoveConfigDatasByTypeAndNLayers("C", 2) ;
  283. for(auto m:tarr3) res.push_back(m) ;
  284. }else if( 216<= equvSmCnt && equvSmCnt < 288 ) {
  285. vector<MoveConfig*> tarr = getMoveConfigDatasByTypeAndNLayers("A", 2) ;
  286. for(auto m:tarr) res.push_back(m) ;
  287. vector<MoveConfig*> tarr1 = getMoveConfigDatasByTypeAndNLayers("A", 3) ;
  288. for(auto m:tarr1) res.push_back(m) ;
  289. vector<MoveConfig*> tarr2 = getMoveConfigDatasByTypeAndNLayers("B", 2) ;
  290. for(auto m:tarr2) res.push_back(m) ;
  291. vector<MoveConfig*> tarr3 = getMoveConfigDatasByTypeAndNLayers("B", 3) ;
  292. for(auto m:tarr3) res.push_back(m) ;
  293. vector<MoveConfig*> tarr4 = getMoveConfigDatasByTypeAndNLayers("C", 2) ;
  294. for(auto m:tarr4) res.push_back(m) ;
  295. }else if( 288 <= equvSmCnt ) {
  296. vector<MoveConfig*> tarr = getMoveConfigDatasByTypeAndNLayers("A", 2) ;
  297. for(auto m:tarr) res.push_back(m) ;
  298. vector<MoveConfig*> tarr1 = getMoveConfigDatasByTypeAndNLayers("A", 3) ;
  299. for(auto m:tarr1) res.push_back(m) ;
  300. vector<MoveConfig*> tarr2 = getMoveConfigDatasByTypeAndNLayers("B", 2) ;
  301. for(auto m:tarr2) res.push_back(m) ;
  302. vector<MoveConfig*> tarr3 = getMoveConfigDatasByTypeAndNLayers("B", 3) ;
  303. for(auto m:tarr3) res.push_back(m) ;
  304. vector<MoveConfig*> tarr4 = getMoveConfigDatasByTypeAndNLayers("C", 2) ;
  305. for(auto m:tarr4) res.push_back(m) ;
  306. vector<MoveConfig*> tarr5 = getMoveConfigDatasByTypeAndNLayers("C", 3) ;
  307. for(auto m:tarr5) res.push_back(m) ;
  308. }
  309. return res ;
  310. }
  311. vector<FillGlobalConfig::MoveConfig*> FillGlobalConfig::getFirstRoundMoveConfigDatas(int equvSmCnt)
  312. {
  313. vector<FillGlobalConfig::MoveConfig*> res ;
  314. FillGlobalConfig* fgc = FillGlobalConfig::getInstance() ;
  315. if( equvSmCnt < 48 ) {
  316. return res ;//empty
  317. }else if( 48<=equvSmCnt && equvSmCnt<96 ) {
  318. res = getMoveConfigDatasByTypeAndNLayers("A", 1) ;
  319. }else if( 96<=equvSmCnt && equvSmCnt<144 ) {
  320. res = getMoveConfigDatasByTypeAndNLayers("A", 2) ;
  321. }else if( 144<= equvSmCnt && equvSmCnt < 192 ) {
  322. vector<FillGlobalConfig::MoveConfig*> tarr1 = getMoveConfigDatasByTypeAndNLayers("A", 2) ;
  323. vector<FillGlobalConfig::MoveConfig*> tarr2 = getMoveConfigDatasByTypeAndNLayers("A", 3) ;
  324. vector<FillGlobalConfig::MoveConfig*> tarr3 = getMoveConfigDatasByTypeAndNLayers("B", 2) ;
  325. for(auto mc:tarr1) res.push_back(mc) ;
  326. for(auto mc:tarr2) res.push_back(mc) ;
  327. for(auto mc:tarr3) res.push_back(mc) ;
  328. }else if( 192<=equvSmCnt && equvSmCnt<216 ) {
  329. vector<FillGlobalConfig::MoveConfig*> tarr1 = getMoveConfigDatasByTypeAndNLayers("A", 2) ;
  330. vector<FillGlobalConfig::MoveConfig*> tarr2 = getMoveConfigDatasByTypeAndNLayers("A", 3) ;
  331. vector<FillGlobalConfig::MoveConfig*> tarr3 = getMoveConfigDatasByTypeAndNLayers("B", 2) ;
  332. vector<FillGlobalConfig::MoveConfig*> tarr4 = getMoveConfigDatasByTypeAndNLayers("C", 2) ;
  333. for(auto mc:tarr1) res.push_back(mc) ;
  334. for(auto mc:tarr2) res.push_back(mc) ;
  335. for(auto mc:tarr3) res.push_back(mc) ;
  336. for(auto mc:tarr4) res.push_back(mc) ;
  337. }else if( 216<=equvSmCnt && equvSmCnt<288 ) {
  338. vector<FillGlobalConfig::MoveConfig*> tarr1 = getMoveConfigDatasByTypeAndNLayers("A", 2) ;
  339. vector<FillGlobalConfig::MoveConfig*> tarr2 = getMoveConfigDatasByTypeAndNLayers("A", 3) ;
  340. vector<FillGlobalConfig::MoveConfig*> tarr3 = getMoveConfigDatasByTypeAndNLayers("B", 2) ;
  341. vector<FillGlobalConfig::MoveConfig*> tarr4 = getMoveConfigDatasByTypeAndNLayers("C", 2) ;
  342. vector<FillGlobalConfig::MoveConfig*> tarr5 = getMoveConfigDatasByTypeAndNLayers("B", 3) ;
  343. for(auto mc:tarr1) res.push_back(mc) ;
  344. for(auto mc:tarr2) res.push_back(mc) ;
  345. for(auto mc:tarr3) res.push_back(mc) ;
  346. for(auto mc:tarr4) res.push_back(mc) ;
  347. for(auto mc:tarr5) res.push_back(mc) ;
  348. }else if( 288 <= equvSmCnt ) {
  349. vector<FillGlobalConfig::MoveConfig*> tarr1 = getMoveConfigDatasByTypeAndNLayers("A", 2) ;
  350. vector<FillGlobalConfig::MoveConfig*> tarr2 = getMoveConfigDatasByTypeAndNLayers("A", 3) ;
  351. vector<FillGlobalConfig::MoveConfig*> tarr3 = getMoveConfigDatasByTypeAndNLayers("B", 2) ;
  352. vector<FillGlobalConfig::MoveConfig*> tarr4 = getMoveConfigDatasByTypeAndNLayers("C", 2) ;
  353. vector<FillGlobalConfig::MoveConfig*> tarr5 = getMoveConfigDatasByTypeAndNLayers("B", 3) ;
  354. vector<FillGlobalConfig::MoveConfig*> tarr6 = getMoveConfigDatasByTypeAndNLayers("C", 3) ;
  355. for(auto mc:tarr1) res.push_back(mc) ;
  356. for(auto mc:tarr2) res.push_back(mc) ;
  357. for(auto mc:tarr3) res.push_back(mc) ;
  358. for(auto mc:tarr4) res.push_back(mc) ;
  359. for(auto mc:tarr5) res.push_back(mc) ;
  360. for(auto mc:tarr6) res.push_back(mc) ;
  361. }
  362. return res ;
  363. }
  364. vector<FillGlobalConfig::MoveConfig*> FillGlobalConfig::getMoveConfigDatasByTypeAndNLayers(string type,int nlayer)
  365. {
  366. vector<FillGlobalConfig::MoveConfig*> res ;
  367. FillGlobalConfig* fgc = FillGlobalConfig::getInstance() ;
  368. int cnt = fgc->getMoveConfigCount() ;
  369. for(int i = 0 ; i<cnt;++ i ) {
  370. MoveConfig* mhc = fgc->getMoveConfigDataByIndex(i) ;
  371. if( mhc->_type.find(type) != string::npos ) {
  372. if(mhc->_nLayer == nlayer ) {
  373. res.push_back( mhc ) ;
  374. }
  375. }
  376. }
  377. return res ;
  378. }
  379. vector<FillGlobalConfig::MultiMoveConfig> FillGlobalConfig::getAllMoveConfigByJewels(LevelData& levelData)
  380. {
  381. vector<FillGlobalConfig::MultiMoveConfig> res ;
  382. int equvSmJewelCnt = 0 ;
  383. for(int ij = 0 ; ij < levelData._jewelIds.size() ; ++ ij ) {
  384. int jid = levelData._jewelIds[ij] ;
  385. int cnt = levelData._cnts[ij] ;
  386. FillGlobalConfig::JewelItem* jewel = this->getJewelItemById(jid);
  387. if( jewel->_size == FILLGLOBALCONFIG_JEWELSIZE_LG ) {
  388. cnt=cnt*4 ;
  389. }else if(jewel->_size == FILLGLOBALCONFIG_JEWELSIZE_MD ) {
  390. cnt=cnt*2 ;
  391. }
  392. equvSmJewelCnt += cnt ;
  393. }
  394. if( equvSmJewelCnt == 0 ) return res ;//empty.
  395. //第一个可移动行
  396. vector<int> residueSmJewCnts ;//第一行剩余宝石
  397. vector<FillGlobalConfig::MoveConfig*> firstMoveConfigs = getFirstRoundMoveConfigDatas(equvSmJewelCnt) ;
  398. int num1 = firstMoveConfigs.size() ;//第一个移动行的可能方案
  399. for(int i1 = 0 ; i1 < num1 ; ++ i1 ) {
  400. FillGlobalConfig::MoveConfig* mc = firstMoveConfigs[i1] ;
  401. int res1 = equvSmJewelCnt - mc->_lowestEquvSmlJewelCnt ;
  402. vector<FillGlobalConfig::MoveConfig*> secondConfigs = getSecondRoundMoveConfigDatas(res1) ;
  403. bool secondAtLeasetHaveOneSolution = false ;
  404. if( secondConfigs.size()>0 ) {
  405. //存在第二移动行的情况
  406. for(int i2 = 0 ; i2 < secondConfigs.size(); ++ i2 ) {
  407. //第二行组合必须是 BA , CB , CA 这个顺序,也就是说第二行的字母ASCII值要小于等第一行的字母值
  408. if( secondConfigs[i2]->_type[0] <= mc->_type[0] ) {
  409. FillGlobalConfig::MultiMoveConfig mmc ;
  410. mmc._first = mc ;
  411. mmc._second = secondConfigs[i2] ;
  412. res.push_back(mmc) ;
  413. secondAtLeasetHaveOneSolution = true ;
  414. }
  415. }
  416. }
  417. if( secondAtLeasetHaveOneSolution==false )
  418. {
  419. //无二移动行的情况
  420. FillGlobalConfig::MultiMoveConfig mmc ;
  421. mmc._first = mc ;
  422. mmc._second = nullptr ;
  423. res.push_back(mmc) ;
  424. }
  425. }
  426. return res ;
  427. }
  428. FillGlobalConfig::PlateItem* FillGlobalConfig::getPlateItemBySzNDirection(int plateSzId,int heng)
  429. {
  430. if( _mapPlateIdArray.find(plateSzId) != _mapPlateIdArray.end() ) {
  431. vector<int>& idarr = _mapPlateIdArray[plateSzId] ;
  432. for(int ii = 0 ; ii < idarr.size();++ii ) {
  433. PlateItem* pi = this->getPlateItemById( idarr[ii] ) ;
  434. if( pi!=nullptr ) {
  435. if( pi->_heng == heng ) {
  436. return pi ;
  437. }
  438. }
  439. }
  440. return nullptr ;
  441. }else{
  442. return nullptr;
  443. }
  444. }
  445. void FillGlobalConfig::clearGridBoxFilledStatus()
  446. {
  447. for(auto it = _mapGridBoxDatas.begin(); it!=_mapGridBoxDatas.end();++it ) {
  448. vector<GridBoxCell>& arr = it->second ;
  449. for(auto itg = arr.begin(); itg != arr.end(); ++ itg ) {
  450. itg->_bigFilled = false ;
  451. itg->_mid1Filled = false;
  452. itg->_mid2Filled = false ;
  453. }
  454. }
  455. }
  456. FillGlobalConfig::GridBoxCell* FillGlobalConfig::getLowestUnfilledGridBox(string name,const int moveid,const int iPlateSiz,ContourData::Point& retPositionLL)
  457. {
  458. if( name.compare("")==0 ) name = "NN" ;
  459. int index = 9999 ;
  460. GridBoxCell* res = nullptr ;
  461. if( _mapGridBoxDatas.find(name) == _mapGridBoxDatas.end() ) {
  462. //如果没找到组合,那么把字母反过来组合
  463. string name2 ;
  464. for(int ic = 0 ;ic<name.length();++ic ) {
  465. name2 += name[name.length()-1-ic] ;
  466. }
  467. name = name2 ;
  468. }
  469. if( _mapGridBoxDatas.find(name) != _mapGridBoxDatas.end() ) {
  470. vector<GridBoxCell>& arr = _mapGridBoxDatas[name] ;
  471. for(int ig = 0 ; ig < arr.size(); ++ ig ) {
  472. GridBoxCell& gbc = arr[ig] ;
  473. if( gbc._move == moveid ) {
  474. if( iPlateSiz == FILLGLOBALCONFIG_PLATESIZE_LG ) {
  475. if( gbc._bigIndex!=-1 && (gbc._bigFilled==false && gbc._mid1Filled == false&& gbc._mid2Filled == false ) && gbc._bigIndex < index ) {
  476. index = gbc._bigIndex ;
  477. res = &gbc ;
  478. retPositionLL.x = gbc._bigllx ;
  479. retPositionLL.y = gbc._biglly ;
  480. }
  481. }else { // FILLGLOBALCONFIG_PLATESIZE_MD
  482. if( gbc._mid1Index != -1 &&(gbc._bigFilled==false && gbc._mid1Filled == false ) && gbc._mid1Index < index ) {
  483. index = gbc._mid1Index ;
  484. res = &gbc ;
  485. retPositionLL.x = gbc._mid1llx ;
  486. retPositionLL.y = gbc._mid1lly ;
  487. }
  488. if( gbc._mid2Index != -1 &&(gbc._bigFilled==false && gbc._mid2Filled == false ) && gbc._mid2Index < index ) {
  489. index = gbc._mid2Index ;
  490. res = &gbc ;
  491. retPositionLL.x = gbc._mid2llx ;
  492. retPositionLL.y = gbc._mid2lly ;
  493. }
  494. }
  495. }
  496. }
  497. }
  498. return res ;
  499. }
  500. void FillGlobalConfig::setFilled( GridBoxCell* gbc , const int iPlateSiz )
  501. {
  502. if( iPlateSiz == FILLGLOBALCONFIG_PLATESIZE_LG ) {
  503. gbc->_bigFilled = true ;
  504. }else {
  505. if( gbc->_mid1Index != -1 && gbc->_mid1Filled == false ) {
  506. gbc->_mid1Filled = true ;
  507. }else if( gbc->_mid2Index!=-1 && gbc->_mid2Filled==false ) {
  508. gbc->_mid2Filled = true ;
  509. }
  510. }
  511. }