From 69410ab17430156d4dc2bfb4b8aa5863c81b14ca Mon Sep 17 00:00:00 2001 From: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> Date: Sat, 16 Dec 2023 13:01:40 -0500 Subject: [PATCH] Issue 679 atomic true on empty (#697) * Fixed true on empty bug Added IF check that returns false when a Direct Rule receives 0 modified cells * Updated syntax for checkstyle Added braces to IF statement * Bug fix progress Added condition to all DirectRule.Java that uses raw evaluation when no modified data is applied to the board; Added null check for STT checkRuleRaw; Updated STT case rule child count assertion from 2 to at least 1; Added null check for TreeTent SurrountTentWithGrass Direct Rule. --------- Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> --- src/main/java/edu/rpi/legup/model/rules/DirectRule.java | 5 +++++ .../shorttruthtable/rules/basic/DirectRule_Generic.java | 2 ++ .../shorttruthtable/rules/caserule/CaseRule_Generic.java | 4 ++-- .../treetent/rules/SurroundTentWithGrassDirectRule.java | 3 +++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java index 4acc7573e..0465ca88c 100644 --- a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java @@ -48,6 +48,11 @@ public String checkRule(TreeTransition transition) { public String checkRuleRaw(TreeTransition transition) { Board finalBoard = transition.getBoard(); String checkStr = null; + + // Go directly to specific direct rule's judgement if no cell's are edited + if (finalBoard.getModifiedData().size() == 0) { + checkStr = checkRuleRawAt(transition, null); + } for (PuzzleElement puzzleElement : finalBoard.getModifiedData()) { String tempStr = checkRuleAt(transition, puzzleElement); if (tempStr != null) { diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/DirectRule_Generic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/DirectRule_Generic.java index a9b9ab651..e1ac78b8c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/DirectRule_Generic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/DirectRule_Generic.java @@ -22,6 +22,8 @@ public DirectRule_Generic(String ruleID, String ruleName, String description, St } public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) { + // Rule must have cell to evaluate on + if (element == null) return super.getInvalidUseOfRuleMessage() + ": Must have painted cell"; // Check that the puzzle element is not unknown ShortTruthTableBoard parentBoard = (ShortTruthTableBoard) transition.getParents().get(0).getBoard(); diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_Generic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_Generic.java index 9f3a7073f..1409f4baa 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_Generic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_Generic.java @@ -38,8 +38,8 @@ public CaseRule_Generic(String ruleID, String ruleName, String title, String des public String checkRuleRaw(TreeTransition transition) { // Validate that two children are generated List childTransitions = transition.getParents().get(0).getChildren(); - if (childTransitions.size() != 2) { - return "ERROR: This case rule must have 2 children."; + if (childTransitions.size() >= 1) { + return "ERROR: This case rule must spawn at least 1 child."; } // Validate that the modified cells are of type UNKNOWN, TRUE, or FALSE diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassDirectRule.java index 829c1c1e9..44e9dfcc4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassDirectRule.java @@ -31,6 +31,9 @@ public SurroundTentWithGrassDirectRule() { */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + if (puzzleElement == null) { + return null; + } if (puzzleElement instanceof TreeTentLine) { return super.getInvalidUseOfRuleMessage() + ": Line is not valid for this rule."; }