Skip to content

Commit

Permalink
Merge pull request #370 from N-Desmarais/Short-Truth-Table-351
Browse files Browse the repository at this point in the history
Short truth table 351

Merging, fixes #351
  • Loading branch information
Chase-Grajeda authored Nov 15, 2022
2 parents 57094f9 + 3d4ddf7 commit 2e1a689
Showing 1 changed file with 22 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,29 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) {
return super.getInvalidUseOfRuleMessage() + ": Only assigned cells are allowed for basic rules";
}

if (this.ELIMINATION_RULE) {
// Strategy: If this is an elimination rule, simply check if there is a contradiction at the specified statement

// This gets the operator of the parent statement, which is what we need for checking the contradiction
PuzzleElement checkElement = cell.getStatementReference().getParentStatement().getCell();

String contradictionMessage = CORRESPONDING_CONTRADICTION_RULE.checkContradictionAt(board, checkElement);
if (contradictionMessage != null) {
if (contradictionMessage.startsWith(CORRESPONDING_CONTRADICTION_RULE.getNoContradictionMessage())) {
return null;
}
else {
return super.getInvalidUseOfRuleMessage() + ": " + contradictionMessage;
}
}
else {
return super.getInvalidUseOfRuleMessage();
}
}
else {
// Strategy: Negate the modified cell and check if there is a contradiction. If there is one, then the
// original statement must be true. If there isn't one, then the original statement must be false.

ShortTruthTableBoard modifiedBoard = board.copy();
((ShortTruthTableCell) modifiedBoard.getPuzzleElement(element)).setType(cell.getType().getNegation());

String contradictionMessage = CORRESPONDING_CONTRADICTION_RULE.checkContradictionAt(modifiedBoard, element);
if (contradictionMessage == null) { // A contradiction exists in the modified statement; this is good!
return null;
}
return super.getInvalidUseOfRuleMessage() + ": " + contradictionMessage;
// Strategy: Negate the modified cell and check if there is a contradiction. If there is one, then the
// original statement must be true. If there isn't one, then the original statement must be false.

ShortTruthTableBoard modifiedBoard = board.copy();

PuzzleElement checkElement =
this.ELIMINATION_RULE
? cell.getStatementReference().getParentStatement().getCell()
: element;

ShortTruthTableCell checkCell =
this.ELIMINATION_RULE
? (ShortTruthTableCell) modifiedBoard.getCell(cell.getX(), cell.getY())
: (ShortTruthTableCell) modifiedBoard.getPuzzleElement(element);

checkCell.setType(checkCell.getType().getNegation());

String contradictionMessage = CORRESPONDING_CONTRADICTION_RULE.checkContradictionAt(modifiedBoard, checkElement);
if (contradictionMessage == null) { // A contradiction exists in the modified statement; this is good!
return null;
}

return super.getInvalidUseOfRuleMessage();
}

/**
Expand Down

0 comments on commit 2e1a689

Please sign in to comment.