Skip to content

Commit

Permalink
Merge branch 'uid' into dev-uid_resolve-conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
charlestian23 committed Mar 10, 2022
2 parents 79969b1 + 0a6e808 commit 81ab94b
Show file tree
Hide file tree
Showing 161 changed files with 446 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ gradle-app.setting
# JDT-specific (Eclipse Java Development Tools)
.classpath

# End of https://www.toptal.com/developers/gitignore/api/intellij+all,gradle,java
# End of https://www.toptal.com/developers/gitignore/api/intellij+all,gradle,java
29 changes: 29 additions & 0 deletions src/main/java/edu/rpi/legup/model/Puzzle.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,35 @@ public Rule getRuleByName(String name) {
return null;
}

/**
* Gets the rule using the specified name
*
* @param id name of the rule
* @return Rule
*/
public Rule getRuleByID(String id) {
for (Rule rule : basicRules) {
if (rule.getRuleID().equals(id)) {
return rule;
}
}
for (Rule rule : contradictionRules) {
if (rule.getRuleID().equals(id)) {
return rule;
}
}
for (Rule rule : caseRules) {
if (rule.getRuleID().equals(id)) {
return rule;
}
}
Rule mergeRule = new MergeRule();
if (mergeRule.getRuleID().equals(id)) {
return mergeRule;
}
return null;
}

