Skip to content

Commit

Permalink
Merge pull request #75 from Bram-Hub/truth-table_issue73_case-rule-bug
Browse files Browse the repository at this point in the history
Truth table issue73 case rule bug
  • Loading branch information
charlestian23 authored Feb 8, 2022
2 parents e8e9b17 + 82ac6e0 commit 6a2e22b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CaseRuleAtomic() {
System.out.println("Case Rule T/F constructor");
}

//Adds all elements that can be selected for this caserule
// Adds all elements that can be selected for this case rule
@Override
public CaseBoard getCaseBoard(Board board) {
ShortTruthTableBoard sttBoard = (ShortTruthTableBoard) board.copy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

public abstract class CaseRule_Generic extends CaseRule {

public CaseRule_Generic(String ruleName, String title, String description) {
public CaseRule_Generic(String ruleName, String title, String description)
{
super(title, description, "edu/rpi/legup/images/shorttruthtable/ruleimages/case/"+ruleName+".png");
// System.out.println("Case Rule Generic constructor");
}


Expand All @@ -32,30 +32,27 @@ public CaseRule_Generic(String ruleName, String title, String description) {
* @return null if the child node logically follow from the parent node, otherwise error message
*/
@Override
public String checkRuleRaw(TreeTransition transition) {
public String checkRuleRaw(TreeTransition transition)
{
List<TreeTransition> childTransitions = transition.getParents().get(0).getChildren();
if (childTransitions.size() != 2) {
if (childTransitions.size() != 2)
return "This case rule must have 2 children.";
}

TreeTransition case1 = childTransitions.get(0);
TreeTransition case2 = childTransitions.get(1);
if (case1.getBoard().getModifiedData().size() != 1 ||
case2.getBoard().getModifiedData().size() != 1) {
if (case1.getBoard().getModifiedData().size() != 1 || case2.getBoard().getModifiedData().size() != 1)
return "This case rule must have 1 modified cell for each case.";
}

ShortTruthTableCell mod1 = (ShortTruthTableCell) case1.getBoard().getModifiedData().iterator().next();
ShortTruthTableCell mod2 = (ShortTruthTableCell) case2.getBoard().getModifiedData().iterator().next();
if (!mod1.getLocation().equals(mod2.getLocation())) {
if (!mod1.getLocation().equals(mod2.getLocation()))
return "This case rule must modify the same cell for each case.";
}

if (!((mod1.getType() == ShortTruthTableCellType.TRUE && mod2.getType() == ShortTruthTableCellType.FALSE) ||
(mod2.getType() == ShortTruthTableCellType.FALSE && mod1.getType() == ShortTruthTableCellType.TRUE))) {
boolean firstPossibility = mod1.getType() == ShortTruthTableCellType.TRUE && mod2.getType() == ShortTruthTableCellType.FALSE;
boolean secondPossibility = mod1.getType() == ShortTruthTableCellType.FALSE && mod2.getType() == ShortTruthTableCellType.TRUE;
if (!firstPossibility && !secondPossibility)
return "This case rule must an empty true or false cell.";
}


return null;
}

Expand All @@ -69,8 +66,8 @@ public String checkRuleRaw(TreeTransition transition) {
* otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
// System.out.println("checkRuleRawAt case rule");
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement)
{
return checkRuleRaw(transition);
}
}

0 comments on commit 6a2e22b

Please sign in to comment.