Skip to content

Commit

Permalink
Merge branch 'dev' into FinishRoomCaseRuleAttempt
Browse files Browse the repository at this point in the history
  • Loading branch information
cadogs authored Apr 2, 2024
2 parents f4f7e90 + e519c8e commit d5bd9a9
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import edu.rpi.legup.puzzle.lightup.LightUpCell;
import edu.rpi.legup.puzzle.lightup.LightUpCellType;
import edu.rpi.legup.puzzle.lightup.rules.FinishWithBulbsDirectRule;
import java.awt.*;
import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -188,8 +189,29 @@ public String checkRuleRaw(TreeTransition transition) {
for (LightUpCell c : spots) {
ArrayList<Board> cases = getCases(parent.getBoard(), c);

// We will allow case rules to have only one option
if (cases.size() == childTransitions.size() && cases.size() >= 1) {
// Note: we will allow case rules to have only one option

// Some error checking to make sure that weird stuff doesn't happen
// if this case rule is incorrectly used to justify changes on the
// puzzle board
if (cases.size() == childTransitions.size() && cases.size() == 1) {
TreeTransition childTransition = childTransitions.get(0);

// If there is only 1 case, then this case rule should function no
// differently than the Finish With Bulbs Direct Rule
FinishWithBulbsDirectRule finishWithBulbs = new FinishWithBulbsDirectRule();
childTransition.setRule(finishWithBulbs);
boolean isCorrect = childTransition.isCorrect();

// Changes the transition back to this case rule
childTransition.setRule(this);

if (isCorrect) {
return null;
}
return super.getInvalidUseOfRuleMessage();
}
else if (cases.size() == childTransitions.size() && cases.size() > 1) {
boolean foundSpot = true;
for (TreeTransition childTrans : childTransitions) {
LightUpBoard actCase = (LightUpBoard) childTrans.getBoard();
Expand All @@ -206,7 +228,7 @@ public String checkRuleRaw(TreeTransition transition) {
LightUpCell posCell = (LightUpCell) posEle;
if (actCell.getType() == posCell.getType()
&& actCell.getLocation()
.equals(posCell.getLocation())) {
.equals(posCell.getLocation())) {
foundCell = true;
break;
}
Expand Down

0 comments on commit d5bd9a9

Please sign in to comment.