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

Short truth table 351 #370

Merged
merged 2 commits into from
Nov 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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