diff --git a/src/main/java/edu/rpi/legup/puzzle/binary/rules/OneOrZeroCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/binary/rules/OneOrZeroCaseRule.java index 21f0b3cbb..192317e9f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/binary/rules/OneOrZeroCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/binary/rules/OneOrZeroCaseRule.java @@ -23,7 +23,7 @@ public OneOrZeroCaseRule() { @Override public String checkRuleRaw(TreeTransition transition) { - List childTransitions = transition.getParents().get(3).getChildren(); + List childTransitions = transition.getParents().get(0).getChildren(); if (childTransitions.size() != 2) { return super.getInvalidUseOfRuleMessage() + ": This case rule must have 2 children."; } diff --git a/src/main/java/edu/rpi/legup/puzzle/binary/rules/SurroundPairDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/binary/rules/SurroundPairDirectRule.java index 232870977..7e0caff73 100644 --- a/src/main/java/edu/rpi/legup/puzzle/binary/rules/SurroundPairDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/binary/rules/SurroundPairDirectRule.java @@ -21,7 +21,26 @@ public SurroundPairDirectRule() { @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; + BinaryBoard board = (BinaryBoard) transition.getBoard(); + BinaryBoard origBoard = (BinaryBoard) transition.getParents().get(0).getBoard(); + ContradictionRule contraRule = new ThreeAdjacentContradictionRule(); + + + BinaryCell cell = (BinaryCell) board.getPuzzleElement(puzzleElement); + + if (cell.getType() == BinaryType.UNKNOWN) { + return "Only ONE or ZERO cells are allowed for this rule!"; + } + + BinaryBoard modified = origBoard.copy(); + modified.getPuzzleElement(puzzleElement).setData(BinaryType.WHITE.toValue()); + if (contraRule.checkContradictionAt(modified, puzzleElement) != null) { + return "Black cells must be placed in a region of black cells!"; + } + return null; + + return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE; + } @Override