/**
* Gets the current board
*
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/edu/rpi/legup/model/PuzzleExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void exportPuzzle(String fileName) throws ExportFileException {
Document newDocument = docBuilder.newDocument();

org.w3c.dom.Element legupElement = newDocument.createElement("Legup");
legupElement.setAttribute("version", "2.0.0");
legupElement.setAttribute("version", "3.0.0");
newDocument.appendChild(legupElement);

org.w3c.dom.Element puzzleElement = newDocument.createElement("puzzle");
Expand Down Expand Up @@ -112,6 +112,7 @@ protected Element createTreeElement(Document newDocument) {

if (transition.isJustified()) {
transElement.setAttribute("rule", transition.getRule().getRuleName());
transElement.setAttribute("rule_id", transition.getRule().getRuleID());
}

for (PuzzleElement data : transition.getBoard().getModifiedData()) {
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/edu/rpi/legup/model/PuzzleImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ protected void createTree(Node node) throws InvalidFileFormatException {
String nodeId = treeNodeElement.getAttribute("id");
String isRoot = treeNodeElement.getAttribute("root");
if (nodeId.isEmpty()) {
throw new InvalidFileFormatException("Proof Tree construction error: cannot find node id");
throw new InvalidFileFormatException("Proof Tree construction error: cannot find node ID");
}
if (treeNodes.containsKey(nodeId)) {
throw new InvalidFileFormatException("Proof Tree construction error: duplicate tree node id found");
throw new InvalidFileFormatException("Proof Tree construction error: duplicate tree node ID found");
}
TreeNode treeNode = new TreeNode(puzzle.getCurrentBoard().copy());
if (isRoot.equalsIgnoreCase("true")) {
Expand Down Expand Up @@ -187,23 +187,24 @@ protected void createTree(Node node) throws InvalidFileFormatException {
treeNode.addChild(transition);
continue;
} else {
throw new InvalidFileFormatException("Proof Tree construction error: duplicate transition id found");
throw new InvalidFileFormatException("Proof Tree construction error: duplicate transition ID found");
}

}

String childId = trans.getAttribute("child");
String ruleName = trans.getAttribute("rule");
String ruleId = trans.getAttribute("rule_id");

TreeNode child = treeNodes.get(childId);

transition = new TreeTransition(treeNode, treeNode.getBoard().copy());

Rule rule;
if (!ruleName.isEmpty()) {
rule = puzzle.getRuleByName(ruleName);
rule = puzzle.getRuleByID(ruleId);
if (rule == null) {
throw new InvalidFileFormatException("Proof Tree construction error: could not find rule by name");
throw new InvalidFileFormatException("Proof Tree construction error: could not find rule by ID");
}
transition.setRule(rule);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/edu/rpi/legup/model/rules/BasicRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ public abstract class BasicRule extends Rule {
/**
* BasicRule Constructor creates a new basic rule.
*
* @param ruleID ID of the rule
* @param ruleName name of the rule
* @param description description of the rule
* @param imageName file name of the image
*/
public BasicRule(String ruleName, String description, String imageName) {
super(ruleName, description, imageName);
public BasicRule(String ruleID, String ruleName, String description, String imageName) {
super(ruleID, ruleName, description, imageName);
this.ruleType = BASIC;
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/edu/rpi/legup/model/rules/CaseRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public abstract class CaseRule extends Rule {
/**
* CaseRule Constructor creates a new case rule.
*
* @param ruleID ID of the rule
* @param ruleName name of the rule
* @param description description of the rule
* @param imageName file name of the image
*/
public CaseRule(String ruleName, String description, String imageName) {
super(ruleName, description, imageName);
public CaseRule(String ruleID, String ruleName, String description, String imageName) {
super(ruleID, ruleName, description, imageName);
this.ruleType = CASE;
this.INVALID_USE_MESSAGE = "Invalid use of the case rule " + this.ruleName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ public abstract class ContradictionRule extends Rule {
/**
* ContradictionRule Constructor creates a new contradiction rule
*
* @param ruleID ID of the rule
* @param ruleName name of the rule
* @param description description of the rule
* @param imageName file name of the image
*/
public ContradictionRule(String ruleName, String description, String imageName) {
super(ruleName, description, imageName);
public ContradictionRule(String ruleID, String ruleName, String description, String imageName) {
super(ruleID, ruleName, description, imageName);
ruleType = CONTRADICTION;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/rpi/legup/model/rules/MergeRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class MergeRule extends Rule {
* MergeRule Constructor merges to board states together
*/
public MergeRule() {
super("Merge Rule",
super("MERGE","Merge Rule",
"Merge any number of nodes into one",
"edu/rpi/legup/images/Legup/MergeRule.png");
this.ruleType = MERGE;
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/edu/rpi/legup/model/rules/Rule.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@RegisterRule
public abstract class Rule {
protected String ruleID;
protected String ruleName;
protected String description;
protected String imageName;
Expand All @@ -24,14 +25,16 @@ public abstract class Rule {
/**
* Rule Constructor creates a new rule
*
* @param ruleID ID of the rule
* @param ruleName name of the rule
* @param description description of the rule
* @param imageName file name of the image
*/
public Rule(String ruleName, String description, String imageName) {
this.imageName = imageName;
public Rule(String ruleID, String ruleName, String description, String imageName) {
this.ruleID = ruleID;
this.ruleName = ruleName;
this.description = description;
this.imageName = imageName;
this.INVALID_USE_MESSAGE = "Invalid use of the rule " + this.ruleName;
loadImage();
}
Expand Down Expand Up @@ -108,6 +111,15 @@ public String getRuleName() {
return ruleName;
}

/**
* Gets the name of the rule
*
* @return name of the rule
*/
public String getRuleID() {
return ruleID;
}

/**
* Sets the rule name
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
public class AdjacentShipsContradictionRule extends ContradictionRule {

public AdjacentShipsContradictionRule() {
super("Adjacent Ships",
super("BTSP-CONT-0001",
"Adjacent Ships",
"",
"edu/rpi/legup/images/battleship/contradictions/AdjacentShips.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
public class ContinueShipBasicRule extends BasicRule {

public ContinueShipBasicRule() {
super("Continue Ship",
super("BTSP-BASC-0001",
"Continue Ship",
"",
"edu/rpi/legup/images/battleship/rules/ContinueShip.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
public class FinishWithWaterBasicRule extends BasicRule {

public FinishWithWaterBasicRule() {
super("Finish with Water",
super("BTSP-BASC-0003",
"Finish with Water",
"",
"edu/rpi/legup/images/battleship/rules/finishWater.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
public class FinishedWithShipsBasicRule extends BasicRule {

public FinishedWithShipsBasicRule() {
super("Finished with Ships",
super("BTSP-BASC-0002",
"Finished with Ships",
"",
"edu/rpi/legup/images/battleship/rules/finishShip.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
public class IncompleteShipContradictionRule extends ContradictionRule {

public IncompleteShipContradictionRule() {
super("Incomplete Ship",
super("BTSP-CONT-0002",
"Incomplete Ship",
"",
"edu/rpi/legup/images/battleship/contradictions/IncompleteShip.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
public class SegmentTypeBasicRule extends BasicRule {

public SegmentTypeBasicRule() {
super("Segment Type",
super("BTSP-BASC-0004",
"Segment Type",
"",
"edu/rpi/legup/images/battleship/rules/SegmentChoice.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

public class SegmentTypeCaseRule extends CaseRule {
public SegmentTypeCaseRule() {
super("Segment Type",
super("BTSP-CASE-0001",
"Segment Type",
"",
"edu/rpi/legup/images/battleship/cases/SegmentType.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
public class ShipLocationCaseRule extends CaseRule {

public ShipLocationCaseRule() {
super("Ship Location",
super("BTSP-CASE-0002",
"Ship Location",
"",
"edu/rpi/legup/images/battleship/cases/ShipLocations.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
public class ShipOrWaterCaseRule extends CaseRule {

public ShipOrWaterCaseRule() {
super("Ship or Water",
super("BTSP-CASE-0003",
"Ship or Water",
"",
"edu/rpi/legup/images/battleship/cases/ShipOrWater.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
public class SurroundShipBasicRule extends BasicRule {

public SurroundShipBasicRule() {
super("Surround Ship",
super("BTSP-BASC-0005",
"Surround Ship",
"",
"edu/rpi/legup/images/battleship/rules/SurroundShip.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
public class TooFewInFleetContradictionRule extends ContradictionRule {

public TooFewInFleetContradictionRule() {
super("Too Few in Fleet",
super("BTSP-CONT-0003",
"Too Few in Fleet",
"",
"edu/rpi/legup/images/battleship/contradictions/too_few_in_fleet.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
public class TooFewRowColContradictionRule extends ContradictionRule {

public TooFewRowColContradictionRule() {
super("Too few in row/col",
super("BTSP-CONT-0004",
"Too few in row/col",
"",
"edu/rpi/legup/images/battleship/contradictions/too_few_segments.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
public class TooManyInFleetContradictionRule extends ContradictionRule {

public TooManyInFleetContradictionRule() {
super("Too Many in Fleet",
super("BTSP-CONT-0005",
"Too Many in Fleet",
"",
"edu/rpi/legup/images/battleship/contradictions/too_many_in_fleet.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
public class TooManyRowColContradiction extends ContradictionRule {

public TooManyRowColContradiction() {
super("Too Many row/col",
super("BTSP-CONT-0006",
"Too Many row/col",
"",
"edu/rpi/legup/images/battleship/contradictions/too_many_segments.png");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
BTSP-BASC-0001 : ContinueShipBasicRule
BTSP-BASC-0002 : FinishedWithShipsBasicRule
BTSP-BASC-0003 : FinishWithWaterBasicRule
BTSP-BASC-0004 : SegmentTypeBasicRule
BTSP-BASC-0005 : SurroundShipBasicRule

BTSP-CONT-0001 : AdjacentShipsContradictionRule
BTSP-CONT-0002 : IncompleteShipContradictionRule
BTSP-CONT-0003 : TooFewInFleetContradictionRule
BTSP-CONT-0004 : TooFewRowColContradictionRule
BTSP-CONT-0005 : TooManyInFleetContradictionRule
BTSP-CONT-0006 : TooManyRowColContradiction

BTSP-CASE-0001 : SegmentTypeCaseRule
BTSP-CASE-0002 : ShipLocationCaseRule
BTSP-CASE-0003 : ShipOrWaterCaseRule

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

public class BlackOrWhiteCaseRule extends CaseRule {
public BlackOrWhiteCaseRule() {
super("Black or White",
super("FPIX-CASE-0001",
"Black or White",
"Each cell is either black or white.",
"edu/rpi/legup/images/fillapix/cases/BlackOrWhite.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

public class FinishWithBlackBasicRule extends BasicRule {
public FinishWithBlackBasicRule() {
super("Finish with Black",
super("FPIX-BASC-0001",
"Finish with Black",
"The remaining unknowns around and on a cell must be black to satisfy the number",
"edu/rpi/legup/images/fillapix/rules/FinishWithBlack.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

public class FinishWithWhiteBasicRule extends BasicRule {
public FinishWithWhiteBasicRule() {
super("Finish with White",
super("FinishWithWhiteBasicRule",
"Finish with White",
"The remaining unknowns around and on a cell must be white to satisfy the number",
"edu/rpi/legup/images/fillapix/rules/FinishWithWhite.png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
public class TooFewBlackCellsContradictionRule extends ContradictionRule {

public TooFewBlackCellsContradictionRule() {
super("Too Few Black Cells",
super("FPIX-CONT-0001",
"Too Few Black Cells",
"There may not be fewer black cells than the number.",
"edu/rpi/legup/images/fillapix/contradictions/TooFewBlackCells.png");
}
Expand Down
Loading

0 comments on commit 81ab94b

Please sign in to comment.