Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 555 bug fix: bizarre Satisfy Number behavior #755

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
Loading