Skip to content

Commit

Permalink
Issue 679 atomic true on empty (#697)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Chase-Grajeda and charlestian23 authored Dec 16, 2023
1 parent 14b0750 commit 69410ab
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/java/edu/rpi/legup/model/rules/DirectRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TreeTransition> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
Expand Down

0 comments on commit 69410ab

Please sign in to comment.