@@ -125,8 +125,10 @@ void SokoGenerator::generateLevel(int roomWidth, int roomHeight, int noOfBoxes,
125
125
if (generationSuccessful) generationSuccessful = placePlayer (newLevel, _roomW, _roomH);
126
126
if (generationSuccessful){
127
127
level lvl = LevelToCLevel (newLevel);
128
+ struct solution sol;
128
129
qDebug () << " Generation Started: " ;
129
- generationSuccessful = solver.solve (lvl, timeout);
130
+ generationSuccessful = solver.solve (lvl, timeout, sol);
131
+ if (generationSuccessful) newLevel.solution = cSolToString (sol);
130
132
qDebug () << " Generation Successful: " << generationSuccessful;
131
133
}
132
134
}
@@ -345,7 +347,7 @@ bool SokoGenerator::placeGoalsAndBoxes(SokoGenerator::Level &level, int roomWidt
345
347
}
346
348
}
347
349
else if (level.grid [yCoord][xCoord] == GOAL){
348
- if (neighbourCheck (level, yCoord, xCoord)){
350
+ if (neighbourCheck (level, yCoord, xCoord) && boxCount < noOfBoxes- 1 ){
349
351
level.grid [yCoord][xCoord] = BOXONGOAL;
350
352
boxCount++;
351
353
}
@@ -438,8 +440,10 @@ void SokoGenerator::regenerateLevel(int lvlNum){
438
440
if (generationSuccessful) placePlayer (newLevel, _roomW, _roomH);
439
441
if (generationSuccessful){
440
442
level lvl = LevelToCLevel (newLevel);
443
+ struct solution sol;
441
444
qDebug () << " Generation Started: " ;
442
- generationSuccessful = solver.solve (lvl, timeout);
445
+ generationSuccessful = solver.solve (lvl, timeout, sol);
446
+ if (generationSuccessful) newLevel.solution = cSolToString (sol);
443
447
qDebug () << " Generation Successful: " << generationSuccessful;
444
448
}
445
449
}
@@ -507,3 +511,16 @@ bool SokoGenerator::isTimeout(clock_t start, float timeout){
507
511
508
512
return false ;
509
513
}
514
+
515
+ string SokoGenerator::cSolToString (struct solution sol){
516
+ string characters = " ludrLUDR" ;
517
+ string solution;
518
+ for (int i = 0 ; i < MAXSOLUTION; i++){
519
+ char sChar = sol.move [i];
520
+ if (characters.find (sChar ) != string::npos){
521
+ solution += sChar ;
522
+ }
523
+ }
524
+
525
+ return solution;
526
+ }
0 commit comments