defaultPreferencesMap = new HashMap<>();
@@ -26,7 +27,6 @@ public class LegupPreferences {
public static final String IMMEDIATE_FEEDBACK = "immediate-feedback";
public static final String COLOR_BLIND = "color-blind";
-
static {
defaultPreferencesMap.put(WORK_DIRECTORY, System.getProperty("user.home"));
defaultPreferencesMap.put(START_FULL_SCREEN, Boolean.toString(false));
@@ -41,16 +41,35 @@ public class LegupPreferences {
}
static {
- preferencesMap.put(WORK_DIRECTORY, preferences.get(WORK_DIRECTORY, defaultPreferencesMap.get(WORK_DIRECTORY)));
- preferencesMap.put(START_FULL_SCREEN, preferences.get(START_FULL_SCREEN, defaultPreferencesMap.get(START_FULL_SCREEN)));
- preferencesMap.put(AUTO_UPDATE, preferences.get(AUTO_UPDATE, defaultPreferencesMap.get(AUTO_UPDATE)));
- preferencesMap.put(DARK_MODE, preferences.get(DARK_MODE, defaultPreferencesMap.get(DARK_MODE)));
- preferencesMap.put(SHOW_MISTAKES, preferences.get(SHOW_MISTAKES, defaultPreferencesMap.get(SHOW_MISTAKES)));
- preferencesMap.put(SHOW_ANNOTATIONS, preferences.get(SHOW_ANNOTATIONS, defaultPreferencesMap.get(SHOW_ANNOTATIONS)));
- preferencesMap.put(ALLOW_DEFAULT_RULES, preferences.get(ALLOW_DEFAULT_RULES, defaultPreferencesMap.get(ALLOW_DEFAULT_RULES)));
- preferencesMap.put(AUTO_GENERATE_CASES, preferences.get(AUTO_GENERATE_CASES, defaultPreferencesMap.get(AUTO_GENERATE_CASES)));
- preferencesMap.put(IMMEDIATE_FEEDBACK, preferences.get(IMMEDIATE_FEEDBACK, defaultPreferencesMap.get(IMMEDIATE_FEEDBACK)));
- preferencesMap.put(COLOR_BLIND, preferences.get(COLOR_BLIND, defaultPreferencesMap.get(COLOR_BLIND)));
+ preferencesMap.put(
+ WORK_DIRECTORY,
+ preferences.get(WORK_DIRECTORY, defaultPreferencesMap.get(WORK_DIRECTORY)));
+ preferencesMap.put(
+ START_FULL_SCREEN,
+ preferences.get(START_FULL_SCREEN, defaultPreferencesMap.get(START_FULL_SCREEN)));
+ preferencesMap.put(
+ AUTO_UPDATE, preferences.get(AUTO_UPDATE, defaultPreferencesMap.get(AUTO_UPDATE)));
+ preferencesMap.put(
+ DARK_MODE, preferences.get(DARK_MODE, defaultPreferencesMap.get(DARK_MODE)));
+ preferencesMap.put(
+ SHOW_MISTAKES,
+ preferences.get(SHOW_MISTAKES, defaultPreferencesMap.get(SHOW_MISTAKES)));
+ preferencesMap.put(
+ SHOW_ANNOTATIONS,
+ preferences.get(SHOW_ANNOTATIONS, defaultPreferencesMap.get(SHOW_ANNOTATIONS)));
+ preferencesMap.put(
+ ALLOW_DEFAULT_RULES,
+ preferences.get(
+ ALLOW_DEFAULT_RULES, defaultPreferencesMap.get(ALLOW_DEFAULT_RULES)));
+ preferencesMap.put(
+ AUTO_GENERATE_CASES,
+ preferences.get(
+ AUTO_GENERATE_CASES, defaultPreferencesMap.get(AUTO_GENERATE_CASES)));
+ preferencesMap.put(
+ IMMEDIATE_FEEDBACK,
+ preferences.get(IMMEDIATE_FEEDBACK, defaultPreferencesMap.get(IMMEDIATE_FEEDBACK)));
+ preferencesMap.put(
+ COLOR_BLIND, preferences.get(COLOR_BLIND, defaultPreferencesMap.get(COLOR_BLIND)));
}
/**
@@ -65,12 +84,8 @@ public static LegupPreferences getInstance() {
return instance;
}
- /**
- * Private LegupPreferences Singleton Constructor
- */
- private LegupPreferences() {
-
- }
+ /** Private LegupPreferences Singleton Constructor */
+ private LegupPreferences() {}
/**
* Gets the user preference by the string key
@@ -85,7 +100,7 @@ public String getUserPref(String key) {
/**
* Gets the user preference by the string key, value pair
*
- * @param key key name of the preference
+ * @param key key name of the preference
* @param value value of the preference
*/
public void setUserPref(String key, String value) {
@@ -96,18 +111,15 @@ public void setUserPref(String key, String value) {
public boolean getUserPrefAsBool(String key) {
if (preferencesMap.get(key).equalsIgnoreCase(Boolean.toString(true))) {
return true;
- }
- else {
+ } else {
if (preferencesMap.get(key).equalsIgnoreCase(Boolean.toString(false))) {
return false;
- }
- else {
+ } else {
throw new RuntimeException("Cannot get user preference - " + key);
}
}
}
-
public String getSavedPath() {
return SAVED_PATH;
}
diff --git a/src/main/java/edu/rpi/legup/app/PuzzleKeyAccelerator.java b/src/main/java/edu/rpi/legup/app/PuzzleKeyAccelerator.java
index 36ffb08aa..f3945be22 100644
--- a/src/main/java/edu/rpi/legup/app/PuzzleKeyAccelerator.java
+++ b/src/main/java/edu/rpi/legup/app/PuzzleKeyAccelerator.java
@@ -1,22 +1,21 @@
package edu.rpi.legup.app;
+import static edu.rpi.legup.app.GameBoardFacade.getInstance;
+
import edu.rpi.legup.history.ICommand;
-import edu.rpi.legup.history.ValidateDirectRuleCommand;
import edu.rpi.legup.history.ValidateContradictionRuleCommand;
-import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.history.ValidateDirectRuleCommand;
import edu.rpi.legup.model.rules.ContradictionRule;
+import edu.rpi.legup.model.rules.DirectRule;
import edu.rpi.legup.model.rules.Rule;
import edu.rpi.legup.model.rules.RuleType;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeView;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection;
-
-import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.HashMap;
import java.util.Map;
-
-import static edu.rpi.legup.app.GameBoardFacade.getInstance;
+import javax.swing.*;
public class PuzzleKeyAccelerator implements KeyListener {
@@ -39,21 +38,17 @@ public void clearKeyMap() {
}
/**
- * Invoked when a key has been typed.
- * See the class description for {@link KeyEvent} for a definition of
- * a key typed event.
+ * Invoked when a key has been typed. See the class description for {@link KeyEvent} for a
+ * definition of a key typed event.
*
* @param e the event to be processed
*/
@Override
- public void keyTyped(KeyEvent e) {
-
- }
+ public void keyTyped(KeyEvent e) {}
/**
- * Invoked when a key has been pressed.
- * See the class description for {@link KeyEvent} for a definition of
- * a key pressed event.
+ * Invoked when a key has been pressed. See the class description for {@link KeyEvent} for a
+ * definition of a key pressed event.
*
* @param e the event to be processed
*/
@@ -62,35 +57,35 @@ public void keyPressed(KeyEvent e) {
KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(e);
Rule rule = keyStrokeMap.get(keyStroke);
if (rule != null) {
- TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView();
+ TreeView treeView =
+ GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView();
String update = "";
if (rule.getRuleType() == RuleType.CASE) {
- // TODO: review this line of code and figure out what it's supposed to do (remove if necessary)
-// handleCaseRule((CaseRule)rule);
- }
- else {
+ // TODO: review this line of code and figure out what it's supposed to do (remove if
+ // necessary)
+ // handleCaseRule((CaseRule)rule);
+ } else {
if (rule.getRuleType() == RuleType.CONTRADICTION) {
TreeViewSelection selection = treeView.getSelection();
- ICommand validate = new ValidateContradictionRuleCommand(selection, (ContradictionRule) rule);
+ ICommand validate =
+ new ValidateContradictionRuleCommand(
+ selection, (ContradictionRule) rule);
if (validate.canExecute()) {
getInstance().getHistory().pushChange(validate);
validate.execute();
- }
- else {
+ } else {
update = validate.getError();
}
- }
- else {
+ } else {
TreeViewSelection selection = treeView.getSelection();
ICommand validate = new ValidateDirectRuleCommand(selection, (DirectRule) rule);
if (validate.canExecute()) {
getInstance().getHistory().pushChange(validate);
validate.execute();
- }
- else {
+ } else {
update = validate.getError();
}
}
@@ -100,14 +95,11 @@ public void keyPressed(KeyEvent e) {
}
/**
- * Invoked when a key has been released.
- * See the class description for {@link KeyEvent} for a definition of
- * a key released event.
+ * Invoked when a key has been released. See the class description for {@link KeyEvent} for a
+ * definition of a key released event.
*
* @param e the event to be processed
*/
@Override
- public void keyReleased(KeyEvent e) {
-
- }
+ public void keyReleased(KeyEvent e) {}
}
diff --git a/src/main/java/edu/rpi/legup/controller/BoardController.java b/src/main/java/edu/rpi/legup/controller/BoardController.java
index f9c328a99..eaae3851d 100644
--- a/src/main/java/edu/rpi/legup/controller/BoardController.java
+++ b/src/main/java/edu/rpi/legup/controller/BoardController.java
@@ -3,16 +3,13 @@
import java.awt.*;
import java.awt.event.*;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
public class BoardController extends Controller {
protected Point lastLeftMousePoint;
protected Point lastRightMousePoint;
/**
- * BoardController Constructor creates a controller object to listen
- * to ui events from a ScrollView
+ * BoardController Constructor creates a controller object to listen to ui events from a
+ * ScrollView
*/
public BoardController() {
super();
@@ -26,13 +23,10 @@ public BoardController() {
* @param e MouseEvent object
*/
@Override
- public void mouseClicked(MouseEvent e) {
-
- }
+ public void mouseClicked(MouseEvent e) {}
/**
- * Mouse Pressed event - sets the cursor to the move cursor and stores
- * info for possible panning
+ * Mouse Pressed event - sets the cursor to the move cursor and stores info for possible panning
*
* @param e MouseEvent object
*/
@@ -42,8 +36,7 @@ public void mousePressed(MouseEvent e) {
}
/**
- * Mouse Released event - sets the cursor back to the default cursor and reset
- * info for panning
+ * Mouse Released event - sets the cursor back to the default cursor and reset info for panning
*
* @param e MouseEvent object
*/
@@ -58,9 +51,7 @@ public void mouseReleased(MouseEvent e) {
* @param e MouseEvent object
*/
@Override
- public void mouseEntered(MouseEvent e) {
-
- }
+ public void mouseEntered(MouseEvent e) {}
/**
* Mouse Exited event - no default action
@@ -68,9 +59,7 @@ public void mouseEntered(MouseEvent e) {
* @param e MouseEvent object
*/
@Override
- public void mouseExited(MouseEvent e) {
-
- }
+ public void mouseExited(MouseEvent e) {}
/**
* Mouse Dragged event - adjusts the viewport
@@ -88,9 +77,7 @@ public void mouseDragged(MouseEvent e) {
* @param e MouseEvent object
*/
@Override
- public void mouseMoved(MouseEvent e) {
-
- }
+ public void mouseMoved(MouseEvent e) {}
/**
* Mouse Wheel Moved event - zooms in on the viewport
diff --git a/src/main/java/edu/rpi/legup/controller/Controller.java b/src/main/java/edu/rpi/legup/controller/Controller.java
index 5eef8cc17..57ce107ac 100644
--- a/src/main/java/edu/rpi/legup/controller/Controller.java
+++ b/src/main/java/edu/rpi/legup/controller/Controller.java
@@ -1,10 +1,9 @@
package edu.rpi.legup.controller;
import edu.rpi.legup.ui.ScrollView;
-
-import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
+import javax.swing.*;
public abstract class Controller implements MouseMotionListener, MouseListener, MouseWheelListener {
protected ScrollView viewer;
@@ -12,7 +11,8 @@ public abstract class Controller implements MouseMotionListener, MouseListener,
private boolean pan;
/**
- * Controller Constructor creates a controller object to listen to ui events from a {@link ScrollView}
+ * Controller Constructor creates a controller object to listen to ui events from a {@link
+ * ScrollView}
*/
public Controller() {
x = y = -1;
@@ -29,13 +29,10 @@ public void setViewer(ScrollView viewer) {
* @param e MouseEvent object
*/
@Override
- public void mouseClicked(MouseEvent e) {
-
- }
+ public void mouseClicked(MouseEvent e) {}
/**
- * Mouse Pressed event sets the cursor to the move cursor and stores
- * info for possible panning
+ * Mouse Pressed event sets the cursor to the move cursor and stores info for possible panning
*
* @param e MouseEvent object
*/
@@ -50,8 +47,7 @@ public void mousePressed(MouseEvent e) {
}
/**
- * Mouse Released event sets the cursor back to the default cursor and reset
- * info for panning
+ * Mouse Released event sets the cursor back to the default cursor and reset info for panning
*
* @param e MouseEvent object
*/
@@ -69,9 +65,7 @@ public void mouseReleased(MouseEvent e) {
* @param e MouseEvent object
*/
@Override
- public void mouseEntered(MouseEvent e) {
-
- }
+ public void mouseEntered(MouseEvent e) {}
/**
* Mouse Exited event no default action
@@ -79,9 +73,7 @@ public void mouseEntered(MouseEvent e) {
* @param e MouseEvent object
*/
@Override
- public void mouseExited(MouseEvent e) {
-
- }
+ public void mouseExited(MouseEvent e) {}
/**
* Mouse Dragged event adjusts the viewport
@@ -106,9 +98,7 @@ public void mouseDragged(MouseEvent e) {
* @param e MouseEvent object
*/
@Override
- public void mouseMoved(MouseEvent e) {
-
- }
+ public void mouseMoved(MouseEvent e) {}
/**
* Mouse Wheel Moved event zooms in on the viewport
@@ -122,11 +112,10 @@ public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getWheelRotation() != 0) {
viewer.zoom(e.getWheelRotation() * 2, e.getPoint());
}
- }
- else {
+ } else {
if (e.getWheelRotation() != 0) {
viewer.zoom(e.getWheelRotation(), e.getPoint());
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/controller/CursorController.java b/src/main/java/edu/rpi/legup/controller/CursorController.java
index 0c9a644ed..2706bd522 100644
--- a/src/main/java/edu/rpi/legup/controller/CursorController.java
+++ b/src/main/java/edu/rpi/legup/controller/CursorController.java
@@ -2,7 +2,6 @@
import java.awt.Component;
import java.awt.Cursor;
-import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Timer;
import java.util.TimerTask;
@@ -10,7 +9,7 @@
public class CursorController {
public static final Cursor BUSY_CURSOR = new Cursor(Cursor.WAIT_CURSOR);
public static final Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR);
- public static final int DELAY = 200; // in milliseconds
+ public static final int DELAY = 200; // in milliseconds
private CursorController() {
// Intentionally left empty
@@ -18,36 +17,38 @@ private CursorController() {
/**
* Creates an ActionListener that will still do the same action processing as the given
- * ActionListener while also displaying a loading cursor if the time it takes to execute
- * the given process exceeds the time (in milliseconds) specified in this.DELAY
- *
- * Sources consulted: http://www.catalysoft.com/articles/busycursor.html
+ * ActionListener while also displaying a loading cursor if the time it takes to execute the
+ * given process exceeds the time (in milliseconds) specified in this.DELAY
*
- * @param component The component you want to set the cursor for
+ *
Sources consulted: http://www.catalysoft.com/articles/busycursor.html
+ *
+ * @param component The component you want to set the cursor for
* @param mainActionListener The ActionListener that does the intended action processing
- * @return An ActionListener object that does the same action processing
- * as mainActionListener while also modifying the cursor if needed
+ * @return An ActionListener object that does the same action processing as mainActionListener
+ * while also modifying the cursor if needed
*/
- public static ActionListener createListener(final Component component, final ActionListener mainActionListener) {
- ActionListener actionListener = e -> {
- TimerTask timerTask = new TimerTask() {
- @Override
- public void run() {
- component.setCursor(BUSY_CURSOR);
- }
- };
+ public static ActionListener createListener(
+ final Component component, final ActionListener mainActionListener) {
+ ActionListener actionListener =
+ e -> {
+ TimerTask timerTask =
+ new TimerTask() {
+ @Override
+ public void run() {
+ component.setCursor(BUSY_CURSOR);
+ }
+ };
- Timer timer = new Timer();
- try {
- timer.schedule(timerTask, DELAY);
- mainActionListener.actionPerformed(e);
- }
- finally {
- timer.cancel();
- component.setCursor(DEFAULT_CURSOR);
- }
- };
+ Timer timer = new Timer();
+ try {
+ timer.schedule(timerTask, DELAY);
+ mainActionListener.actionPerformed(e);
+ } finally {
+ timer.cancel();
+ component.setCursor(DEFAULT_CURSOR);
+ }
+ };
return actionListener;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/controller/EditorElementController.java b/src/main/java/edu/rpi/legup/controller/EditorElementController.java
index 80e7dd35a..5a23885af 100644
--- a/src/main/java/edu/rpi/legup/controller/EditorElementController.java
+++ b/src/main/java/edu/rpi/legup/controller/EditorElementController.java
@@ -1,31 +1,13 @@
package edu.rpi.legup.controller;
-import edu.rpi.legup.app.GameBoardFacade;
-import edu.rpi.legup.app.LegupPreferences;
import edu.rpi.legup.history.*;
-import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.elements.Element;
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.CaseBoard;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.*;
-import edu.rpi.legup.model.tree.TreeElement;
-import edu.rpi.legup.model.tree.TreeElementType;
-import edu.rpi.legup.ui.proofeditorui.rulesview.RuleButton;
-import edu.rpi.legup.ui.proofeditorui.treeview.TreeElementView;
-import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel;
-import edu.rpi.legup.ui.proofeditorui.treeview.TreeView;
-import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection;
import edu.rpi.legup.ui.puzzleeditorui.elementsview.ElementButton;
-
-import javax.swing.*;
-import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.util.List;
-
-import static edu.rpi.legup.app.GameBoardFacade.getInstance;
+import javax.swing.*;
public class EditorElementController implements ActionListener {
protected Object lastSource;
@@ -66,6 +48,5 @@ public void actionPerformed(ActionEvent e) {
button.setBorderToSelected();
this.prevButton = button;
-
}
}
diff --git a/src/main/java/edu/rpi/legup/controller/ElementController.java b/src/main/java/edu/rpi/legup/controller/ElementController.java
index 50fa7d1b9..5840650e1 100644
--- a/src/main/java/edu/rpi/legup/controller/ElementController.java
+++ b/src/main/java/edu/rpi/legup/controller/ElementController.java
@@ -1,10 +1,12 @@
package edu.rpi.legup.controller;
-import edu.rpi.legup.puzzle.treetent.TreeTentBoard;
-import edu.rpi.legup.ui.ScrollView;
+import static edu.rpi.legup.app.GameBoardFacade.*;
+
import edu.rpi.legup.app.GameBoardFacade;
import edu.rpi.legup.app.LegupPreferences;
import edu.rpi.legup.history.AutoCaseRuleCommand;
+import edu.rpi.legup.history.EditDataCommand;
+import edu.rpi.legup.history.ICommand;
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.elements.Element;
import edu.rpi.legup.model.gameboard.Board;
@@ -14,26 +16,24 @@
import edu.rpi.legup.model.tree.TreeElement;
import edu.rpi.legup.model.tree.TreeElementType;
import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.treetent.TreeTentBoard;
import edu.rpi.legup.ui.DynamicView;
import edu.rpi.legup.ui.boardview.BoardView;
import edu.rpi.legup.ui.boardview.ElementSelection;
import edu.rpi.legup.ui.boardview.ElementView;
import edu.rpi.legup.ui.boardview.SelectionItemView;
import edu.rpi.legup.ui.proofeditorui.treeview.*;
-import edu.rpi.legup.history.ICommand;
-import edu.rpi.legup.history.EditDataCommand;
-
import java.awt.*;
import java.awt.event.*;
-import static edu.rpi.legup.app.GameBoardFacade.*;
-
-public class ElementController implements MouseListener, MouseMotionListener, ActionListener, KeyListener {
+public class ElementController
+ implements MouseListener, MouseMotionListener, ActionListener, KeyListener {
protected BoardView boardView;
private Element selectedElement;
/**
- * ElementController Constructor controller to handles ui events associated interacting with a {@link BoardView}
+ * ElementController Constructor controller to handles ui events associated interacting with a
+ * {@link BoardView}
*/
public ElementController() {
this.boardView = null;
@@ -59,9 +59,7 @@ public void setBoardView(BoardView boardView) {
* @param e the event to be processed
*/
@Override
- public void mouseClicked(MouseEvent e) {
-
- }
+ public void mouseClicked(MouseEvent e) {}
/**
* Invoked when a mouse button has been pressed on a component.
@@ -69,9 +67,7 @@ public void mouseClicked(MouseEvent e) {
* @param e the event to be processed
*/
@Override
- public void mousePressed(MouseEvent e) {
-
- }
+ public void mousePressed(MouseEvent e) {}
/**
* Invoked when a mouse button has been released on a component.
@@ -100,21 +96,21 @@ public void mouseReleased(MouseEvent e) {
if (elementView != null) {
if (board instanceof CaseBoard) {
CaseBoard caseBoard = (CaseBoard) board;
- AutoCaseRuleCommand autoCaseRuleCommand = new AutoCaseRuleCommand(elementView, selection, caseBoard.getCaseRule(), caseBoard, e);
+ AutoCaseRuleCommand autoCaseRuleCommand =
+ new AutoCaseRuleCommand(
+ elementView, selection, caseBoard.getCaseRule(), caseBoard, e);
if (autoCaseRuleCommand.canExecute()) {
autoCaseRuleCommand.execute();
getInstance().getHistory().pushChange(autoCaseRuleCommand);
if (treePanel != null) {
treePanel.updateError("");
}
- }
- else {
+ } else {
if (treePanel != null) {
treePanel.updateError(autoCaseRuleCommand.getError());
}
}
- }
- else {
+ } else {
if (selection != null) {
ICommand edit = new EditDataCommand(elementView, selection, e);
if (edit.canExecute()) {
@@ -123,8 +119,7 @@ public void mouseReleased(MouseEvent e) {
if (treePanel != null) {
treePanel.updateError("");
}
- }
- else {
+ } else {
if (treePanel != null) {
treePanel.updateError(edit.getError());
}
@@ -132,20 +127,27 @@ public void mouseReleased(MouseEvent e) {
}
}
}
-// if (selectedElement != null) {
+ // if (selectedElement != null) {
GridBoard b = (GridBoard) this.boardView.getBoard();
Point point = e.getPoint();
- Point scaledPoint = new Point((int) Math.floor(point.x / (30 * this.boardView.getScale())), (int) Math.floor(point.y / (30 * this.boardView.getScale())));
+ Point scaledPoint =
+ new Point(
+ (int) Math.floor(point.x / (30 * this.boardView.getScale())),
+ (int) Math.floor(point.y / (30 * this.boardView.getScale())));
if (this.boardView.getBoard() instanceof TreeTentBoard) {
scaledPoint.setLocation(scaledPoint.getX() - 1, scaledPoint.getY() - 1);
}
- System.out.printf("selected Element is NOT null, attempting to change board at (%d, %d)\n", scaledPoint.x, scaledPoint.y);
-// System.out.println("Before: " + b.getCell(scaledPoint.x, scaledPoint.y).getData());
+ System.out.printf(
+ "selected Element is NOT null, attempting to change board at (%d, %d)\n",
+ scaledPoint.x, scaledPoint.y);
+ // System.out.println("Before: " + b.getCell(scaledPoint.x,
+ // scaledPoint.y).getData());
b.setCell(scaledPoint.x, scaledPoint.y, this.selectedElement, e);
-// System.out.println("After: " + b.getCell(scaledPoint.x, scaledPoint.y).getData());
-// } else {
-// System.out.println("selected Element is null!");
-// }
+ // System.out.println("After: " + b.getCell(scaledPoint.x,
+ // scaledPoint.y).getData());
+ // } else {
+ // System.out.println("selected Element is null!");
+ // }
boardView.repaint();
}
@@ -175,7 +177,9 @@ public void mouseEntered(MouseEvent e) {
selection.newHover(elementView);
if (LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.SHOW_MISTAKES)) {
PuzzleElement element = elementView.getPuzzleElement();
- if (treeElement != null && treeElement.getType() == TreeElementType.TRANSITION && board.getModifiedData().contains(element)) {
+ if (treeElement != null
+ && treeElement.getType() == TreeElementType.TRANSITION
+ && board.getModifiedData().contains(element)) {
TreeTransition transition = (TreeTransition) treeElement;
if (transition.isJustified() && !transition.isCorrect()) {
error = transition.getRule().checkRuleAt(transition, element);
@@ -183,8 +187,7 @@ public void mouseEntered(MouseEvent e) {
}
if (error != null) {
dynamicView.updateError(error);
- }
- else {
+ } else {
dynamicView.resetStatus();
}
}
@@ -222,9 +225,7 @@ public void mouseExited(MouseEvent e) {
* @param e the event to be processed
*/
@Override
- public void mouseDragged(MouseEvent e) {
-
- }
+ public void mouseDragged(MouseEvent e) {}
/**
* Invoked when the mouse moved
@@ -250,7 +251,9 @@ public void mouseMoved(MouseEvent e) {
selection.newHover(elementView);
if (LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.SHOW_MISTAKES)) {
PuzzleElement element = elementView.getPuzzleElement();
- if (treeElement != null && treeElement.getType() == TreeElementType.TRANSITION && board.getModifiedData().contains(element)) {
+ if (treeElement != null
+ && treeElement.getType() == TreeElementType.TRANSITION
+ && board.getModifiedData().contains(element)) {
TreeTransition transition = (TreeTransition) treeElement;
if (transition.isJustified() && !transition.isCorrect()) {
error = transition.getRule().checkRuleAt(transition, element);
@@ -258,8 +261,7 @@ public void mouseMoved(MouseEvent e) {
}
if (error != null) {
dynamicView.updateError(error);
- }
- else {
+ } else {
dynamicView.resetStatus();
}
}
@@ -267,9 +269,7 @@ public void mouseMoved(MouseEvent e) {
}
}
- public void changeCell(MouseEvent e, PuzzleElement data) {
-
- }
+ public void changeCell(MouseEvent e, PuzzleElement data) {}
/**
* Invoked when an action occurs.
@@ -299,8 +299,7 @@ public void actionPerformed(ActionEvent e) {
if (puzzleElement.equalsData(prevBord.getPuzzleElement(puzzleElement))) {
puzzleElement.setModified(false);
- }
- else {
+ } else {
puzzleElement.setModified(true);
}
@@ -311,33 +310,26 @@ public void actionPerformed(ActionEvent e) {
}
/**
- * Invoked when a key has been typed.
- * See the class description for {@link KeyEvent} for a definition of
- * a key typed event.
+ * Invoked when a key has been typed. See the class description for {@link KeyEvent} for a
+ * definition of a key typed event.
*
* @param e the event to be processed
*/
@Override
- public void keyTyped(KeyEvent e) {
-
- }
+ public void keyTyped(KeyEvent e) {}
/**
- * Invoked when a key has been pressed.
- * See the class description for {@link KeyEvent} for a definition of
- * a key pressed event.
+ * Invoked when a key has been pressed. See the class description for {@link KeyEvent} for a
+ * definition of a key pressed event.
*
* @param e the event to be processed
*/
@Override
- public void keyPressed(KeyEvent e) {
-
- }
+ public void keyPressed(KeyEvent e) {}
/**
- * Invoked when a key has been released.
- * See the class description for {@link KeyEvent} for a definition of
- * a key released event.
+ * Invoked when a key has been released. See the class description for {@link KeyEvent} for a
+ * definition of a key released event.
*
* @param e the event to be processed
*/
diff --git a/src/main/java/edu/rpi/legup/controller/RuleController.java b/src/main/java/edu/rpi/legup/controller/RuleController.java
index fef6fca45..6e88dc4be 100644
--- a/src/main/java/edu/rpi/legup/controller/RuleController.java
+++ b/src/main/java/edu/rpi/legup/controller/RuleController.java
@@ -1,5 +1,7 @@
package edu.rpi.legup.controller;
+import static edu.rpi.legup.app.GameBoardFacade.getInstance;
+
import edu.rpi.legup.app.GameBoardFacade;
import edu.rpi.legup.app.LegupPreferences;
import edu.rpi.legup.history.*;
@@ -10,19 +12,16 @@
import edu.rpi.legup.ui.proofeditorui.rulesview.RuleButton;
import edu.rpi.legup.ui.proofeditorui.rulesview.RulePanel;
import edu.rpi.legup.ui.proofeditorui.treeview.*;
-
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
-import static edu.rpi.legup.app.GameBoardFacade.getInstance;
-
public class RuleController implements ActionListener {
protected Object lastSource;
/**
- * RuleController Constructor creates a controller object to listen
- * to ui events from a {@link RulePanel}
+ * RuleController Constructor creates a controller object to listen to ui events from a {@link
+ * RulePanel}
*/
public RuleController() {
super();
@@ -51,56 +50,56 @@ public void buttonPressed(Rule rule) {
if (caseRuleCommand.canExecute()) {
caseRuleCommand.execute();
getInstance().getHistory().pushChange(caseRuleCommand);
- }
- else {
+ } else {
updateErrorString = caseRuleCommand.getError();
}
- }
- else {
- if (LegupPreferences.getInstance().getUserPref(LegupPreferences.AUTO_GENERATE_CASES).equalsIgnoreCase(Boolean.toString(true))) {
+ } else {
+ if (LegupPreferences.getInstance()
+ .getUserPref(LegupPreferences.AUTO_GENERATE_CASES)
+ .equalsIgnoreCase(Boolean.toString(true))) {
CaseBoard caseBoard = caseRule.getCaseBoard(element.getBoard());
if (caseBoard != null && caseBoard.getCount() > 0) {
- puzzle.notifyBoardListeners(listener -> listener.onCaseBoardAdded(caseBoard));
- }
- else {
+ puzzle.notifyBoardListeners(
+ listener -> listener.onCaseBoardAdded(caseBoard));
+ } else {
updateErrorString = "This board cannot be applied with this case rule.";
}
- }
- else {
- updateErrorString = "Auto generated case rules are turned off in preferences.";
+ } else {
+ updateErrorString =
+ "Auto generated case rules are turned off in preferences.";
}
}
- }
- else {
+ } else {
ICommand caseRuleCommand = new ValidateCaseRuleCommand(selection, caseRule);
if (caseRuleCommand.canExecute()) {
caseRuleCommand.execute();
getInstance().getHistory().pushChange(caseRuleCommand);
- }
- else {
+ } else {
updateErrorString = caseRuleCommand.getError();
}
}
- }
- else {
+ } else {
if (rule.getRuleType() == RuleType.CONTRADICTION) {
- ICommand validate = new ValidateContradictionRuleCommand(selection, (ContradictionRule) rule);
+ ICommand validate =
+ new ValidateContradictionRuleCommand(selection, (ContradictionRule) rule);
if (validate.canExecute()) {
getInstance().getHistory().pushChange(validate);
validate.execute();
- }
- else {
+ } else {
updateErrorString = validate.getError();
}
- }
- else {
- boolean def = LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.ALLOW_DEFAULT_RULES);
- ICommand validate = def ? new ApplyDefaultDirectRuleCommand(selection, (DirectRule) rule) : new ValidateDirectRuleCommand(selection, (DirectRule) rule);
+ } else {
+ boolean def =
+ LegupPreferences.getInstance()
+ .getUserPrefAsBool(LegupPreferences.ALLOW_DEFAULT_RULES);
+ ICommand validate =
+ def
+ ? new ApplyDefaultDirectRuleCommand(selection, (DirectRule) rule)
+ : new ValidateDirectRuleCommand(selection, (DirectRule) rule);
if (validate.canExecute()) {
getInstance().getHistory().pushChange(validate);
validate.execute();
- }
- else {
+ } else {
updateErrorString = validate.getError();
}
}
diff --git a/src/main/java/edu/rpi/legup/controller/ToolbarController.java b/src/main/java/edu/rpi/legup/controller/ToolbarController.java
index 2ee4ee25e..6cbb5ee60 100644
--- a/src/main/java/edu/rpi/legup/controller/ToolbarController.java
+++ b/src/main/java/edu/rpi/legup/controller/ToolbarController.java
@@ -1,19 +1,15 @@
package edu.rpi.legup.controller;
import edu.rpi.legup.ui.LegupUI;
-
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
public class ToolbarController implements ActionListener {
private LegupUI legupUI;
/**
- * ToolbarController Constructor - creates a new {@link ToolbarController} to listen
- * for button pressed from the tool mBar
+ * ToolbarController Constructor - creates a new {@link ToolbarController} to listen for button
+ * pressed from the tool mBar
*
* @param legupUI legupUI
*/
@@ -27,7 +23,5 @@ public ToolbarController(LegupUI legupUI) {
* @param e action event
*/
@Override
- public void actionPerformed(ActionEvent e) {
-
- }
+ public void actionPerformed(ActionEvent e) {}
}
diff --git a/src/main/java/edu/rpi/legup/controller/TreeController.java b/src/main/java/edu/rpi/legup/controller/TreeController.java
index 6eae4ac3b..80fdee1af 100644
--- a/src/main/java/edu/rpi/legup/controller/TreeController.java
+++ b/src/main/java/edu/rpi/legup/controller/TreeController.java
@@ -1,25 +1,22 @@
package edu.rpi.legup.controller;
+import static edu.rpi.legup.app.GameBoardFacade.getInstance;
+
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.tree.Tree;
-import edu.rpi.legup.model.tree.TreeElementType;
import edu.rpi.legup.ui.boardview.BoardView;
import edu.rpi.legup.ui.proofeditorui.treeview.*;
-
-import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
-
-import static edu.rpi.legup.app.GameBoardFacade.getInstance;
+import javax.swing.*;
public class TreeController extends Controller {
/**
- * TreeController Constructor creates a controller object to listen to ui events from a {@link TreePanel}
+ * TreeController Constructor creates a controller object to listen to ui events from a {@link
+ * TreePanel}
*/
- public TreeController() {
-
- }
+ public TreeController() {}
/**
* Mouse Clicked event no default action
@@ -27,9 +24,7 @@ public TreeController() {
* @param e MouseEvent object
*/
@Override
- public void mouseClicked(MouseEvent e) {
-
- }
+ public void mouseClicked(MouseEvent e) {}
/**
* Mouse Pressed event sets the cursor to the move cursor and stores info for possible panning
@@ -44,6 +39,7 @@ public void mousePressed(MouseEvent e) {
/**
* Mouse Released event sets the cursor back to the default cursor and reset info for panning
* Set board modifiability
+ *
* @param e MouseEvent object
*/
@Override
@@ -58,19 +54,19 @@ public void mouseReleased(MouseEvent e) {
if (treeElementView != null) {
if (e.isShiftDown()) {
selection.addToSelection(treeElementView);
- }
- else {
+ } else {
if (e.isControlDown()) {
- if (!(selection.getSelectedViews().size() == 1 && treeElementView == selection.getFirstSelection())) {
+ if (!(selection.getSelectedViews().size() == 1
+ && treeElementView == selection.getFirstSelection())) {
selection.toggleSelection(treeElementView);
}
- }
- else {
+ } else {
selection.newSelection(treeElementView);
}
}
puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection));
- puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(treeElementView.getTreeElement()));
+ puzzle.notifyBoardListeners(
+ listener -> listener.onTreeElementChanged(treeElementView.getTreeElement()));
}
}
@@ -88,7 +84,8 @@ public void mouseEntered(MouseEvent e) {
TreeElementView treeElementView = treeView.getTreeElementView(point);
Puzzle puzzle = getInstance().getPuzzleModule();
if (treeElementView != null) {
- puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(treeElementView.getTreeElement()));
+ puzzle.notifyBoardListeners(
+ listener -> listener.onTreeElementChanged(treeElementView.getTreeElement()));
}
}
@@ -108,7 +105,8 @@ public void mouseExited(MouseEvent e) {
selection.setMousePoint(null);
if (elementView != null) {
TreeElementView selectedView = selection.getFirstSelection();
- puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(selectedView.getTreeElement()));
+ puzzle.notifyBoardListeners(
+ listener -> listener.onTreeElementChanged(selectedView.getTreeElement()));
}
}
@@ -137,15 +135,20 @@ public void mouseMoved(MouseEvent e) {
TreeViewSelection selection = treeView.getSelection();
selection.setMousePoint(treeView.getActualPoint(e.getPoint()));
if (treeElementView != null && treeElementView != selection.getHover()) {
- puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(treeElementView.getTreeElement()));
+ puzzle.notifyBoardListeners(
+ listener ->
+ listener.onTreeElementChanged(treeElementView.getTreeElement()));
selection.newHover(treeElementView);
puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection));
- }
- else {
+ } else {
if (treeElementView == null && selection.getHover() != null) {
- puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(selection.getFirstSelection().getTreeElement()));
+ puzzle.notifyBoardListeners(
+ listener ->
+ listener.onTreeElementChanged(
+ selection.getFirstSelection().getTreeElement()));
selection.clearHover();
- puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection));
+ puzzle.notifyTreeListeners(
+ listener -> listener.onTreeSelectionChanged(selection));
}
}
}
diff --git a/src/main/java/edu/rpi/legup/history/AddTreeElementCommand.java b/src/main/java/edu/rpi/legup/history/AddTreeElementCommand.java
index 0aa6f416d..12b39cd85 100644
--- a/src/main/java/edu/rpi/legup/history/AddTreeElementCommand.java
+++ b/src/main/java/edu/rpi/legup/history/AddTreeElementCommand.java
@@ -6,7 +6,6 @@
import edu.rpi.legup.ui.proofeditorui.treeview.TreeElementView;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeView;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection;
-
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -18,7 +17,8 @@ public class AddTreeElementCommand extends PuzzleCommand {
private Map addChild;
/**
- * AddTreeElementCommand Constructor creates a command for adding a tree element to the proof tree
+ * AddTreeElementCommand Constructor creates a command for adding a tree element to the proof
+ * tree
*
* @param selection selection of tree elements views
*/
@@ -27,9 +27,7 @@ public AddTreeElementCommand(TreeViewSelection selection) {
this.addChild = new HashMap<>();
}
- /**
- * Executes an command
- */
+ /** Executes an command */
@Override
public void executeCommand() {
Tree tree = GameBoardFacade.getInstance().getTree();
@@ -43,12 +41,11 @@ public void executeCommand() {
TreeElement child = addChild.get(treeElement);
if (child == null) {
child = tree.addTreeElement(treeElement);
- }
- else {
+ } else {
+
if (treeElement.getType() == TreeElementType.NODE) {
child = tree.addTreeElement((TreeNode) treeElement, (TreeTransition) child);
- }
- else {
+ } else {
child = tree.addTreeElement((TreeTransition) treeElement, (TreeNode) child);
}
}
@@ -69,15 +66,14 @@ public void executeCommand() {
* Gets the reason why the command cannot be executed
*
* @return if command cannot be executed, returns reason for why the command cannot be executed,
- * otherwise null if command can be executed
+ * otherwise null if command can be executed
*/
@Override
public String getErrorString() {
List selectedViews = selection.getSelectedViews();
if (selectedViews.isEmpty()) {
return CommandError.NO_SELECTED_VIEWS.toString();
- }
- else {
+ } else {
for (TreeElementView view : selectedViews) {
TreeElement element = view.getTreeElement();
if (element.getType() == TreeElementType.TRANSITION) {
@@ -85,8 +81,7 @@ public String getErrorString() {
if (transition.getChildNode() != null) {
return CommandError.ADD_WITH_CHILD.toString();
}
- }
- else {
+ } else {
TreeNode node = (TreeNode) element;
if (!node.getChildren().isEmpty()) {
TreeTransition transition = node.getChildren().get(0);
@@ -100,9 +95,7 @@ public String getErrorString() {
return null;
}
- /**
- * Undoes an command
- */
+ /** Undoes an command */
@Override
public void undoCommand() {
Tree tree = GameBoardFacade.getInstance().getTree();
@@ -119,4 +112,4 @@ public void undoCommand() {
}
puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection));
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/history/ApplyDefaultDirectRuleCommand.java b/src/main/java/edu/rpi/legup/history/ApplyDefaultDirectRuleCommand.java
index bc4c89741..02dffae44 100644
--- a/src/main/java/edu/rpi/legup/history/ApplyDefaultDirectRuleCommand.java
+++ b/src/main/java/edu/rpi/legup/history/ApplyDefaultDirectRuleCommand.java
@@ -1,128 +1,129 @@
-package edu.rpi.legup.history;
-
-import edu.rpi.legup.app.GameBoardFacade;
-import edu.rpi.legup.model.Puzzle;
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.*;
-import edu.rpi.legup.ui.proofeditorui.treeview.*;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class ApplyDefaultDirectRuleCommand extends PuzzleCommand {
-
- private TreeViewSelection selection;
- private DirectRule rule;
- private Map addMap;
-
- /**
- * ApplyDefaultDirectRuleCommand Constructor creates a command for applying the default of a basic rule
- *
- * @param selection selection of tree element views
- * @param rule basic rule for the command
- */
- public ApplyDefaultDirectRuleCommand(TreeViewSelection selection, DirectRule rule) {
- this.selection = selection.copy();
- this.rule = rule;
- this.addMap = new HashMap<>();
- }
-
- /**
- * Gets the reason why the command cannot be executed
- *
- * @return if command cannot be executed, returns reason for why the command cannot be executed,
- * otherwise null if command can be executed
- */
- @Override
- public String getErrorString() {
- List selectedViews = selection.getSelectedViews();
- if (selectedViews.isEmpty()) {
- return CommandError.DEFAULT_APPLICATION + " - " + CommandError.NO_SELECTED_VIEWS.toString();
- }
- else {
- for (TreeElementView view : selectedViews) {
- TreeElement element = view.getTreeElement();
- if (element.getType() == TreeElementType.NODE) {
- TreeNode node = (TreeNode) element;
- if (!node.getChildren().isEmpty()) {
- return CommandError.DEFAULT_APPLICATION + " - " + CommandError.NO_CHILDREN.toString();
- }
- else {
- if (rule.getDefaultBoard(node) == null) {
- return CommandError.DEFAULT_APPLICATION + " - " + "This selection contains a tree element that this rule cannot be applied to.";
- }
- }
- }
- else {
- return CommandError.DEFAULT_APPLICATION + " - " + CommandError.SELECTION_CONTAINS_TRANSITION.toString();
- }
- }
- }
- return null;
- }
-
- /**
- * Executes an command
- */
- @Override
- public void executeCommand() {
- Tree tree = GameBoardFacade.getInstance().getTree();
- TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView();
- Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
- final TreeViewSelection newSelection = new TreeViewSelection();
-
- for (TreeElementView selectedView : selection.getSelectedViews()) {
- TreeNodeView nodeView = (TreeNodeView) selectedView;
- TreeNode node = nodeView.getTreeElement();
- TreeTransition transition = addMap.get(node);
- TreeNode childNode;
- if (transition == null) {
- transition = (TreeTransition) tree.addTreeElement(node);
- childNode = (TreeNode) tree.addTreeElement(transition);
- addMap.put(node, transition);
- }
- else {
- tree.addTreeElement(node, transition);
- childNode = transition.getChildNode();
- }
-
- transition.setRule(rule);
- Board defaultBoard = rule.getDefaultBoard(node);
- transition.setBoard(defaultBoard);
- Board copyBoard = defaultBoard.copy();
- copyBoard.setModifiable(false);
- childNode.setBoard(copyBoard);
-
- final TreeTransition finalTran = transition;
- puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(finalTran));
-
- newSelection.addToSelection(treeView.getElementView(childNode));
- }
-
- final TreeElement finalTreeElement = newSelection.getFirstSelection().getTreeElement();
- puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
- puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection));
- }
-
- /**
- * Undoes an command
- */
- @Override
- public void undoCommand() {
- Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
-
- for (TreeElementView selectedView : selection.getSelectedViews()) {
- TreeNodeView nodeView = (TreeNodeView) selectedView;
- TreeNode node = nodeView.getTreeElement();
- final TreeTransition transition = addMap.get(node);
-
- puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(transition));
- }
-
- final TreeElement finalTreeElement = selection.getFirstSelection().getTreeElement();
- puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
- puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection));
- }
-}
+package edu.rpi.legup.history;
+
+import edu.rpi.legup.app.GameBoardFacade;
+import edu.rpi.legup.model.Puzzle;
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.*;
+import edu.rpi.legup.ui.proofeditorui.treeview.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ApplyDefaultDirectRuleCommand extends PuzzleCommand {
+
+ private TreeViewSelection selection;
+ private DirectRule rule;
+ private Map addMap;
+
+ /**
+ * ApplyDefaultDirectRuleCommand Constructor creates a command for applying the default of a
+ * basic rule
+ *
+ * @param selection selection of tree element views
+ * @param rule basic rule for the command
+ */
+ public ApplyDefaultDirectRuleCommand(TreeViewSelection selection, DirectRule rule) {
+ this.selection = selection.copy();
+ this.rule = rule;
+ this.addMap = new HashMap<>();
+ }
+
+ /**
+ * Gets the reason why the command cannot be executed
+ *
+ * @return if command cannot be executed, returns reason for why the command cannot be executed,
+ * otherwise null if command can be executed
+ */
+ @Override
+ public String getErrorString() {
+ List selectedViews = selection.getSelectedViews();
+ if (selectedViews.isEmpty()) {
+ return CommandError.DEFAULT_APPLICATION
+ + " - "
+ + CommandError.NO_SELECTED_VIEWS.toString();
+ } else {
+ for (TreeElementView view : selectedViews) {
+ TreeElement element = view.getTreeElement();
+ if (element.getType() == TreeElementType.NODE) {
+ TreeNode node = (TreeNode) element;
+ if (!node.getChildren().isEmpty()) {
+
+ return CommandError.DEFAULT_APPLICATION
+ + " - "
+ + CommandError.NO_CHILDREN.toString();
+ } else {
+ if (rule.getDefaultBoard(node) == null) {
+ return CommandError.DEFAULT_APPLICATION
+ + " - This selection contains a tree element that this rule"
+ + " cannot be applied to.";
+ }
+ }
+ } else {
+ return CommandError.DEFAULT_APPLICATION
+ + " - "
+ + CommandError.SELECTION_CONTAINS_TRANSITION.toString();
+ }
+ }
+ }
+ return null;
+ }
+
+ /** Executes an command */
+ @Override
+ public void executeCommand() {
+ Tree tree = GameBoardFacade.getInstance().getTree();
+ TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView();
+ Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
+ final TreeViewSelection newSelection = new TreeViewSelection();
+
+ for (TreeElementView selectedView : selection.getSelectedViews()) {
+ TreeNodeView nodeView = (TreeNodeView) selectedView;
+ TreeNode node = nodeView.getTreeElement();
+ TreeTransition transition = addMap.get(node);
+ TreeNode childNode;
+ if (transition == null) {
+ transition = (TreeTransition) tree.addTreeElement(node);
+ childNode = (TreeNode) tree.addTreeElement(transition);
+ addMap.put(node, transition);
+ } else {
+ tree.addTreeElement(node, transition);
+ childNode = transition.getChildNode();
+ }
+
+ transition.setRule(rule);
+ Board defaultBoard = rule.getDefaultBoard(node);
+ transition.setBoard(defaultBoard);
+ Board copyBoard = defaultBoard.copy();
+ copyBoard.setModifiable(false);
+ childNode.setBoard(copyBoard);
+
+ final TreeTransition finalTran = transition;
+ puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(finalTran));
+
+ newSelection.addToSelection(treeView.getElementView(childNode));
+ }
+
+ final TreeElement finalTreeElement = newSelection.getFirstSelection().getTreeElement();
+ puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
+ puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection));
+ }
+
+ /** Undoes an command */
+ @Override
+ public void undoCommand() {
+ Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
+
+ for (TreeElementView selectedView : selection.getSelectedViews()) {
+ TreeNodeView nodeView = (TreeNodeView) selectedView;
+ TreeNode node = nodeView.getTreeElement();
+ final TreeTransition transition = addMap.get(node);
+
+ puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(transition));
+ }
+
+ final TreeElement finalTreeElement = selection.getFirstSelection().getTreeElement();
+ puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
+ puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection));
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java b/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java
index a4c157c77..54e33756a 100644
--- a/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java
+++ b/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java
@@ -1,5 +1,7 @@
package edu.rpi.legup.history;
+import static edu.rpi.legup.app.GameBoardFacade.getInstance;
+
import edu.rpi.legup.app.GameBoardFacade;
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.gameboard.Board;
@@ -8,12 +10,9 @@
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.boardview.ElementView;
import edu.rpi.legup.ui.proofeditorui.treeview.*;
-
import java.awt.event.MouseEvent;
import java.util.*;
-import static edu.rpi.legup.app.GameBoardFacade.getInstance;
-
public class AutoCaseRuleCommand extends PuzzleCommand {
private ElementView elementView;
@@ -30,12 +29,17 @@ public class AutoCaseRuleCommand extends PuzzleCommand {
* AutoCaseRuleCommand Constructor creates a command for validating a case rule
*
* @param elementView currently selected puzzle puzzleElement view that is being edited
- * @param selection currently selected tree puzzleElement views that is being edited
+ * @param selection currently selected tree puzzleElement views that is being edited
* @param caseRule currently selected caseRule puzzleElement view that is being edited
* @param caseBoard currently selected caseBoard puzzleElement view that is being edited
* @param mouseEvent currently selected mouseEvent puzzleElement view that is being edited
*/
- public AutoCaseRuleCommand(ElementView elementView, TreeViewSelection selection, CaseRule caseRule, CaseBoard caseBoard, MouseEvent mouseEvent) {
+ public AutoCaseRuleCommand(
+ ElementView elementView,
+ TreeViewSelection selection,
+ CaseRule caseRule,
+ CaseBoard caseBoard,
+ MouseEvent mouseEvent) {
this.elementView = elementView;
this.selection = selection.copy();
this.caseRule = caseRule;
@@ -44,9 +48,7 @@ public AutoCaseRuleCommand(ElementView elementView, TreeViewSelection selection,
this.caseTrans = new ArrayList<>();
}
- /**
- * Executes an command
- */
+ /** Executes an command */
@Override
public void executeCommand() {
Tree tree = getInstance().getTree();
@@ -56,7 +58,8 @@ public void executeCommand() {
TreeNode node = (TreeNode) selection.getFirstSelection().getTreeElement();
if (caseTrans.isEmpty()) {
- List cases = caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement());
+ List cases =
+ caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement());
for (Board board : cases) {
final TreeTransition transition = (TreeTransition) tree.addTreeElement(node);
board.setModifiable(false);
@@ -70,8 +73,7 @@ public void executeCommand() {
puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(transition));
newSelection.addToSelection(treeView.getElementView(childNode));
}
- }
- else {
+ } else {
for (final TreeTransition transition : caseTrans) {
tree.addTreeElement(node, transition);
TreeNode childNode = transition.getChildNode();
@@ -89,7 +91,7 @@ public void executeCommand() {
* Gets the reason why the command cannot be executed
*
* @return if command cannot be executed, returns reason for why the command cannot be executed,
- * otherwise null if command can be executed
+ * otherwise null if command can be executed
*/
@Override
public String getErrorString() {
@@ -111,20 +113,20 @@ public String getErrorString() {
return "The selected data element is not pickable with this case rule.";
}
- if (caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement()).size() == 0) {
+ if (caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement()).size()
+ == 0) {
return "The selection must produce at least one case";
}
- if (caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement()).size() > MAX_CASES) {
+ if (caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement()).size()
+ > MAX_CASES) {
return "The selection can produce a max of " + MAX_CASES + " cases";
}
return null;
}
- /**
- * Undoes an command
- */
+ /** Undoes an command */
@Override
public void undoCommand() {
Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
diff --git a/src/main/java/edu/rpi/legup/history/CommandError.java b/src/main/java/edu/rpi/legup/history/CommandError.java
index 90c9db526..35b7bb15b 100644
--- a/src/main/java/edu/rpi/legup/history/CommandError.java
+++ b/src/main/java/edu/rpi/legup/history/CommandError.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.history;
public enum CommandError {
-
NO_SELECTED_VIEWS("The selection does not have any tree elements."),
ONE_SELECTED_VIEW("The selection must have exactly one tree element."),
UNMODIFIABLE_BOARD("The selection contains a board which is not modifiable."),
diff --git a/src/main/java/edu/rpi/legup/history/CommandState.java b/src/main/java/edu/rpi/legup/history/CommandState.java
index b7c2ff938..f47c0405d 100644
--- a/src/main/java/edu/rpi/legup/history/CommandState.java
+++ b/src/main/java/edu/rpi/legup/history/CommandState.java
@@ -1,7 +1,10 @@
package edu.rpi.legup.history;
public enum CommandState {
- CREATED("Created"), EXECUTED("Executed"), UNDOED("Undoed"), REDOED("Redoed");
+ CREATED("Created"),
+ EXECUTED("Executed"),
+ UNDOED("Undoed"),
+ REDOED("Redoed");
private String value;
diff --git a/src/main/java/edu/rpi/legup/history/DeleteTreeElementCommand.java b/src/main/java/edu/rpi/legup/history/DeleteTreeElementCommand.java
index 80cad9b24..0469685c1 100644
--- a/src/main/java/edu/rpi/legup/history/DeleteTreeElementCommand.java
+++ b/src/main/java/edu/rpi/legup/history/DeleteTreeElementCommand.java
@@ -5,14 +5,14 @@
import edu.rpi.legup.model.observer.ITreeListener;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;
-
import java.util.List;
public class DeleteTreeElementCommand extends PuzzleCommand {
private TreeViewSelection selection;
/**
- * DeleteTreeElementCommand Constructor creates a PuzzleCommand for deleting a tree puzzleElement
+ * DeleteTreeElementCommand Constructor creates a PuzzleCommand for deleting a tree
+ * puzzleElement
*
* @param selection the currently selected tree elements before the command is executed
*/
@@ -20,9 +20,7 @@ public DeleteTreeElementCommand(TreeViewSelection selection) {
this.selection = selection.copy();
}
- /**
- * Executes an command
- */
+ /** Executes an command */
@Override
public void executeCommand() {
Tree tree = GameBoardFacade.getInstance().getTree();
@@ -35,8 +33,7 @@ public void executeCommand() {
if (firstSelectedView.getType() == TreeElementType.NODE) {
TreeNodeView nodeView = (TreeNodeView) firstSelectedView;
newSelectedView = nodeView.getParentView();
- }
- else {
+ } else {
TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView;
newSelectedView = transitionView.getParentViews().get(0);
}
@@ -48,15 +45,17 @@ public void executeCommand() {
}
final TreeViewSelection newSelection = new TreeViewSelection(newSelectedView);
- puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(newSelectedView.getTreeElement()));
- puzzle.notifyTreeListeners((ITreeListener listener) -> listener.onTreeSelectionChanged(newSelection));
+ puzzle.notifyBoardListeners(
+ listener -> listener.onTreeElementChanged(newSelectedView.getTreeElement()));
+ puzzle.notifyTreeListeners(
+ (ITreeListener listener) -> listener.onTreeSelectionChanged(newSelection));
}
/**
* Gets the reason why the command cannot be executed
*
* @return if command cannot be executed, returns reason for why the command cannot be executed,
- * otherwise null if command can be executed
+ * otherwise null if command can be executed
*/
@Override
public String getErrorString() {
@@ -74,9 +73,7 @@ public String getErrorString() {
return null;
}
- /**
- * Undoes an command
- */
+ /** Undoes an command */
@Override
public void undoCommand() {
Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
@@ -89,8 +86,7 @@ public void undoCommand() {
node.getParent().setChildNode(node);
puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(node));
- }
- else {
+ } else {
TreeTransition transition = (TreeTransition) element;
transition.getParents().forEach(node -> node.addChild(transition));
transition.getParents().get(0).getChildren().forEach(TreeTransition::reverify);
@@ -99,7 +95,10 @@ public void undoCommand() {
}
}
- puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(selection.getFirstSelection().getTreeElement()));
+ puzzle.notifyBoardListeners(
+ listener ->
+ listener.onTreeElementChanged(
+ selection.getFirstSelection().getTreeElement()));
puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection));
}
}
diff --git a/src/main/java/edu/rpi/legup/history/EditDataCommand.java b/src/main/java/edu/rpi/legup/history/EditDataCommand.java
index 328cc050d..d65f03d66 100644
--- a/src/main/java/edu/rpi/legup/history/EditDataCommand.java
+++ b/src/main/java/edu/rpi/legup/history/EditDataCommand.java
@@ -1,5 +1,7 @@
package edu.rpi.legup.history;
+import static edu.rpi.legup.app.GameBoardFacade.getInstance;
+
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.PuzzleElement;
@@ -8,12 +10,9 @@
import edu.rpi.legup.ui.boardview.BoardView;
import edu.rpi.legup.ui.boardview.ElementView;
import edu.rpi.legup.ui.proofeditorui.treeview.*;
-
import java.awt.event.MouseEvent;
import java.util.List;
-import static edu.rpi.legup.app.GameBoardFacade.getInstance;
-
public class EditDataCommand extends PuzzleCommand {
private TreeTransition transition;
private PuzzleElement savePuzzleElement;
@@ -27,8 +26,8 @@ public class EditDataCommand extends PuzzleCommand {
* EditDataCommand Constructor create a puzzle command for editing a board
*
* @param elementView currently selected puzzle puzzleElement view that is being edited
- * @param selection currently selected tree puzzleElement views that is being edited
- * @param event mouse event
+ * @param selection currently selected tree puzzleElement views that is being edited
+ * @param event mouse event
*/
public EditDataCommand(ElementView elementView, TreeViewSelection selection, MouseEvent event) {
this.elementView = elementView;
@@ -39,9 +38,7 @@ public EditDataCommand(ElementView elementView, TreeViewSelection selection, Mou
this.transition = null;
}
- /**
- * Executes a command
- */
+ /** Executes a command */
@SuppressWarnings("unchecked")
@Override
public void executeCommand() {
@@ -69,8 +66,7 @@ public void executeCommand() {
puzzleElement = board.getPuzzleElement(selectedPuzzleElement);
savePuzzleElement = puzzleElement.copy();
- }
- else {
+ } else {
transition = (TreeTransition) treeElement;
puzzleElement = board.getPuzzleElement(selectedPuzzleElement);
savePuzzleElement = puzzleElement.copy();
@@ -82,8 +78,7 @@ public void executeCommand() {
if (prevBoard.getPuzzleElement(selectedPuzzleElement).equalsData(puzzleElement)) {
board.removeModifiedData(puzzleElement);
- }
- else {
+ } else {
board.addModifiedData(puzzleElement);
}
transition.propagateChange(puzzleElement);
@@ -92,7 +87,8 @@ public void executeCommand() {
puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
puzzle.notifyBoardListeners(listener -> listener.onBoardDataChanged(puzzleElement));
- final TreeViewSelection newSelection = new TreeViewSelection(treeView.getElementView(transition));
+ final TreeViewSelection newSelection =
+ new TreeViewSelection(treeView.getElementView(transition));
puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection));
}
@@ -100,7 +96,7 @@ public void executeCommand() {
* Gets the reason why the command cannot be executed
*
* @return if command cannot be executed, returns reason for why the command cannot be executed,
- * otherwise null if command can be executed
+ * otherwise null if command can be executed
*/
@Override
public String getErrorString() {
@@ -116,19 +112,16 @@ public String getErrorString() {
TreeNodeView nodeView = (TreeNodeView) selectedView;
if (!nodeView.getChildrenViews().isEmpty()) {
return CommandError.UNMODIFIABLE_BOARD.toString();
- }
- else {
+ } else {
if (!board.getPuzzleElement(selectedPuzzleElement).isModifiable()) {
return CommandError.UNMODIFIABLE_DATA.toString();
}
}
- }
- else {
+ } else {
TreeTransitionView transitionView = (TreeTransitionView) selectedView;
if (!transitionView.getTreeElement().getBoard().isModifiable()) {
return CommandError.UNMODIFIABLE_BOARD.toString();
- }
- else {
+ } else {
if (!board.getPuzzleElement(selectedPuzzleElement).isModifiable()) {
return CommandError.UNMODIFIABLE_DATA.toString();
}
@@ -137,9 +130,7 @@ public String getErrorString() {
return null;
}
- /**
- * Undoes an command
- */
+ /** Undoes an command */
@SuppressWarnings("unchecked")
@Override
public void undoCommand() {
@@ -152,7 +143,8 @@ public void undoCommand() {
if (selectedView.getType() == TreeElementType.NODE) {
tree.removeTreeElement(transition);
- puzzle.notifyTreeListeners((ITreeListener listener) -> listener.onTreeElementRemoved(transition));
+ puzzle.notifyTreeListeners(
+ (ITreeListener listener) -> listener.onTreeElementRemoved(transition));
}
Board prevBoard = transition.getParents().get(0).getBoard();
@@ -162,8 +154,7 @@ public void undoCommand() {
if (prevBoard.getPuzzleElement(selectedPuzzleElement).equalsData(puzzleElement)) {
board.removeModifiedData(puzzleElement);
- }
- else {
+ } else {
board.addModifiedData(puzzleElement);
}
transition.propagateChange(puzzleElement);
diff --git a/src/main/java/edu/rpi/legup/history/History.java b/src/main/java/edu/rpi/legup/history/History.java
index 77e3fae94..371284f8c 100644
--- a/src/main/java/edu/rpi/legup/history/History.java
+++ b/src/main/java/edu/rpi/legup/history/History.java
@@ -1,10 +1,8 @@
package edu.rpi.legup.history;
import edu.rpi.legup.app.GameBoardFacade;
-
import java.util.ArrayList;
import java.util.List;
-
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -16,10 +14,9 @@ public class History {
private int curIndex;
/**
- * History Constructor this holds information about changes to the board
- * and Tree structure for undoing and redoing operations. Though history is
- * an List, it is implemented like a stack. The curIndex points to the
- * top of the stack (where the last change was made).
+ * History Constructor this holds information about changes to the board and Tree structure for
+ * undoing and redoing operations. Though history is an List, it is implemented like a stack.
+ * The curIndex points to the top of the stack (where the last change was made).
*/
public History() {
history = new ArrayList<>();
@@ -27,9 +24,9 @@ public History() {
}
/**
- * Pushes a change to the history list and increments the current index.
- * If the current index does not point to the top of the stack, then at least
- * 1 undo operation was called and that information will be lost by the next change
+ * Pushes a change to the history list and increments the current index. If the current index
+ * does not point to the top of the stack, then at least 1 undo operation was called and that
+ * information will be lost by the next change
*
* @param command command to be pushed onto the stack
*/
@@ -47,37 +44,35 @@ public void pushChange(ICommand command) {
}
}
- /**
- * Undoes an action
- */
+ /** Undoes an action */
public void undo() {
synchronized (lock) {
if (curIndex > -1) {
ICommand command = history.get(curIndex--);
command.undo();
LOGGER.info("Undoed " + command.getClass().getSimpleName());
- GameBoardFacade.getInstance().notifyHistoryListeners(l -> l.onUndo(curIndex < 0, curIndex == history.size() - 1));
+ GameBoardFacade.getInstance()
+ .notifyHistoryListeners(
+ l -> l.onUndo(curIndex < 0, curIndex == history.size() - 1));
}
}
}
- /**
- * Redoes an action
- */
+ /** Redoes an action */
public void redo() {
synchronized (lock) {
if (curIndex < history.size() - 1) {
ICommand command = history.get(++curIndex);
command.redo();
LOGGER.info("Redoed " + command.getClass().getSimpleName());
- GameBoardFacade.getInstance().notifyHistoryListeners(l -> l.onRedo(curIndex < 0, curIndex == history.size() - 1));
+ GameBoardFacade.getInstance()
+ .notifyHistoryListeners(
+ l -> l.onRedo(curIndex < 0, curIndex == history.size() - 1));
}
}
}
- /**
- * Clears all actions from the history stack
- */
+ /** Clears all actions from the history stack */
public void clear() {
history.clear();
curIndex = -1;
diff --git a/src/main/java/edu/rpi/legup/history/ICommand.java b/src/main/java/edu/rpi/legup/history/ICommand.java
index bc82c4df5..913d9daaf 100644
--- a/src/main/java/edu/rpi/legup/history/ICommand.java
+++ b/src/main/java/edu/rpi/legup/history/ICommand.java
@@ -1,13 +1,12 @@
package edu.rpi.legup.history;
public interface ICommand {
- /**
- * Executes a command
- */
+ /** Executes a command */
void execute();
/**
* Determines whether this command can be executed
+ *
* @return true if can execute, false otherwise
*/
boolean canExecute();
@@ -16,17 +15,13 @@ public interface ICommand {
* Gets the reason why the command cannot be executed
*
* @return if command cannot be executed, returns reason for why the command cannot be executed,
- * otherwise null if command can be executed
+ * otherwise null if command can be executed
*/
String getError();
- /**
- * Undoes a command
- */
+ /** Undoes a command */
void undo();
- /**
- * Redoes a command
- */
+ /** Redoes a command */
void redo();
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/history/IHistoryListener.java b/src/main/java/edu/rpi/legup/history/IHistoryListener.java
index 5201a09c5..f464941d6 100644
--- a/src/main/java/edu/rpi/legup/history/IHistoryListener.java
+++ b/src/main/java/edu/rpi/legup/history/IHistoryListener.java
@@ -12,7 +12,7 @@ public interface IHistoryListener {
* Called when an action is undone
*
* @param isBottom true if there are no more actions to undo, false otherwise
- * @param isTop true if there are no more changes to redo, false otherwise
+ * @param isTop true if there are no more changes to redo, false otherwise
*/
void onUndo(boolean isBottom, boolean isTop);
@@ -20,12 +20,10 @@ public interface IHistoryListener {
* Called when an action is redone
*
* @param isBottom true if there are no more actions to undo, false otherwise
- * @param isTop true if there are no more changes to redo, false otherwise
+ * @param isTop true if there are no more changes to redo, false otherwise
*/
void onRedo(boolean isBottom, boolean isTop);
- /**
- * Called when the edu.rpi.legup.history is cleared
- */
+ /** Called when the edu.rpi.legup.history is cleared */
void onClearHistory();
}
diff --git a/src/main/java/edu/rpi/legup/history/InvalidCommandStateTransition.java b/src/main/java/edu/rpi/legup/history/InvalidCommandStateTransition.java
index 7e79814a6..71d072328 100644
--- a/src/main/java/edu/rpi/legup/history/InvalidCommandStateTransition.java
+++ b/src/main/java/edu/rpi/legup/history/InvalidCommandStateTransition.java
@@ -2,7 +2,14 @@
public class InvalidCommandStateTransition extends RuntimeException {
- public InvalidCommandStateTransition(PuzzleCommand puzzleCommand, CommandState from, CommandState to) {
- super("PuzzleCommand - " + puzzleCommand.getClass().getSimpleName() + " - Attempted invalid command state transition from " + from + " to " + to);
+ public InvalidCommandStateTransition(
+ PuzzleCommand puzzleCommand, CommandState from, CommandState to) {
+ super(
+ "PuzzleCommand - "
+ + puzzleCommand.getClass().getSimpleName()
+ + " - Attempted invalid command state transition from "
+ + from
+ + " to "
+ + to);
}
}
diff --git a/src/main/java/edu/rpi/legup/history/MergeCommand.java b/src/main/java/edu/rpi/legup/history/MergeCommand.java
index 2091ecf0a..f234a0884 100644
--- a/src/main/java/edu/rpi/legup/history/MergeCommand.java
+++ b/src/main/java/edu/rpi/legup/history/MergeCommand.java
@@ -6,7 +6,6 @@
import edu.rpi.legup.model.rules.MergeRule;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -25,9 +24,7 @@ public MergeCommand(TreeViewSelection selection) {
this.transition = null;
}
- /**
- * Executes an command
- */
+ /** Executes an command */
@Override
public void executeCommand() {
List selectedViews = selection.getSelectedViews();
@@ -55,8 +52,7 @@ public void executeCommand() {
transition.setRule(new MergeRule());
transition.setChildNode(mergedNode);
mergedNode.setParent(transition);
- }
- else {
+ } else {
mergedNode = transition.getChildNode();
}
@@ -75,15 +71,14 @@ public void executeCommand() {
puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection));
}
- /**
- * Undoes an command
- */
+ /** Undoes an command */
@Override
public void undoCommand() {
Tree tree = GameBoardFacade.getInstance().getTree();
Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
- TreeTransition transition = ((TreeNode) selection.getFirstSelection().getTreeElement()).getChildren().get(0);
+ TreeTransition transition =
+ ((TreeNode) selection.getFirstSelection().getTreeElement()).getChildren().get(0);
tree.removeTreeElement(transition);
puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(transition));
@@ -94,7 +89,7 @@ public void undoCommand() {
* Gets the reason why the command cannot be executed
*
* @return if command cannot be executed, returns reason for why the command cannot be executed,
- * otherwise null if command can be executed
+ * otherwise null if command can be executed
*/
@Override
public String getErrorString() {
@@ -112,8 +107,7 @@ public String getErrorString() {
return CommandError.NO_CHILDREN.toString();
}
nodeList.add(nodeView.getTreeElement());
- }
- else {
+ } else {
return CommandError.SELECTION_CONTAINS_TRANSITION.toString();
}
}
@@ -130,12 +124,12 @@ public String getErrorString() {
}
Set leafNodes = tree.getLeafTreeElements(lca);
if (leafNodes.size() != mergingNodes.size()) {
-// return "Unable to merge tree elements.";
+ // return "Unable to merge tree elements.";
}
for (TreeNode node : mergingNodes) {
if (!leafNodes.contains(node)) {
-// return "Unable to merge tree elements.";
+ // return "Unable to merge tree elements.";
}
}
diff --git a/src/main/java/edu/rpi/legup/history/PuzzleCommand.java b/src/main/java/edu/rpi/legup/history/PuzzleCommand.java
index 0c96b16f5..3768e3cbd 100644
--- a/src/main/java/edu/rpi/legup/history/PuzzleCommand.java
+++ b/src/main/java/edu/rpi/legup/history/PuzzleCommand.java
@@ -1,25 +1,18 @@
package edu.rpi.legup.history;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
public abstract class PuzzleCommand implements ICommand {
private CommandState state;
private boolean isCached;
private String cachedError;
- /**
- * Puzzle Command Constructor for creating an undoable and redoable change to the model.
- */
+ /** Puzzle Command Constructor for creating an undoable and redoable change to the model. */
protected PuzzleCommand() {
this.state = CommandState.CREATED;
this.isCached = false;
this.cachedError = null;
}
- /**
- * Executes an command
- */
+ /** Executes an command */
@Override
public final void execute() {
if (canExecute()) {
@@ -28,9 +21,7 @@ public final void execute() {
}
}
- /**
- * Determines whether this command can be executed
- */
+ /** Determines whether this command can be executed */
@Override
public final boolean canExecute() {
cachedError = getError();
@@ -42,14 +33,13 @@ public final boolean canExecute() {
* Gets the reason why the command cannot be executed
*
* @return if command cannot be executed, returns reason for why the command cannot be executed,
- * otherwise null if command can be executed
+ * otherwise null if command can be executed
*/
@Override
public final String getError() {
if (isCached) {
return cachedError;
- }
- else {
+ } else {
return getErrorString();
}
}
@@ -58,57 +48,44 @@ public final String getError() {
* Gets the reason why the command cannot be executed
*
* @return if command cannot be executed, returns reason for why the command cannot be executed,
- * otherwise null if command can be executed
+ * otherwise null if command can be executed
*/
public abstract String getErrorString();
- /**
- * Executes an command
- */
+ /** Executes an command */
public abstract void executeCommand();
- /**
- * Undoes an command
- */
+ /** Undoes an command */
public abstract void undoCommand();
- /**
- * Redoes an command
- */
+ /** Redoes an command */
public void redoCommand() {
if (state == CommandState.UNDOED) {
executeCommand();
state = CommandState.REDOED;
- }
- else {
+ } else {
throw new InvalidCommandStateTransition(this, state, CommandState.REDOED);
}
}
- /**
- * Undoes an command
- */
+ /** Undoes an command */
@Override
public final void undo() {
if (state == CommandState.EXECUTED || state == CommandState.REDOED) {
undoCommand();
state = CommandState.UNDOED;
- }
- else {
+ } else {
throw new InvalidCommandStateTransition(this, state, CommandState.UNDOED);
}
}
- /**
- * Redoes an command
- */
+ /** Redoes an command */
public final void redo() {
if (state == CommandState.UNDOED) {
redoCommand();
state = CommandState.REDOED;
- }
- else {
+ } else {
throw new InvalidCommandStateTransition(this, state, CommandState.REDOED);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java b/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java
index 398f17478..7737ecfd3 100644
--- a/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java
+++ b/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java
@@ -1,18 +1,17 @@
package edu.rpi.legup.history;
+import static edu.rpi.legup.app.GameBoardFacade.getInstance;
+
import edu.rpi.legup.app.GameBoardFacade;
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.rules.Rule;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;
-
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static edu.rpi.legup.app.GameBoardFacade.getInstance;
-
public class ValidateCaseRuleCommand extends PuzzleCommand {
private TreeViewSelection selection;
@@ -34,9 +33,7 @@ public ValidateCaseRuleCommand(TreeViewSelection selection, CaseRule caseRule) {
this.addNode = new HashMap<>();
}
- /**
- * Executes an command
- */
+ /** Executes an command */
@Override
public void executeCommand() {
Tree tree = getInstance().getTree();
@@ -58,8 +55,7 @@ public void executeCommand() {
if (childNode == null) {
childNode = (TreeNode) tree.addTreeElement(transition);
addNode.put(transition, childNode);
- }
- else {
+ } else {
childNode = (TreeNode) tree.addTreeElement(transition, childNode);
}
@@ -75,8 +71,7 @@ public void executeCommand() {
if (firstSelectedView.getType() == TreeElementType.NODE) {
TreeNodeView nodeView = (TreeNodeView) firstSelectedView;
finalTreeElement = nodeView.getChildrenViews().get(0).getTreeElement();
- }
- else {
+ } else {
TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView;
finalTreeElement = transitionView.getChildView().getTreeElement();
}
@@ -88,7 +83,7 @@ public void executeCommand() {
* Gets the reason why the command cannot be executed
*
* @return if command cannot be executed, returns reason for why the command cannot be executed,
- * otherwise null if command can be executed
+ * otherwise null if command can be executed
*/
@Override
public String getErrorString() {
@@ -100,8 +95,7 @@ public String getErrorString() {
for (TreeElementView view : selectedViews) {
if (view.getType() == TreeElementType.NODE) {
return CommandError.SELECTION_CONTAINS_NODE.toString();
- }
- else {
+ } else {
TreeTransitionView transView = (TreeTransitionView) view;
if (transView.getParentViews().size() > 1) {
return CommandError.CONTAINS_MERGE.toString();
@@ -111,9 +105,7 @@ public String getErrorString() {
return null;
}
- /**
- * Undoes an command
- */
+ /** Undoes an command */
@Override
public void undoCommand() {
Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
@@ -136,4 +128,4 @@ public void undoCommand() {
puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection));
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java
index 23f8dce21..8737b4008 100644
--- a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java
+++ b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java
@@ -5,7 +5,6 @@
import edu.rpi.legup.model.rules.ContradictionRule;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -19,10 +18,11 @@ public class ValidateContradictionRuleCommand extends PuzzleCommand {
private Map addTran;
/**
- * ValidateContradictionRuleCommand Constructor creates a puzzle command for verifying a contradiction rule
+ * ValidateContradictionRuleCommand Constructor creates a puzzle command for verifying a
+ * contradiction rule
*
* @param selection currently selected tree puzzleElement views
- * @param rule contradiction rule to be set to all the tree elements
+ * @param rule contradiction rule to be set to all the tree elements
*/
public ValidateContradictionRuleCommand(TreeViewSelection selection, ContradictionRule rule) {
this.selection = selection.copy();
@@ -31,9 +31,7 @@ public ValidateContradictionRuleCommand(TreeViewSelection selection, Contradicti
this.addTran = new HashMap<>();
}
- /**
- * Executes a command
- */
+ /** Executes a command */
@Override
public void executeCommand() {
Tree tree = GameBoardFacade.getInstance().getTree();
@@ -48,8 +46,7 @@ public void executeCommand() {
if (treeElement.getType() == TreeElementType.TRANSITION) {
TreeTransition transition = (TreeTransition) treeElement;
treeNode = transition.getParents().get(0);
- }
- else {
+ } else {
treeNode = (TreeNode) treeElement;
}
@@ -58,7 +55,11 @@ public void executeCommand() {
saveElements.put(treeNode, save);
}
- treeNode.getChildren().forEach(n -> puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(n)));
+ treeNode.getChildren()
+ .forEach(
+ n ->
+ puzzle.notifyTreeListeners(
+ listener -> listener.onTreeElementRemoved(n)));
treeNode.getChildren().clear();
@@ -68,8 +69,7 @@ public void executeCommand() {
transition.setRule(newRule);
transition.getBoard().setModifiable(false);
tree.addTreeElement(transition);
- }
- else {
+ } else {
transition.getBoard().setModifiable(false);
tree.addTreeElement(treeNode, transition);
}
@@ -85,19 +85,18 @@ public void executeCommand() {
if (firstSelectedView.getType() == TreeElementType.NODE) {
TreeNodeView nodeView = (TreeNodeView) firstSelectedView;
finalTreeElement = nodeView.getChildrenViews().get(0).getTreeElement();
- }
- else {
+ } else {
TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView;
if (transitionView.getChildView() != null) {
finalTreeElement = transitionView.getChildView().getTreeElement();
- }
- else {
+ } else {
finalTreeElement = null;
}
}
if (finalTreeElement != null) {
- puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
+ puzzle.notifyBoardListeners(
+ listener -> listener.onTreeElementChanged(finalTreeElement));
}
puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection));
}
@@ -106,7 +105,7 @@ public void executeCommand() {
* Gets the reason why the command cannot be executed
*
* @return if command cannot be executed, returns reason for why the command cannot be executed,
- * otherwise null if command can be executed
+ * otherwise null if command can be executed
*/
@Override
public String getErrorString() {
@@ -126,9 +125,7 @@ public String getErrorString() {
return null;
}
- /**
- * Undoes a command
- */
+ /** Undoes a command */
@Override
public void undoCommand() {
Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
@@ -140,18 +137,25 @@ public void undoCommand() {
if (element.getType() == TreeElementType.TRANSITION) {
TreeTransition transition = (TreeTransition) element;
node = transition.getParents().get(0);
- }
- else {
+ } else {
node = (TreeNode) element;
}
- node.getChildren().forEach(n -> puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(n)));
+ node.getChildren()
+ .forEach(
+ n ->
+ puzzle.notifyTreeListeners(
+ listener -> listener.onTreeElementRemoved(n)));
node.getChildren().clear();
ArrayList save = saveElements.get(node);
if (save != null) {
node.getChildren().addAll(save);
- node.getChildren().forEach(n -> puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(n)));
+ node.getChildren()
+ .forEach(
+ n ->
+ puzzle.notifyTreeListeners(
+ listener -> listener.onTreeElementAdded(n)));
}
}
diff --git a/src/main/java/edu/rpi/legup/history/ValidateDirectRuleCommand.java b/src/main/java/edu/rpi/legup/history/ValidateDirectRuleCommand.java
index 61babe883..d9c063464 100644
--- a/src/main/java/edu/rpi/legup/history/ValidateDirectRuleCommand.java
+++ b/src/main/java/edu/rpi/legup/history/ValidateDirectRuleCommand.java
@@ -1,152 +1,142 @@
-package edu.rpi.legup.history;
-
-import edu.rpi.legup.app.GameBoardFacade;
-import edu.rpi.legup.model.Puzzle;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.rules.Rule;
-import edu.rpi.legup.model.tree.*;
-import edu.rpi.legup.ui.proofeditorui.treeview.*;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class ValidateDirectRuleCommand extends PuzzleCommand {
- private TreeViewSelection selection;
-
- private Map oldRules;
- private Map addNode;
- private DirectRule newRule;
-
- /**
- * ValidateDesireRuleCommand Constructor creates a command for verifying a basic rule
- *
- * @param selection selection of tree elements
- * @param rule basic rule
- */
- public ValidateDirectRuleCommand(TreeViewSelection selection, DirectRule rule) {
- this.selection = selection.copy();
- this.newRule = rule;
- this.oldRules = new HashMap<>();
- this.addNode = new HashMap<>();
- }
-
- /**
- * Executes an command
- */
- @Override
- public void executeCommand() {
- Tree tree = GameBoardFacade.getInstance().getTree();
- TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView();
- Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
- final TreeViewSelection newSelection = new TreeViewSelection();
-
- List selectedViews = selection.getSelectedViews();
- for (TreeElementView selectedView : selectedViews) {
- TreeElement element = selectedView.getTreeElement();
- TreeTransitionView transitionView;
- if (element.getType() == TreeElementType.NODE) {
- TreeNodeView nodeView = (TreeNodeView) selectedView;
- transitionView = nodeView.getChildrenViews().get(0);
- }
- else {
- transitionView = (TreeTransitionView) selectedView;
- }
- TreeTransition transition = transitionView.getTreeElement();
-
- oldRules.put(transition, transition.getRule());
- transition.setRule(newRule);
-
- TreeNode childNode = transition.getChildNode();
- if (childNode == null) {
- childNode = addNode.get(transition);
- if (childNode == null) {
- childNode = (TreeNode) tree.addTreeElement(transition);
- addNode.put(transition, childNode);
- }
- else {
- tree.addTreeElement(transition, childNode);
- }
-
- final TreeNode finalNode = childNode;
- puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(finalNode));
- }
- newSelection.addToSelection(treeView.getElementView(childNode));
- }
- TreeElementView firstSelectedView = selection.getFirstSelection();
- final TreeElement finalTreeElement;
- if (firstSelectedView.getType() == TreeElementType.NODE) {
- TreeNodeView nodeView = (TreeNodeView) firstSelectedView;
- finalTreeElement = nodeView.getChildrenViews().get(0).getTreeElement();
- }
- else {
- TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView;
- finalTreeElement = transitionView.getChildView().getTreeElement();
- }
- puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
- puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection));
- }
-
- /**
- * Gets the reason why the command cannot be executed
- *
- * @return if command cannot be executed, returns reason for why the command cannot be executed,
- * otherwise null if command can be executed
- */
- @Override
- public String getErrorString() {
- List selectedViews = selection.getSelectedViews();
- if (selectedViews.isEmpty()) {
- return CommandError.NO_SELECTED_VIEWS.toString();
- }
-
- for (TreeElementView view : selectedViews) {
- if (view.getType() == TreeElementType.NODE) {
- TreeNodeView nodeView = (TreeNodeView) view;
- if (nodeView.getChildrenViews().size() != 1) {
- return CommandError.ONE_CHILD.toString();
- }
- }
- else {
- TreeTransitionView transView = (TreeTransitionView) view;
- if (transView.getParentViews().size() > 1) {
- return CommandError.CONTAINS_MERGE.toString();
- }
- }
- }
- return null;
- }
-
- /**
- * Undoes an command
- */
- @Override
- public void undoCommand() {
- Tree tree = GameBoardFacade.getInstance().getTree();
- Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
-
- for (TreeElementView selectedView : selection.getSelectedViews()) {
- TreeElement element = selectedView.getTreeElement();
- TreeTransitionView transitionView;
- if (element.getType() == TreeElementType.NODE) {
- TreeNodeView nodeView = (TreeNodeView) selectedView;
- transitionView = nodeView.getChildrenViews().get(0);
- }
- else {
- transitionView = (TreeTransitionView) selectedView;
- }
- TreeTransition transition = transitionView.getTreeElement();
- transition.setRule(oldRules.get(transition));
-
- if (addNode.get(transition) != null) {
- final TreeNode childNode = transition.getChildNode();
- tree.removeTreeElement(childNode);
- puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(childNode));
- }
- }
-
- final TreeElement finalTreeElement = selection.getFirstSelection().getTreeElement();
- puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
- puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection));
- }
-}
+package edu.rpi.legup.history;
+
+import edu.rpi.legup.app.GameBoardFacade;
+import edu.rpi.legup.model.Puzzle;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.rules.Rule;
+import edu.rpi.legup.model.tree.*;
+import edu.rpi.legup.ui.proofeditorui.treeview.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ValidateDirectRuleCommand extends PuzzleCommand {
+ private TreeViewSelection selection;
+
+ private Map oldRules;
+ private Map addNode;
+ private DirectRule newRule;
+
+ /**
+ * ValidateDesireRuleCommand Constructor creates a command for verifying a basic rule
+ *
+ * @param selection selection of tree elements
+ * @param rule basic rule
+ */
+ public ValidateDirectRuleCommand(TreeViewSelection selection, DirectRule rule) {
+ this.selection = selection.copy();
+ this.newRule = rule;
+ this.oldRules = new HashMap<>();
+ this.addNode = new HashMap<>();
+ }
+
+ /** Executes an command */
+ @Override
+ public void executeCommand() {
+ Tree tree = GameBoardFacade.getInstance().getTree();
+ TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView();
+ Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
+ final TreeViewSelection newSelection = new TreeViewSelection();
+
+ List selectedViews = selection.getSelectedViews();
+ for (TreeElementView selectedView : selectedViews) {
+ TreeElement element = selectedView.getTreeElement();
+ TreeTransitionView transitionView;
+ if (element.getType() == TreeElementType.NODE) {
+ TreeNodeView nodeView = (TreeNodeView) selectedView;
+ transitionView = nodeView.getChildrenViews().get(0);
+ } else {
+ transitionView = (TreeTransitionView) selectedView;
+ }
+ TreeTransition transition = transitionView.getTreeElement();
+
+ oldRules.put(transition, transition.getRule());
+ transition.setRule(newRule);
+
+ TreeNode childNode = transition.getChildNode();
+ if (childNode == null) {
+ childNode = addNode.get(transition);
+ if (childNode == null) {
+ childNode = (TreeNode) tree.addTreeElement(transition);
+ addNode.put(transition, childNode);
+ } else {
+ tree.addTreeElement(transition, childNode);
+ }
+
+ final TreeNode finalNode = childNode;
+ puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(finalNode));
+ }
+ newSelection.addToSelection(treeView.getElementView(childNode));
+ }
+ TreeElementView firstSelectedView = selection.getFirstSelection();
+ final TreeElement finalTreeElement;
+ if (firstSelectedView.getType() == TreeElementType.NODE) {
+ TreeNodeView nodeView = (TreeNodeView) firstSelectedView;
+ finalTreeElement = nodeView.getChildrenViews().get(0).getTreeElement();
+ } else {
+ TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView;
+ finalTreeElement = transitionView.getChildView().getTreeElement();
+ }
+ puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
+ puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection));
+ }
+
+ /**
+ * Gets the reason why the command cannot be executed
+ *
+ * @return if command cannot be executed, returns reason for why the command cannot be executed,
+ * otherwise null if command can be executed
+ */
+ @Override
+ public String getErrorString() {
+ List selectedViews = selection.getSelectedViews();
+ if (selectedViews.isEmpty()) {
+ return CommandError.NO_SELECTED_VIEWS.toString();
+ }
+
+ for (TreeElementView view : selectedViews) {
+ if (view.getType() == TreeElementType.NODE) {
+ TreeNodeView nodeView = (TreeNodeView) view;
+ if (nodeView.getChildrenViews().size() != 1) {
+ return CommandError.ONE_CHILD.toString();
+ }
+ } else {
+ TreeTransitionView transView = (TreeTransitionView) view;
+ if (transView.getParentViews().size() > 1) {
+ return CommandError.CONTAINS_MERGE.toString();
+ }
+ }
+ }
+ return null;
+ }
+
+ /** Undoes an command */
+ @Override
+ public void undoCommand() {
+ Tree tree = GameBoardFacade.getInstance().getTree();
+ Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule();
+
+ for (TreeElementView selectedView : selection.getSelectedViews()) {
+ TreeElement element = selectedView.getTreeElement();
+ TreeTransitionView transitionView;
+ if (element.getType() == TreeElementType.NODE) {
+ TreeNodeView nodeView = (TreeNodeView) selectedView;
+ transitionView = nodeView.getChildrenViews().get(0);
+ } else {
+ transitionView = (TreeTransitionView) selectedView;
+ }
+ TreeTransition transition = transitionView.getTreeElement();
+ transition.setRule(oldRules.get(transition));
+
+ if (addNode.get(transition) != null) {
+ final TreeNode childNode = transition.getChildNode();
+ tree.removeTreeElement(childNode);
+ puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(childNode));
+ }
+ }
+
+ final TreeElement finalTreeElement = selection.getFirstSelection().getTreeElement();
+ puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
+ puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection));
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/model/Puzzle.java b/src/main/java/edu/rpi/legup/model/Puzzle.java
index 18614131b..7971c95af 100644
--- a/src/main/java/edu/rpi/legup/model/Puzzle.java
+++ b/src/main/java/edu/rpi/legup/model/Puzzle.java
@@ -1,6 +1,7 @@
package edu.rpi.legup.model;
import edu.rpi.legup.model.elements.*;
+import edu.rpi.legup.model.elements.Element;
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.ElementFactory;
import edu.rpi.legup.model.observer.IBoardListener;
@@ -12,32 +13,27 @@
import edu.rpi.legup.model.tree.TreeElement;
import edu.rpi.legup.model.tree.TreeElementType;
import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
-import edu.rpi.legup.ui.puzzleeditorui.elementsview.NonPlaceableElementPanel;
-import edu.rpi.legup.utility.LegupUtils;
-import org.w3c.dom.Document;
-import edu.rpi.legup.model.elements.Element;
-import org.w3c.dom.Node;
import edu.rpi.legup.save.InvalidFileFormatException;
import edu.rpi.legup.ui.boardview.BoardView;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
+import edu.rpi.legup.utility.LegupUtils;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
-import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
-
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
public abstract class Puzzle implements IBoardSubject, ITreeSubject {
private static final Logger LOGGER = LogManager.getLogger(Puzzle.class.getName());
@@ -59,9 +55,7 @@ public abstract class Puzzle implements IBoardSubject, ITreeSubject {
protected List placeableElements;
protected List nonPlaceableElements;
- /**
- * Puzzle Constructor - creates a new Puzzle
- */
+ /** Puzzle Constructor - creates a new Puzzle */
public Puzzle() {
this.boardListeners = new ArrayList<>();
this.treeListeners = new ArrayList<>();
@@ -87,7 +81,7 @@ private void registerPuzzleElements() {
System.out.println("possible element: " + c.getName());
- //check that the element is not abstract
+ // check that the element is not abstract
if (Modifier.isAbstract(c.getModifiers())) continue;
for (Annotation a : c.getAnnotations()) {
@@ -107,8 +101,7 @@ private void registerPuzzleElements() {
default:
break;
}
- }
- catch (InvocationTargetException e) {
+ } catch (InvocationTargetException e) {
System.out.println(" Failed ");
e.getTargetException().printStackTrace();
}
@@ -116,12 +109,14 @@ private void registerPuzzleElements() {
}
}
-// } catch (IOException | ClassNotFoundException | NoSuchMethodException |
-// InstantiationException | IllegalAccessException | InvocationTargetException e) {
-// LOGGER.error("Unable to find rules for " + this.getClass().getSimpleName(), e);
-// }
- }
- catch (Exception e) {
+ // } catch (IOException | ClassNotFoundException | NoSuchMethodException |
+ // InstantiationException | IllegalAccessException |
+ // InvocationTargetException
+ // e) {
+ // LOGGER.error("Unable to find rules for " +
+ // this.getClass().getSimpleName(), e);
+ // }
+ } catch (Exception e) {
LOGGER.error("Unable to find elements for " + this.getClass().getSimpleName(), e);
}
}
@@ -136,7 +131,7 @@ private void registerRules() {
System.out.println("possible rule: " + c.getName());
- //check that the rule is not abstract
+ // check that the rule is not abstract
if (Modifier.isAbstract(c.getModifiers())) continue;
for (Annotation a : c.getAnnotations()) {
@@ -161,8 +156,7 @@ private void registerRules() {
default:
break;
}
- }
- catch (InvocationTargetException e) {
+ } catch (InvocationTargetException e) {
System.out.println(" Failed ");
e.getTargetException().printStackTrace();
}
@@ -170,19 +164,19 @@ private void registerRules() {
}
}
-// } catch (IOException | ClassNotFoundException | NoSuchMethodException |
-// InstantiationException | IllegalAccessException | InvocationTargetException e) {
-// LOGGER.error("Unable to find rules for " + this.getClass().getSimpleName(), e);
-// }
- }
- catch (Exception e) {
+ // } catch (IOException | ClassNotFoundException | NoSuchMethodException |
+ // InstantiationException | IllegalAccessException |
+ // InvocationTargetException
+ // e) {
+ // LOGGER.error("Unable to find rules for " +
+ // this.getClass().getSimpleName(), e);
+ // }
+ } catch (Exception e) {
LOGGER.error("Unable to find rules for " + this.getClass().getSimpleName(), e);
}
}
- /**
- * Initializes the view. Called by the invoker of the class
- */
+ /** Initializes the view. Called by the invoker of the class */
public abstract void initializeView();
/**
@@ -196,7 +190,7 @@ private void registerRules() {
/**
* Checks if the given height and width are valid board dimensions for the given puzzle
*
- * @param rows the number of rows on the board
+ * @param rows the number of rows on the board
* @param columns the number of columns on the board
* @return true if the given dimensions are valid for the given puzzle, false otherwise
*/
@@ -230,13 +224,13 @@ public boolean isPuzzleComplete() {
if (leaf.getType() == TreeElementType.NODE) {
TreeNode node = (TreeNode) leaf;
if (!node.isRoot()) {
- isComplete &= node.getParent().isContradictoryBranch() || isBoardComplete(node.getBoard());
- }
- else {
+ isComplete &=
+ node.getParent().isContradictoryBranch()
+ || isBoardComplete(node.getBoard());
+ } else {
isComplete &= isBoardComplete(node.getBoard());
}
- }
- else {
+ } else {
isComplete = false;
}
}
@@ -268,8 +262,7 @@ public boolean isPuzzleComplete() {
public void importPuzzle(String fileName) throws InvalidFileFormatException {
try {
importPuzzle(new FileInputStream(fileName));
- }
- catch (IOException e) {
+ } catch (IOException e) {
LOGGER.error("Importing puzzle error", e);
throw new InvalidFileFormatException("Could not find file");
}
@@ -287,8 +280,7 @@ public void importPuzzle(InputStream inputStream) throws InvalidFileFormatExcept
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(inputStream);
- }
- catch (IOException | SAXException | ParserConfigurationException e) {
+ } catch (IOException | SAXException | ParserConfigurationException e) {
LOGGER.error("Importing puzzle error", e);
throw new InvalidFileFormatException("Could not find file");
}
@@ -300,8 +292,7 @@ public void importPuzzle(InputStream inputStream) throws InvalidFileFormatExcept
throw new InvalidFileFormatException("Puzzle importer null");
}
importer.initializePuzzle(node);
- }
- else {
+ } else {
LOGGER.error("Invalid file");
throw new InvalidFileFormatException("Invalid file: must be a Legup file");
}
@@ -351,7 +342,6 @@ public List getNonPlaceableElements() {
return nonPlaceableElements;
}
-
/**
* Sets the list of direct rules
*
diff --git a/src/main/java/edu/rpi/legup/model/PuzzleExporter.java b/src/main/java/edu/rpi/legup/model/PuzzleExporter.java
index 613d2ed1c..a052a736a 100644
--- a/src/main/java/edu/rpi/legup/model/PuzzleExporter.java
+++ b/src/main/java/edu/rpi/legup/model/PuzzleExporter.java
@@ -3,23 +3,21 @@
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
-import org.w3c.dom.Document;
import edu.rpi.legup.save.ExportFileException;
-
+import java.io.File;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import java.io.File;
-import java.util.*;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.time.ZoneId;
-
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
public abstract class PuzzleExporter {
@@ -60,7 +58,8 @@ public void exportPuzzle(String fileName) throws ExportFileException {
legupElement.appendChild(puzzleElement);
puzzleElement.appendChild(createBoardElement(newDocument));
- if (puzzle.getTree() != null && !puzzle.getTree().getRootNode().getChildren().isEmpty()) {
+ if (puzzle.getTree() != null
+ && !puzzle.getTree().getRootNode().getChildren().isEmpty()) {
puzzleElement.appendChild(createProofElement(newDocument));
}
@@ -84,13 +83,11 @@ public void exportPuzzle(String fileName) throws ExportFileException {
StreamResult result = new StreamResult(new File(fileName));
transformer.transform(source, result);
- }
- catch (ParserConfigurationException | TransformerException e) {
+ } catch (ParserConfigurationException | TransformerException e) {
throw new ExportFileException("Puzzle Exporter: parser configuration exception");
- }
- catch (Exception e) {
+ } catch (Exception e) {
throw e;
- //throw new ExportFileException(e.getMessage());
+ // throw new ExportFileException(e.getMessage());
}
}
diff --git a/src/main/java/edu/rpi/legup/model/PuzzleImporter.java b/src/main/java/edu/rpi/legup/model/PuzzleImporter.java
index 327a92773..0cc163200 100644
--- a/src/main/java/edu/rpi/legup/model/PuzzleImporter.java
+++ b/src/main/java/edu/rpi/legup/model/PuzzleImporter.java
@@ -6,14 +6,13 @@
import edu.rpi.legup.model.rules.Rule;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import java.util.*;
-
public abstract class PuzzleImporter {
private static final Logger LOGGER = LogManager.getLogger(PuzzleImporter.class.getName());
@@ -35,20 +34,20 @@ public PuzzleImporter(Puzzle puzzle) {
/**
* Initializes an empty puzzle
*
- * @param rows number of rows on the puzzle
+ * @param rows number of rows on the puzzle
* @param columns number of columns on the puzzle
* @throws RuntimeException if puzzle can not be made
*/
public void initializePuzzle(int rows, int columns) throws RuntimeException {
if (this.puzzle.isValidDimensions(rows, columns)) {
initializeBoard(rows, columns);
- }
- else {
+ } else {
throw new IllegalArgumentException("Invalid dimensions provided");
}
}
- public void initializePuzzle(String[] statements) throws InputMismatchException, IllegalArgumentException {
+ public void initializePuzzle(String[] statements)
+ throws InputMismatchException, IllegalArgumentException {
// Note: Error checking for the statements will be left up to the puzzles that support
// text input. For example, some puzzles may be okay with "blank" statements (Strings with
// length = 0) while others may not.
@@ -72,46 +71,49 @@ public void initializePuzzle(Node node) throws InvalidFileFormatException {
Node n = childNodes.item(i);
if (n.getNodeName().equalsIgnoreCase("board")) {
if (initBoard) {
- throw new InvalidFileFormatException("Puzzle creation error: duplicate board puzzleElement found");
+ throw new InvalidFileFormatException(
+ "Puzzle creation error: duplicate board puzzleElement found");
}
initializeBoard(n);
initBoard = true;
- }
- else {
+ } else {
if (n.getNodeName().equalsIgnoreCase("proof")) {
if (initProof) {
- throw new InvalidFileFormatException("Puzzle creation error: duplicate proof puzzleElement found");
+ throw new InvalidFileFormatException(
+ "Puzzle creation error: duplicate proof puzzleElement found");
}
if (!initBoard) {
- throw new InvalidFileFormatException("Puzzle creation error: could not find board puzzleElement");
+ throw new InvalidFileFormatException(
+ "Puzzle creation error: could not find board puzzleElement");
}
initializeProof(n);
initProof = true;
- }
- else {
+ } else {
if (!n.getNodeName().equalsIgnoreCase("#text")) {
- throw new InvalidFileFormatException("Puzzle creation error: unknown node found in file");
+ throw new InvalidFileFormatException(
+ "Puzzle creation error: unknown node found in file");
}
}
}
}
if (!initBoard) {
- throw new InvalidFileFormatException("Puzzle creation error: could not find board puzzleElement");
+ throw new InvalidFileFormatException(
+ "Puzzle creation error: could not find board puzzleElement");
}
if (!initProof) {
createDefaultTree();
}
- }
- else {
- throw new InvalidFileFormatException("Invalid file format; does not contain \"puzzle\" node");
+ } else {
+ throw new InvalidFileFormatException(
+ "Invalid file format; does not contain \"puzzle\" node");
}
}
/**
* Creates the board for building
*
- * @param rows number of rows on the puzzle
+ * @param rows number of rows on the puzzle
* @param columns number of columns on the puzzle
* @throws RuntimeException if board can not be created
*/
@@ -125,7 +127,8 @@ public void initializePuzzle(Node node) throws InvalidFileFormatException {
*/
public abstract void initializeBoard(Node node) throws InvalidFileFormatException;
- public abstract void initializeBoard(String[] statements) throws UnsupportedOperationException, IllegalArgumentException;
+ public abstract void initializeBoard(String[] statements)
+ throws UnsupportedOperationException, IllegalArgumentException;
/**
* Creates the proof for building
@@ -143,21 +146,22 @@ public void initializeProof(Node node) throws InvalidFileFormatException {
Node n = treeList.item(i);
if (n.getNodeName().equalsIgnoreCase("tree")) {
if (initTree) {
- throw new InvalidFileFormatException("Proof Tree construction error: duplicate tree puzzleElement");
+ throw new InvalidFileFormatException(
+ "Proof Tree construction error: duplicate tree puzzleElement");
}
createTree(n);
initTree = true;
- }
- else {
- throw new InvalidFileFormatException("Proof Tree construction error: unknown puzzleElement found");
+ } else {
+ throw new InvalidFileFormatException(
+ "Proof Tree construction error: unknown puzzleElement found");
}
}
if (!initTree) {
createDefaultTree();
}
- }
- else {
- throw new InvalidFileFormatException("Invalid file format; does not contain \"proof\" node");
+ } else {
+ throw new InvalidFileFormatException(
+ "Invalid file format; does not contain \"proof\" node");
}
}
@@ -171,7 +175,8 @@ protected void setCells(Node node) throws InvalidFileFormatException {
NodeList dataList = ((org.w3c.dom.Element) node).getElementsByTagName("cell");
Board board = puzzle.getCurrentBoard();
for (int i = 0; i < dataList.getLength(); i++) {
- PuzzleElement data = puzzle.getFactory().importCell(dataList.item(i), puzzle.getCurrentBoard());
+ PuzzleElement data =
+ puzzle.getFactory().importCell(dataList.item(i), puzzle.getCurrentBoard());
board.setPuzzleElement(data.getIndex(), data);
}
}
@@ -199,15 +204,18 @@ 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")) {
if (tree.getRootNode() != null) {
- throw new InvalidFileFormatException("Proof Tree construction error: multiple root nodes declared");
+ throw new InvalidFileFormatException(
+ "Proof Tree construction error: multiple root nodes declared");
}
treeNode.setRoot(true);
tree.setRootNode(treeNode);
@@ -215,7 +223,6 @@ protected void createTree(Node node) throws InvalidFileFormatException {
treeNodes.put(nodeId, treeNode);
}
-
for (int i = 0; i < nodeList.getLength(); i++) {
org.w3c.dom.Element treeNodeElement = (org.w3c.dom.Element) nodeList.item(i);
String nodeId = treeNodeElement.getAttribute("id");
@@ -231,11 +238,10 @@ protected void createTree(Node node) throws InvalidFileFormatException {
transition.addParent(treeNode);
treeNode.addChild(transition);
continue;
+ } else {
+ throw new InvalidFileFormatException(
+ "Proof Tree construction error: duplicate transition ID found");
}
- else {
- throw new InvalidFileFormatException("Proof Tree construction error: duplicate transition ID found");
- }
-
}
String childId = trans.getAttribute("child");
@@ -250,7 +256,8 @@ protected void createTree(Node node) throws InvalidFileFormatException {
if (!ruleName.isEmpty()) {
rule = puzzle.getRuleByID(ruleId);
if (rule == null) {
- throw new InvalidFileFormatException("Proof Tree construction error: could not find rule by ID");
+ throw new InvalidFileFormatException(
+ "Proof Tree construction error: could not find rule by ID");
}
transition.setRule(rule);
}
@@ -266,14 +273,16 @@ protected void createTree(Node node) throws InvalidFileFormatException {
}
}
- //validateTreeStructure(treeNodes, treeTransitions);
+ // validateTreeStructure(treeNodes, treeTransitions);
System.err.println("Tree Size: " + treeTransitions.size());
for (Map.Entry entry : nodeChanges.entrySet()) {
makeTransitionChanges(entry.getKey(), entry.getValue());
}
}
- protected void validateTreeStructure(HashMap nodes, HashMap transitions) throws InvalidFileFormatException {
+ protected void validateTreeStructure(
+ HashMap nodes, HashMap transitions)
+ throws InvalidFileFormatException {
Tree tree = puzzle.getTree();
if (tree == null) {
@@ -300,25 +309,27 @@ protected void validateTreeStructure(HashMap nodes, HashMap nodes, HashMap mergingNodes = transition.getParents();
List mergingBoards = new ArrayList<>();
@@ -349,7 +363,8 @@ protected void makeTransitionChanges(TreeTransition transition, Node transElemen
TreeNode lca = Tree.getLowestCommonAncestor(mergingNodes);
if (lca == null) {
- throw new InvalidFileFormatException("Proof Tree construction error: unable to find merge node");
+ throw new InvalidFileFormatException(
+ "Proof Tree construction error: unable to find merge node");
}
Board lcaBoard = lca.getBoard();
@@ -360,8 +375,7 @@ protected void makeTransitionChanges(TreeTransition transition, Node transElemen
if (childNode != null) {
childNode.setBoard(mergedBoard.copy());
}
- }
- else {
+ } else {
NodeList cellList = transElement.getChildNodes();
for (int i = 0; i < cellList.getLength(); i++) {
Node node = cellList.item(i);
@@ -372,10 +386,10 @@ protected void makeTransitionChanges(TreeTransition transition, Node transElemen
board.setPuzzleElement(cell.getIndex(), cell);
board.addModifiedData(cell);
transition.propagateChange(cell);
- }
- else {
+ } else {
if (!node.getNodeName().equalsIgnoreCase("#text")) {
- throw new InvalidFileFormatException("Proof Tree construction error: unknown node in transition");
+ throw new InvalidFileFormatException(
+ "Proof Tree construction error: unknown node in transition");
}
}
}
diff --git a/src/main/java/edu/rpi/legup/model/RegisterPuzzle.java b/src/main/java/edu/rpi/legup/model/RegisterPuzzle.java
index 32f01edbc..c4c1ed273 100644
--- a/src/main/java/edu/rpi/legup/model/RegisterPuzzle.java
+++ b/src/main/java/edu/rpi/legup/model/RegisterPuzzle.java
@@ -7,6 +7,4 @@
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
-public @interface RegisterPuzzle {
-
-}
+public @interface RegisterPuzzle {}
diff --git a/src/main/java/edu/rpi/legup/model/elements/Element.java b/src/main/java/edu/rpi/legup/model/elements/Element.java
index 7ab502c63..8b75d075d 100644
--- a/src/main/java/edu/rpi/legup/model/elements/Element.java
+++ b/src/main/java/edu/rpi/legup/model/elements/Element.java
@@ -1,10 +1,8 @@
package edu.rpi.legup.model.elements;
-import edu.rpi.legup.model.rules.RuleType;
-
-import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
+import javax.swing.*;
@RegisterElement
public abstract class Element {
@@ -31,10 +29,11 @@ public Element(String elementID, String elementName, String description, String
private void loadImage() {
if (imageName != null) {
this.image = new ImageIcon(ClassLoader.getSystemClassLoader().getResource(imageName));
- //Resize images to be 100px wide
+ // Resize images to be 100px wide
Image image = this.image.getImage();
if (this.image.getIconWidth() < 120) return;
- int height = (int) (100 * ((double) this.image.getIconHeight() / this.image.getIconWidth()));
+ int height =
+ (int) (100 * ((double) this.image.getIconHeight() / this.image.getIconWidth()));
if (height == 0) {
System.out.println("height is 0 error");
System.out.println("height: " + this.image.getIconHeight());
diff --git a/src/main/java/edu/rpi/legup/model/elements/ElementType.java b/src/main/java/edu/rpi/legup/model/elements/ElementType.java
index ea47ca0eb..dff4fe04f 100644
--- a/src/main/java/edu/rpi/legup/model/elements/ElementType.java
+++ b/src/main/java/edu/rpi/legup/model/elements/ElementType.java
@@ -1,5 +1,6 @@
package edu.rpi.legup.model.elements;
public enum ElementType {
- PLACEABLE, NONPLACEABLE
+ PLACEABLE,
+ NONPLACEABLE
}
diff --git a/src/main/java/edu/rpi/legup/model/elements/NonPlaceableElement.java b/src/main/java/edu/rpi/legup/model/elements/NonPlaceableElement.java
index 87859991f..4ab0ab509 100644
--- a/src/main/java/edu/rpi/legup/model/elements/NonPlaceableElement.java
+++ b/src/main/java/edu/rpi/legup/model/elements/NonPlaceableElement.java
@@ -1,7 +1,8 @@
package edu.rpi.legup.model.elements;
public abstract class NonPlaceableElement extends Element {
- public NonPlaceableElement(String elementID, String elementName, String description, String imageName) {
+ public NonPlaceableElement(
+ String elementID, String elementName, String description, String imageName) {
super(elementID, elementName, description, imageName);
this.elementType = ElementType.NONPLACEABLE;
}
diff --git a/src/main/java/edu/rpi/legup/model/elements/PlaceableElement.java b/src/main/java/edu/rpi/legup/model/elements/PlaceableElement.java
index 2d018ddbb..133658700 100644
--- a/src/main/java/edu/rpi/legup/model/elements/PlaceableElement.java
+++ b/src/main/java/edu/rpi/legup/model/elements/PlaceableElement.java
@@ -1,7 +1,8 @@
package edu.rpi.legup.model.elements;
public abstract class PlaceableElement extends Element {
- public PlaceableElement(String elementID, String elementName, String description, String imageName) {
+ public PlaceableElement(
+ String elementID, String elementName, String description, String imageName) {
super(elementID, elementName, description, imageName);
this.elementType = ElementType.PLACEABLE;
}
diff --git a/src/main/java/edu/rpi/legup/model/elements/RegisterElement.java b/src/main/java/edu/rpi/legup/model/elements/RegisterElement.java
index bda3f3070..368ecc8d1 100644
--- a/src/main/java/edu/rpi/legup/model/elements/RegisterElement.java
+++ b/src/main/java/edu/rpi/legup/model/elements/RegisterElement.java
@@ -6,6 +6,4 @@
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
-public @interface RegisterElement {
-
-}
+public @interface RegisterElement {}
diff --git a/src/main/java/edu/rpi/legup/model/gameboard/Board.java b/src/main/java/edu/rpi/legup/model/gameboard/Board.java
index 4bf2ff548..d8bdf5199 100644
--- a/src/main/java/edu/rpi/legup/model/gameboard/Board.java
+++ b/src/main/java/edu/rpi/legup/model/gameboard/Board.java
@@ -11,9 +11,7 @@ public abstract class Board {
protected Set modifiedData;
protected boolean isModifiable;
- /**
- * Board Constructor creates an empty board.
- */
+ /** Board Constructor creates an empty board. */
public Board() {
this.puzzleElements = new ArrayList<>();
this.modifiedData = new HashSet<>();
@@ -46,7 +44,7 @@ public PuzzleElement getPuzzleElement(PuzzleElement puzzleElement) {
/**
* Sets a specific {@link PuzzleElement} on the board.
*
- * @param index index of the puzzleElement
+ * @param index index of the puzzleElement
* @param puzzleElement new puzzleElement at the index
*/
public void setPuzzleElement(int index, PuzzleElement puzzleElement) {
@@ -139,8 +137,8 @@ public void removeModifiedData(PuzzleElement data) {
}
/**
- * Called when a {@link PuzzleElement} data on this has changed and passes in the equivalent puzzle element with
- * the new data.
+ * Called when a {@link PuzzleElement} data on this has changed and passes in the equivalent
+ * puzzle element with the new data.
*
* @param puzzleElement equivalent puzzle element with the new data.
*/
@@ -150,22 +148,20 @@ public void notifyChange(PuzzleElement puzzleElement) {
}
/**
- * Called when a {@link PuzzleElement} has been added and passes in the equivalent puzzle element with the data.
+ * Called when a {@link PuzzleElement} has been added and passes in the equivalent puzzle
+ * element with the data.
*
* @param puzzleElement equivalent puzzle element with the data.
*/
- public void notifyAddition(PuzzleElement puzzleElement) {
-
- }
+ public void notifyAddition(PuzzleElement puzzleElement) {}
/**
- * Called when a {@link PuzzleElement} has been deleted and passes in the equivalent puzzle element with the data.
+ * Called when a {@link PuzzleElement} has been deleted and passes in the equivalent puzzle
+ * element with the data.
*
* @param puzzleElement equivalent puzzle element with the data.
*/
- public void notifyDeletion(PuzzleElement puzzleElement) {
-
- }
+ public void notifyDeletion(PuzzleElement puzzleElement) {}
@SuppressWarnings("unchecked")
public Board mergedBoard(Board lca, List boards) {
diff --git a/src/main/java/edu/rpi/legup/model/gameboard/CaseBoard.java b/src/main/java/edu/rpi/legup/model/gameboard/CaseBoard.java
index 799825025..fa3625a43 100644
--- a/src/main/java/edu/rpi/legup/model/gameboard/CaseBoard.java
+++ b/src/main/java/edu/rpi/legup/model/gameboard/CaseBoard.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.model.gameboard;
import edu.rpi.legup.model.rules.CaseRule;
-
import java.awt.event.MouseEvent;
import java.util.HashSet;
import java.util.Set;
diff --git a/src/main/java/edu/rpi/legup/model/gameboard/ElementFactory.java b/src/main/java/edu/rpi/legup/model/gameboard/ElementFactory.java
index 99e9bf65a..bfc785bdd 100644
--- a/src/main/java/edu/rpi/legup/model/gameboard/ElementFactory.java
+++ b/src/main/java/edu/rpi/legup/model/gameboard/ElementFactory.java
@@ -1,28 +1,30 @@
package edu.rpi.legup.model.gameboard;
+import edu.rpi.legup.save.InvalidFileFormatException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import edu.rpi.legup.save.InvalidFileFormatException;
public abstract class ElementFactory {
/**
* Creates a {@link PuzzleElement} based on the xml document Node and adds it to the board.
*
- * @param node node that represents the puzzleElement
+ * @param node node that represents the puzzleElement
* @param board board to add the newly created cell
* @return newly created cell from the xml document Node
- * @throws InvalidFileFormatException thrown if the xml node is invalid for the specific puzzle element
+ * @throws InvalidFileFormatException thrown if the xml node is invalid for the specific puzzle
+ * element
*/
- public abstract PuzzleElement importCell(Node node, Board board) throws InvalidFileFormatException;
+ public abstract PuzzleElement importCell(Node node, Board board)
+ throws InvalidFileFormatException;
/**
* Creates a xml document {@link PuzzleElement} from a cell for exporting.
*
- * @param document xml document
+ * @param document xml document
* @param puzzleElement PuzzleElement cell
* @return xml PuzzleElement
*/
public abstract Element exportCell(Document document, PuzzleElement puzzleElement);
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java b/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java
index d31e8185a..9593690ce 100644
--- a/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java
+++ b/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java
@@ -1,10 +1,8 @@
package edu.rpi.legup.model.gameboard;
import edu.rpi.legup.model.elements.Element;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
import edu.rpi.legup.puzzle.treetent.TreeTentBoard;
import edu.rpi.legup.puzzle.treetent.TreeTentClue;
-
import java.awt.*;
import java.awt.event.MouseEvent;
@@ -15,7 +13,7 @@ public class GridBoard extends Board {
/**
* GridBoard Constructor creates a board for grid using puzzles from a width and height.
*
- * @param width width of the board
+ * @param width width of the board
* @param height height of the board
*/
public GridBoard(int width, int height) {
@@ -43,83 +41,88 @@ public GridBoard(int size) {
* @return grid cell at location (x, y)
*/
public GridCell getCell(int x, int y) {
- if (y * dimension.width + x >= puzzleElements.size() || x >= dimension.width ||
- y >= dimension.height || x < 0 || y < 0) {
- System.err.printf("not in bounds, bounds are %dx%d\n", dimension.width, dimension.height);
+ if (y * dimension.width + x >= puzzleElements.size()
+ || x >= dimension.width
+ || y >= dimension.height
+ || x < 0
+ || y < 0) {
+ System.err.printf(
+ "not in bounds, bounds are %dx%d\n", dimension.width, dimension.height);
return null;
}
return (GridCell) puzzleElements.get(y * dimension.width + x);
}
/**
- * Sets the {@link GridCell} at the location (x,y). This method does not set the cell if the location specified is
- * out of bounds.
+ * Sets the {@link GridCell} at the location (x,y). This method does not set the cell if the
+ * location specified is out of bounds.
*
- * @param x x location of the cell
- * @param y y location of the cell
+ * @param x x location of the cell
+ * @param y y location of the cell
* @param cell grid cell to set at location (x,y)
*/
public void setCell(int x, int y, GridCell cell) {
- if (y * dimension.width + x >= puzzleElements.size() || x >= dimension.width ||
- y >= dimension.height || x < 0 || y < 0) {
+ if (y * dimension.width + x >= puzzleElements.size()
+ || x >= dimension.width
+ || y >= dimension.height
+ || x < 0
+ || y < 0) {
return;
}
puzzleElements.set(y * dimension.width + x, cell);
}
public void setCell(int x, int y, Element e, MouseEvent m) {
- if (this instanceof TreeTentBoard && ((y == dimension.height && 0 <= x && x < dimension.width) || (x == dimension.width && 0 <= y && y < dimension.height))) {
+ if (this instanceof TreeTentBoard
+ && ((y == dimension.height && 0 <= x && x < dimension.width)
+ || (x == dimension.width && 0 <= y && y < dimension.height))) {
TreeTentBoard treeTentBoard = ((TreeTentBoard) this);
TreeTentClue clue = treeTentBoard.getClue(x, y);
if (y == dimension.height) {
if (m.getButton() == MouseEvent.BUTTON1) {
if (clue.getData() < dimension.height) {
clue.setData(clue.getData() + 1);
- }
- else {
+ } else {
clue.setData(0);
}
- }
- else {
+ } else {
if (clue.getData() > 0) {
clue.setData(clue.getData() - 1);
- }
- else {
+ } else {
clue.setData(dimension.height);
}
}
- }
- else { //x == dimension.width
+ } else { // x == dimension.width
if (m.getButton() == MouseEvent.BUTTON1) {
if (clue.getData() < dimension.width) {
clue.setData(clue.getData() + 1);
- }
- else {
+ } else {
clue.setData(0);
}
- }
- else {
+ } else {
if (clue.getData() > 0) {
clue.setData(clue.getData() - 1);
- }
- else {
+ } else {
clue.setData(dimension.width);
}
}
}
- }
- else {
- if (e != null && y * dimension.width + x >= puzzleElements.size() || x >= dimension.width ||
- y >= dimension.height || x < 0 || y < 0) {
+ } else {
+ if (e != null && y * dimension.width + x >= puzzleElements.size()
+ || x >= dimension.width
+ || y >= dimension.height
+ || x < 0
+ || y < 0) {
return;
- }
- else {
+ } else {
if (e != null) {
puzzleElements.get(y * dimension.width + x).setType(e, m);
}
}
}
-// puzzleElements.set(y * dimension.width + x, puzzleElements.get(y * dimension.width + x));
+ // puzzleElements.set(y * dimension.width + x, puzzleElements.get(y * dimension.width
+ // +
+ // x));
}
/**
@@ -163,4 +166,4 @@ public GridBoard copy() {
}
return newGridBoard;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/model/gameboard/GridCell.java b/src/main/java/edu/rpi/legup/model/gameboard/GridCell.java
index 8209c0b6f..a33c3ec80 100644
--- a/src/main/java/edu/rpi/legup/model/gameboard/GridCell.java
+++ b/src/main/java/edu/rpi/legup/model/gameboard/GridCell.java
@@ -8,7 +8,7 @@ public class GridCell extends PuzzleElement {
/**
* GridCell Constructor creates a grid cell at the specified location given as a {@link Point}
*
- * @param value data value that represents the grid cell
+ * @param value data value that represents the grid cell
* @param location location on the board
*/
public GridCell(T value, Point location) {
@@ -20,8 +20,8 @@ public GridCell(T value, Point location) {
* GridCell Constructor creates a grid cell at the specified location given as x,y pair
*
* @param value data value that represents the grid cell
- * @param x x location
- * @param y y location
+ * @param x x location
+ * @param y y location
*/
public GridCell(T value, int x, int y) {
this(value, new Point(x, y));
@@ -59,4 +59,3 @@ public GridCell copy() {
return copy;
}
}
-
diff --git a/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java b/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java
index 3d84287e3..4ce030a04 100644
--- a/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java
+++ b/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.model.gameboard;
import edu.rpi.legup.model.elements.Element;
-
import java.awt.event.MouseEvent;
public abstract class PuzzleElement {
@@ -13,9 +12,7 @@ public abstract class PuzzleElement {
protected boolean isValid;
protected int casesDepended;
- /**
- * PuzzleElement Constructor creates a new puzzle element.
- */
+ /** PuzzleElement Constructor creates a new puzzle element. */
public PuzzleElement() {
this.index = -1;
this.data = null;
@@ -131,8 +128,8 @@ public void setGiven(boolean given) {
}
/**
- * Get whether this puzzle element data is a valid change according to the rule applied to the transition that
- * this puzzle element is contained in.
+ * Get whether this puzzle element data is a valid change according to the rule applied to the
+ * transition that this puzzle element is contained in.
*
* @return true if the puzzle element logically follows from the rule, otherwise false.
*/
@@ -141,8 +138,8 @@ public boolean isValid() {
}
/**
- * Sets whether this puzzle element data is a valid change according to the rule applied to the transition that
- * this puzzle element is contained in.
+ * Sets whether this puzzle element data is a valid change according to the rule applied to the
+ * transition that this puzzle element is contained in.
*
* @param isValid true if the puzzle element logically follows from the rule, otherwise false.
*/
diff --git a/src/main/java/edu/rpi/legup/model/observer/ITreeListener.java b/src/main/java/edu/rpi/legup/model/observer/ITreeListener.java
index d8fa24166..d5e7fdb2d 100644
--- a/src/main/java/edu/rpi/legup/model/observer/ITreeListener.java
+++ b/src/main/java/edu/rpi/legup/model/observer/ITreeListener.java
@@ -25,8 +25,6 @@ public interface ITreeListener {
*/
void onTreeSelectionChanged(TreeViewSelection selection);
- /**
- * Called when the model has finished updating the tree.
- */
+ /** Called when the model has finished updating the tree. */
void onUpdateTree();
}
diff --git a/src/main/java/edu/rpi/legup/model/rules/CaseRule.java b/src/main/java/edu/rpi/legup/model/rules/CaseRule.java
index a01db2b6d..e87896fcc 100644
--- a/src/main/java/edu/rpi/legup/model/rules/CaseRule.java
+++ b/src/main/java/edu/rpi/legup/model/rules/CaseRule.java
@@ -1,17 +1,16 @@
package edu.rpi.legup.model.rules;
+import static edu.rpi.legup.model.rules.RuleType.CASE;
+
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.CaseBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import static edu.rpi.legup.model.rules.RuleType.CASE;
-
public abstract class CaseRule extends Rule {
private final String INVALID_USE_MESSAGE;
@@ -19,10 +18,10 @@ 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 ruleID ID of the rule
+ * @param ruleName name of the rule
* @param description description of the rule
- * @param imageName file name of the image
+ * @param imageName file name of the image
*/
public CaseRule(String ruleID, String ruleName, String description, String imageName) {
super(ruleID, ruleName, description, imageName);
@@ -31,7 +30,8 @@ public CaseRule(String ruleID, String ruleName, String description, String image
}
/**
- * Gets the case board that indicates where this case rule can be applied on the given {@link Board}.
+ * Gets the case board that indicates where this case rule can be applied on the given {@link
+ * Board}.
*
* @param board board to find locations where this case rule can be applied
* @return a case board
@@ -39,16 +39,18 @@ public CaseRule(String ruleID, String ruleName, String description, String image
public abstract CaseBoard getCaseBoard(Board board);
/**
- * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule.
+ * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on
+ * this case rule.
*
- * @param board the current board state
+ * @param board the current board state
* @param puzzleElement equivalent puzzleElement
* @return a list of elements the specified could be
*/
public abstract List getCases(Board board, PuzzleElement puzzleElement);
/**
- * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule.
+ * Checks whether the {@link TreeTransition} logically follows from the parent node using this
+ * rule.
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
@@ -61,7 +63,8 @@ public String checkRule(TreeTransition transition) {
}
for (TreeTransition childTrans : parentNodes.get(0).getChildren()) {
- if (childTrans.getRule() == null || !childTrans.getRule().getClass().equals(this.getClass())) {
+ if (childTrans.getRule() == null
+ || !childTrans.getRule().getClass().equals(this.getClass())) {
return "All children nodes must be justified with the same case rule.";
}
}
@@ -81,8 +84,8 @@ public String checkRule(TreeTransition transition) {
}
/**
- * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is
- * the one that should overridden in child classes.
+ * Checks whether the {@link TreeTransition} logically follows from the parent node using this
+ * rule. This method is the one that should overridden in child classes.
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
@@ -91,13 +94,13 @@ public String checkRule(TreeTransition transition) {
public abstract String checkRuleRaw(TreeTransition transition);
/**
- * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using
- * this rule.
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule.
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement) {
@@ -105,34 +108,35 @@ public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement
}
/**
- * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using
- * this rule. This method is the one that should overridden in child classes.
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule. This method is the one that should overridden in child
+ * classes.
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public abstract String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement);
/**
- * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid
- * Overridden by case rules dependent on more than just the modified data
+ * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be
+ * valid Overridden by case rules dependent on more than just the modified data
*
- * @param board board state at application
+ * @param board board state at application
* @param puzzleElement selected puzzleElement
- * @return List of puzzle elements (typically cells) this application of the case rule depends upon.
- * Defaults to any element modified by any case
+ * @return List of puzzle elements (typically cells) this application of the case rule depends
+ * upon. Defaults to any element modified by any case
*/
public List dependentElements(Board board, PuzzleElement puzzleElement) {
List elements = new ArrayList<>();
- List cases = getCases(board,puzzleElement);
+ List cases = getCases(board, puzzleElement);
for (Board caseBoard : cases) {
Set data = caseBoard.getModifiedData();
for (PuzzleElement element : data) {
- if(!elements.contains(board.getPuzzleElement(element))){
+ if (!elements.contains(board.getPuzzleElement(element))) {
elements.add(board.getPuzzleElement(element));
}
}
@@ -141,5 +145,3 @@ public List dependentElements(Board board, PuzzleElement puzzleEl
return elements;
}
}
-
-
diff --git a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java
index 0d3a79a98..b38a95fd2 100644
--- a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java
@@ -1,22 +1,23 @@
package edu.rpi.legup.model.rules;
+import static edu.rpi.legup.model.rules.RuleType.CONTRADICTION;
+
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.tree.TreeTransition;
-import static edu.rpi.legup.model.rules.RuleType.CONTRADICTION;
-
public abstract class ContradictionRule extends Rule {
- private final String NO_CONTRADICTION_MESSAGE = "No instance of the contradiction " + this.ruleName + " here";
+ private final String NO_CONTRADICTION_MESSAGE =
+ "No instance of the contradiction " + this.ruleName + " here";
/**
* ContradictionRule Constructor creates a new contradiction rule
*
- * @param ruleID ID of the rule
- * @param ruleName name of the 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
+ * @param imageName file name of the image
*/
public ContradictionRule(String ruleID, String ruleName, String description, String imageName) {
super(ruleID, ruleName, description, imageName);
@@ -35,13 +36,13 @@ public String checkRule(TreeTransition transition) {
}
/**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement) {
@@ -49,8 +50,8 @@ public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement
}
/**
- * Checks whether the transition logically follows from the parent node using this rule.
- * This method is the one that should overridden in child classes
+ * Checks whether the transition logically follows from the parent node using this rule. This
+ * method is the one that should overridden in child classes
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
@@ -61,14 +62,14 @@ public String checkRuleRaw(TreeTransition transition) {
}
/**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
@@ -96,13 +97,13 @@ public String getNoContradictionMessage() {
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
public abstract String checkContradictionAt(Board board, PuzzleElement puzzleElement);
-
}
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 847764b7b..d550bc02c 100644
--- a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java
+++ b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java
@@ -1,105 +1,104 @@
-package edu.rpi.legup.model.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-import static edu.rpi.legup.model.rules.RuleType.BASIC;
-
-public abstract class DirectRule extends Rule {
- /**
- * DirectRule 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 DirectRule(String ruleID, String ruleName, String description, String imageName) {
- super(ruleID, ruleName, description, imageName);
- this.ruleType = BASIC;
- }
-
- /**
- * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule.
- *
- * @param transition transition to check
- * @return null if the child node logically follow from the parent node, otherwise error message
- */
- public String checkRule(TreeTransition transition) {
- Board finalBoard = transition.getBoard();
- if (transition.getParents().size() != 1 ||
- transition.getParents().get(0).getChildren().size() != 1) {
- return "State must have only 1 parent and 1 child";
- }
- else if (finalBoard.getModifiedData().isEmpty()) {
- // null transition
- return null;
- }
- else {
- return checkRuleRaw(transition);
- }
- }
-
- /**
- * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is
- * the one that should overridden in child classes.
- *
- * @param transition transition to check
- * @return null if the child node logically follow from the parent node, otherwise error message
- */
- 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) {
- checkStr = tempStr;
- }
- }
- return checkStr;
- }
-
- /**
- * Checks whether the child node logically follows from the parent node at the specific {@link PuzzleElement} using
- * this rule.
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement) {
- Board finalBoard = transition.getBoard();
- puzzleElement = finalBoard.getPuzzleElement(puzzleElement);
- String checkStr;
- if (!puzzleElement.isModified()) {
- checkStr = "PuzzleElement must be modified";
- }
- else {
- if (transition.getParents().size() != 1 ||
- transition.getParents().get(0).getChildren().size() != 1) {
- checkStr = "State must have only 1 parent and 1 child";
- }
- else {
- checkStr = checkRuleRawAt(transition, puzzleElement);
- }
- }
- puzzleElement.setValid(checkStr == null);
- return checkStr;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- public abstract Board getDefaultBoard(TreeNode node);
-}
+package edu.rpi.legup.model.rules;
+
+import static edu.rpi.legup.model.rules.RuleType.BASIC;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public abstract class DirectRule extends Rule {
+ /**
+ * DirectRule 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 DirectRule(String ruleID, String ruleName, String description, String imageName) {
+ super(ruleID, ruleName, description, imageName);
+ this.ruleType = BASIC;
+ }
+
+ /**
+ * Checks whether the {@link TreeTransition} logically follows from the parent node using this
+ * rule.
+ *
+ * @param transition transition to check
+ * @return null if the child node logically follow from the parent node, otherwise error message
+ */
+ public String checkRule(TreeTransition transition) {
+ Board finalBoard = transition.getBoard();
+ // System.out.println(finalBoard.getModifiedData().size());
+ if (transition.getParents().size() != 1
+ || transition.getParents().get(0).getChildren().size() != 1) {
+ return "State must have only 1 parent and 1 child";
+ } else if (finalBoard.getModifiedData().isEmpty()) {
+ // null transition
+ return null;
+ } else {
+ return checkRuleRaw(transition);
+ }
+ }
+
+ /**
+ * Checks whether the {@link TreeTransition} logically follows from the parent node using this
+ * rule. This method is the one that should overridden in child classes.
+ *
+ * @param transition transition to check
+ * @return null if the child node logically follow from the parent node, otherwise error message
+ */
+ 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) {
+ checkStr = tempStr;
+ }
+ }
+ return checkStr;
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific {@link
+ * PuzzleElement} using this rule.
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ Board finalBoard = transition.getBoard();
+ puzzleElement = finalBoard.getPuzzleElement(puzzleElement);
+ String checkStr;
+ if (!puzzleElement.isModified()) {
+ checkStr = "PuzzleElement must be modified";
+ } else {
+ if (transition.getParents().size() != 1
+ || transition.getParents().get(0).getChildren().size() != 1) {
+ checkStr = "State must have only 1 parent and 1 child";
+ } else {
+ checkStr = checkRuleRawAt(transition, puzzleElement);
+ }
+ }
+ puzzleElement.setValid(checkStr == null);
+ return checkStr;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ public abstract Board getDefaultBoard(TreeNode node);
+}
diff --git a/src/main/java/edu/rpi/legup/model/rules/MergeRule.java b/src/main/java/edu/rpi/legup/model/rules/MergeRule.java
index 9ae18648e..f7badcd8b 100644
--- a/src/main/java/edu/rpi/legup/model/rules/MergeRule.java
+++ b/src/main/java/edu/rpi/legup/model/rules/MergeRule.java
@@ -1,33 +1,29 @@
package edu.rpi.legup.model.rules;
+import static edu.rpi.legup.model.rules.RuleType.MERGE;
+
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.tree.Tree;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
-
import java.util.ArrayList;
import java.util.List;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import static edu.rpi.legup.model.rules.RuleType.MERGE;
-
public class MergeRule extends Rule {
- /**
- * MergeRule Constructor merges to board states together
- */
+ /** MergeRule Constructor merges to board states together */
public MergeRule() {
- super("MERGE", "Merge Rule",
+ super(
+ "MERGE",
+ "Merge Rule",
"Merge any number of nodes into one",
"edu/rpi/legup/images/Legup/MergeRule.png");
this.ruleType = MERGE;
}
/**
- * Checks whether the transition logically follows from the parent node using this rule.
- * This method is the one that should overridden in child classes
+ * Checks whether the transition logically follows from the parent node using this rule. This
+ * method is the one that should overridden in child classes
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
@@ -61,14 +57,14 @@ public String checkRuleRaw(TreeTransition transition) {
}
/**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
@@ -87,13 +83,13 @@ public String checkRule(TreeTransition transition) {
}
/**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/model/rules/RegisterRule.java b/src/main/java/edu/rpi/legup/model/rules/RegisterRule.java
index 40def6edd..c1fe0b88c 100644
--- a/src/main/java/edu/rpi/legup/model/rules/RegisterRule.java
+++ b/src/main/java/edu/rpi/legup/model/rules/RegisterRule.java
@@ -5,6 +5,4 @@
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
-public @interface RegisterRule {
-
-}
+public @interface RegisterRule {}
diff --git a/src/main/java/edu/rpi/legup/model/rules/Rule.java b/src/main/java/edu/rpi/legup/model/rules/Rule.java
index 50f2cf962..f70bb2889 100644
--- a/src/main/java/edu/rpi/legup/model/rules/Rule.java
+++ b/src/main/java/edu/rpi/legup/model/rules/Rule.java
@@ -1,17 +1,12 @@
package edu.rpi.legup.model.rules;
+import edu.rpi.legup.app.LegupPreferences;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.tree.TreeTransition;
-
-import edu.rpi.legup.app.LegupPreferences;
-
-import javax.swing.ImageIcon;
-import java.awt.image.BufferedImage;
-import java.awt.Image;
import java.awt.Graphics2D;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import javax.swing.ImageIcon;
@RegisterRule
public abstract class Rule {
@@ -27,10 +22,10 @@ public abstract class Rule {
/**
* Rule Constructor creates a new rule
*
- * @param ruleID ID of the rule
- * @param ruleName name of the 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
+ * @param imageName file name of the image
*/
public Rule(String ruleID, String ruleName, String description, String imageName) {
this.ruleID = ruleID;
@@ -50,8 +45,8 @@ public Rule(String ruleID, String ruleName, String description, String imageName
public abstract String checkRule(TreeTransition transition);
/**
- * Checks whether the transition logically follows from the parent node using this rule.
- * This method is the one that should overridden in child classes
+ * Checks whether the transition logically follows from the parent node using this rule. This
+ * method is the one that should overridden in child classes
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
@@ -59,43 +54,44 @@ public Rule(String ruleID, String ruleName, String description, String imageName
protected abstract String checkRuleRaw(TreeTransition transition);
/**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
public abstract String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement);
/**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
- protected abstract String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement);
+ protected abstract String checkRuleRawAt(
+ TreeTransition transition, PuzzleElement puzzleElement);
- /**
- * Loads the image file
- */
+ /** Loads the image file */
public void loadImage() {
if (imageName != null) {
String name = imageName;
LegupPreferences prefs = LegupPreferences.getInstance();
- if (name.contains("shorttruthtable") && prefs.getUserPref(LegupPreferences.COLOR_BLIND).equals("true")) {
+ if (name.contains("shorttruthtable")
+ && prefs.getUserPref(LegupPreferences.COLOR_BLIND).equals("true")) {
name = name.replace("ruleimages", "ruleimages_cb");
}
this.image = new ImageIcon(ClassLoader.getSystemClassLoader().getResource(name));
- //Resize images to be 100px wide
+ // Resize images to be 100px wide
Image image = this.image.getImage();
if (this.image.getIconWidth() < 120) return;
- int height = (int) (100 * ((double) this.image.getIconHeight() / this.image.getIconWidth()));
+ int height =
+ (int) (100 * ((double) this.image.getIconHeight() / this.image.getIconWidth()));
if (height == 0) {
System.out.println("height is 0 error");
System.out.println("height: " + this.image.getIconHeight());
@@ -166,4 +162,4 @@ public RuleType getRuleType() {
public String getInvalidUseOfRuleMessage() {
return this.INVALID_USE_MESSAGE;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/model/rules/RuleType.java b/src/main/java/edu/rpi/legup/model/rules/RuleType.java
index b7ce315cf..06aa1844b 100644
--- a/src/main/java/edu/rpi/legup/model/rules/RuleType.java
+++ b/src/main/java/edu/rpi/legup/model/rules/RuleType.java
@@ -1,5 +1,8 @@
package edu.rpi.legup.model.rules;
public enum RuleType {
- BASIC, CASE, CONTRADICTION, MERGE
+ BASIC,
+ CASE,
+ CONTRADICTION,
+ MERGE
}
diff --git a/src/main/java/edu/rpi/legup/model/tree/Tree.java b/src/main/java/edu/rpi/legup/model/tree/Tree.java
index 79c0bcece..a0746db87 100644
--- a/src/main/java/edu/rpi/legup/model/tree/Tree.java
+++ b/src/main/java/edu/rpi/legup/model/tree/Tree.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.model.tree;
import edu.rpi.legup.model.gameboard.Board;
-
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -20,9 +19,7 @@ public Tree(Board initBoard) {
this.rootNode.setRoot(true);
}
- /**
- * Tree Constructor creates the tree structure with null root node
- */
+ /** Tree Constructor creates the tree structure with null root node */
public Tree() {
this.rootNode = null;
}
@@ -44,9 +41,9 @@ public TreeNode addNode(TreeTransition transition) {
public TreeElement addTreeElement(TreeElement element) {
if (element.getType() == TreeElementType.NODE) {
TreeNode treeNode = (TreeNode) element;
- return addTreeElement(treeNode, new TreeTransition(treeNode, treeNode.getBoard().copy()));
- }
- else {
+ return addTreeElement(
+ treeNode, new TreeTransition(treeNode, treeNode.getBoard().copy()));
+ } else {
TreeTransition transition = (TreeTransition) element;
Board copyBoard = transition.board.copy();
copyBoard.setModifiable(false);
@@ -70,8 +67,7 @@ public void removeTreeElement(TreeElement element) {
if (element.getType() == TreeElementType.NODE) {
TreeNode node = (TreeNode) element;
node.getParent().setChildNode(null);
- }
- else {
+ } else {
TreeTransition transition = (TreeTransition) element;
transition.getParents().forEach(n -> n.removeChild(transition));
transition.getParents().get(0).getChildren().forEach(TreeTransition::reverify);
@@ -79,8 +75,8 @@ public void removeTreeElement(TreeElement element) {
}
/**
- * Determines if the tree is valid by checking whether this tree puzzleElement and
- * all descendants of this tree puzzleElement is justified and justified correctly
+ * Determines if the tree is valid by checking whether this tree puzzleElement and all
+ * descendants of this tree puzzleElement is justified and justified correctly
*
* @return true if tree is valid, false otherwise
*/
@@ -114,7 +110,7 @@ public Set getLeafTreeElements(TreeNode node) {
/**
* Recursively gets a Set of TreeNodes that are leaf nodes
*
- * @param leafs Set of TreeNodes that are leaf nodes
+ * @param leafs Set of TreeNodes that are leaf nodes
* @param element current TreeNode being evaluated
*/
private void getLeafTreeElements(Set leafs, TreeElement element) {
@@ -123,41 +119,37 @@ private void getLeafTreeElements(Set leafs, TreeElement element) {
List childTrans = node.getChildren();
if (childTrans.isEmpty()) {
leafs.add(node);
- }
- else {
+ } else {
childTrans.forEach(t -> getLeafTreeElements(leafs, t));
}
- }
- else {
+ } else {
TreeTransition transition = (TreeTransition) element;
TreeNode childNode = transition.getChildNode();
if (childNode == null) {
leafs.add(transition);
- }
- else {
+ } else {
getLeafTreeElements(leafs, childNode);
}
}
}
/**
- * Gets the lowest common ancestor (LCA) among the list of {@link TreeNode} passed into
- * the function. This lowest common ancestor is the most immediate ancestor
- * node such that the list of tree nodes specified are descendants of the node.
- * This will return null if no such ancestor exists
+ * Gets the lowest common ancestor (LCA) among the list of {@link TreeNode} passed into the
+ * function. This lowest common ancestor is the most immediate ancestor node such that the list
+ * of tree nodes specified are descendants of the node. This will return null if no such
+ * ancestor exists
*
* @param nodes list of tree nodes to find the LCA
- * @return the first ancestor node that all tree nodes have in common, otherwise null if none exists
+ * @return the first ancestor node that all tree nodes have in common, otherwise null if none
+ * exists
*/
public static TreeNode getLowestCommonAncestor(List nodes) {
if (nodes.isEmpty()) {
return null;
- }
- else {
+ } else {
if (nodes.size() == 1) {
return nodes.get(0);
- }
- else {
+ } else {
List> ancestors = new ArrayList<>();
for (TreeNode node : nodes) {
ancestors.add(node.getAncestors());
diff --git a/src/main/java/edu/rpi/legup/model/tree/TreeElement.java b/src/main/java/edu/rpi/legup/model/tree/TreeElement.java
index 17168ac98..59f75acf3 100644
--- a/src/main/java/edu/rpi/legup/model/tree/TreeElement.java
+++ b/src/main/java/edu/rpi/legup/model/tree/TreeElement.java
@@ -16,8 +16,8 @@ public TreeElement(TreeElementType type) {
}
/**
- * Determines if this tree node leads to a contradiction. Every path from this tree node
- * must lead to a contradiction including all of its children
+ * Determines if this tree node leads to a contradiction. Every path from this tree node must
+ * lead to a contradiction including all of its children
*
* @return true if this tree node leads to a contradiction, false otherwise
*/
@@ -28,15 +28,16 @@ public TreeElement(TreeElementType type) {
* whether this tree puzzleElement and all descendants of this tree puzzleElement is justified
* and justified correctly
*
- * @return true if this tree puzzleElement and all descendants of this tree puzzleElement is valid,
- * false otherwise
+ * @return true if this tree puzzleElement and all descendants of this tree puzzleElement is
+ * valid, false otherwise
*/
public abstract boolean isValidBranch();
/**
* Gets the type of tree puzzleElement
*
- * @return NODE if this tree puzzleElement is a tree node, TRANSITION, if this tree puzzleElement is a transition
+ * @return NODE if this tree puzzleElement is a tree node, TRANSITION, if this tree
+ * puzzleElement is a transition
*/
public TreeElementType getType() {
return type;
diff --git a/src/main/java/edu/rpi/legup/model/tree/TreeElementType.java b/src/main/java/edu/rpi/legup/model/tree/TreeElementType.java
index ad93f16b6..67437a535 100644
--- a/src/main/java/edu/rpi/legup/model/tree/TreeElementType.java
+++ b/src/main/java/edu/rpi/legup/model/tree/TreeElementType.java
@@ -1,5 +1,6 @@
package edu.rpi.legup.model.tree;
public enum TreeElementType {
- NODE, TRANSITION
+ NODE,
+ TRANSITION
}
diff --git a/src/main/java/edu/rpi/legup/model/tree/TreeNode.java b/src/main/java/edu/rpi/legup/model/tree/TreeNode.java
index 59f6e736e..a2ac7cb21 100644
--- a/src/main/java/edu/rpi/legup/model/tree/TreeNode.java
+++ b/src/main/java/edu/rpi/legup/model/tree/TreeNode.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.utility.DisjointSets;
-
import java.util.*;
public class TreeNode extends TreeElement {
@@ -24,8 +23,8 @@ public TreeNode(Board board) {
}
/**
- * Determines if this tree node leads to a contradiction. Every path from this tree node
- * must lead to a contradiction including all of its children
+ * Determines if this tree node leads to a contradiction. Every path from this tree node must
+ * lead to a contradiction including all of its children
*
* @return true if this tree node leads to a contradiction, false otherwise
*/
@@ -43,8 +42,8 @@ public boolean isContradictoryBranch() {
* whether this tree puzzleElement and all descendants of this tree puzzleElement is justified
* and justified correctly
*
- * @return true if this tree puzzleElement and all descendants of this tree puzzleElement is valid,
- * false otherwise
+ * @return true if this tree puzzleElement and all descendants of this tree puzzleElement is
+ * valid, false otherwise
*/
@Override
public boolean isValidBranch() {
@@ -104,8 +103,7 @@ public List getDescendants() {
it.add(transition);
}
}
- }
- else {
+ } else {
TreeTransition trans = (TreeTransition) next;
TreeNode childNode = trans.getChildNode();
if (childNode != null && !descendants.contains(childNode)) {
@@ -118,9 +116,9 @@ public List getDescendants() {
}
/**
- * Gets a DisjointSets containing the children of this node such that the sets contained within the DisjointSets
- * are such that elements in the same set are branches of this tree node that will eventually merge. This could
- * mean that multiple merges take place before this happens.
+ * Gets a DisjointSets containing the children of this node such that the sets contained within
+ * the DisjointSets are such that elements in the same set are branches of this tree node that
+ * will eventually merge. This could mean that multiple merges take place before this happens.
*
* @return DisjointSets of tree transitions containing unique non-merging branches
*/
@@ -143,8 +141,7 @@ public DisjointSets findMergingBranches() {
if (element.getType() == TreeElementType.NODE) {
TreeNode node = (TreeNode) element;
nodes.addAll(node.getChildren());
- }
- else {
+ } else {
TreeTransition childTran = (TreeTransition) element;
if (childTran.getChildNode() != null) {
nodes.add(childTran.getChildNode());
@@ -169,8 +166,8 @@ public DisjointSets findMergingBranches() {
}
/**
- * Finds the point at which the set of tree elements passed in will merge. This must be a set gotten from
- * findMergingBranches method DisjointSets
+ * Finds the point at which the set of tree elements passed in will merge. This must be a set
+ * gotten from findMergingBranches method DisjointSets
*
* @param branches tree elements to find the merging point
* @return tree transition of the merging point or null if no such point exists
@@ -186,14 +183,15 @@ public static TreeTransition findMergingPoint(Set extends TreeElement> branche
mergeSet.createSet(element);
if (element.getType() == TreeElementType.NODE) {
TreeNode node = (TreeNode) element;
- node.getDescendants().forEach((TreeElement e) -> {
- if (!mergeSet.contains(e)) {
- mergeSet.createSet(e);
- }
- mergeSet.union(element, e);
- });
- }
- else {
+ node.getDescendants()
+ .forEach(
+ (TreeElement e) -> {
+ if (!mergeSet.contains(e)) {
+ mergeSet.createSet(e);
+ }
+ mergeSet.union(element, e);
+ });
+ } else {
TreeTransition transition = (TreeTransition) element;
TreeNode childNode = transition.getChildNode();
if (childNode != null) {
@@ -228,8 +226,7 @@ public static TreeTransition findMergingPoint(Set extends TreeElement> branche
if (element.getType() == TreeElementType.NODE) {
TreeNode node = (TreeNode) element;
next.addAll(node.getChildren());
- }
- else {
+ } else {
TreeTransition tran = (TreeTransition) element;
next.add(tran.getChildNode());
}
@@ -332,5 +329,4 @@ public void setRoot(boolean isRoot) {
public void clearChildren() {
this.children.clear();
}
-
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java b/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java
index 72572ac72..e79cd4b96 100644
--- a/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java
+++ b/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java
@@ -5,7 +5,6 @@
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.rules.Rule;
import edu.rpi.legup.model.rules.RuleType;
-
import java.util.ArrayList;
import java.util.List;
@@ -38,7 +37,7 @@ public TreeTransition(Board board) {
* TreeTransition Constructor - create a transition from one node to another
*
* @param parent parent tree node associated with the transition
- * @param board board state of the transition
+ * @param board board state of the transition
*/
public TreeTransition(TreeNode parent, Board board) {
this(board);
@@ -71,8 +70,7 @@ public void propagateChange(PuzzleElement element) {
board.removeModifiedData(element);
board.notifyChange(element);
changed = true;
- }
- else {
+ } else {
if (!lcaElement.equalsData(element)) {
mergedData.setData(element.getData());
board.addModifiedData(mergedData);
@@ -89,8 +87,7 @@ public void propagateChange(PuzzleElement element) {
}
}
}
- }
- else {
+ } else {
// Overwrite previous modifications to this element
board.removeModifiedData(board.getPuzzleElement(element));
@@ -98,7 +95,8 @@ public void propagateChange(PuzzleElement element) {
board.notifyChange(element);
// mark first transition as modified
- if (!board.getPuzzleElement(element).equalsData(parents.get(0).getBoard().getPuzzleElement(element))) {
+ if (!board.getPuzzleElement(element)
+ .equalsData(parents.get(0).getBoard().getPuzzleElement(element))) {
board.addModifiedData(element);
}
@@ -116,8 +114,7 @@ public void propagateChange(PuzzleElement element) {
// Set as modifiable if reverted to starting value (and started modifiable)
if (headBoard.getPuzzleElement(element).equalsData(element)) {
copy.setModifiable(headBoard.getPuzzleElement(element).isModifiable());
- }
- else{
+ } else {
copy.setModifiable(false);
}
@@ -159,8 +156,7 @@ public void propagateAddition(PuzzleElement element) {
board.removeModifiedData(element);
board.notifyDeletion(element);
changed = true;
- }
- else {
+ } else {
if (!lcaElement.equalsData(element)) {
mergedData.setData(element.getData());
board.addModifiedData(mergedData);
@@ -175,8 +171,7 @@ public void propagateAddition(PuzzleElement element) {
}
}
}
- }
- else {
+ } else {
if (childNode != null) {
board.notifyAddition(element);
childNode.getBoard().notifyAddition(element.copy());
@@ -214,8 +209,7 @@ public void propagateDeletion(PuzzleElement element) {
board.removeModifiedData(element);
board.notifyDeletion(element);
changed = true;
- }
- else {
+ } else {
if (!lcaElement.equalsData(element)) {
mergedData.setData(element.getData());
board.addModifiedData(mergedData);
@@ -230,8 +224,7 @@ public void propagateDeletion(PuzzleElement element) {
}
}
}
- }
- else {
+ } else {
if (childNode != null) {
board.notifyDeletion(element);
childNode.getBoard().notifyDeletion(element.copy());
@@ -244,8 +237,8 @@ public void propagateDeletion(PuzzleElement element) {
}
/**
- * Determines if this tree node leads to a contradiction. Every path from this tree node
- * must lead to a contradiction including all of its children
+ * Determines if this tree node leads to a contradiction. Every path from this tree node must
+ * lead to a contradiction including all of its children
*
* @return true if this tree node leads to a contradiction, false otherwise
*/
@@ -253,12 +246,10 @@ public void propagateDeletion(PuzzleElement element) {
public boolean isContradictoryBranch() {
if (isJustified() && isCorrect() && rule.getRuleType() == RuleType.CONTRADICTION) {
return true;
- }
- else {
+ } else {
if (childNode == null) {
return false;
- }
- else {
+ } else {
return childNode.isContradictoryBranch() && isJustified() && isCorrect();
}
}
@@ -269,8 +260,8 @@ public boolean isContradictoryBranch() {
* whether this tree puzzleElement and all descendants of this tree puzzleElement is justified
* and justified correctly
*
- * @return true if this tree puzzleElement and all descendants of this tree puzzleElement is valid,
- * false otherwise
+ * @return true if this tree puzzleElement and all descendants of this tree puzzleElement is
+ * valid, false otherwise
*/
@Override
public boolean isValidBranch() {
diff --git a/src/main/java/edu/rpi/legup/puzzle/PuzzleElementTypes.java b/src/main/java/edu/rpi/legup/puzzle/PuzzleElementTypes.java
index f2ddb056c..f0dd5a6e9 100644
--- a/src/main/java/edu/rpi/legup/puzzle/PuzzleElementTypes.java
+++ b/src/main/java/edu/rpi/legup/puzzle/PuzzleElementTypes.java
@@ -1,4 +1,3 @@
package edu.rpi.legup.puzzle;
-public enum PuzzleElementTypes {
-}
+public enum PuzzleElementTypes {}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/Battleship.java b/src/main/java/edu/rpi/legup/puzzle/battleship/Battleship.java
index 22a980251..41af3f626 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/Battleship.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/Battleship.java
@@ -17,9 +17,7 @@ public Battleship() {
this.factory = new BattleshipCellFactory();
}
- /**
- * Initializes the game board. Called by the invoker of the class
- */
+ /** Initializes the game board. Called by the invoker of the class */
@Override
public void initializeView() {
boardView = new BattleshipView((BattleshipBoard) currentBoard);
@@ -35,8 +33,8 @@ public Board generatePuzzle(int difficulty) {
/**
* Determines if the given dimensions are valid for Battleship
*
- * @param rows the number of rows
- * @param columns the number of columns
+ * @param rows the number of rows
+ * @param columns the number of columns
* @return true if the given dimensions are valid for Battleship, false otherwise
*/
public boolean isValidDimensions(int rows, int columns) {
@@ -74,84 +72,98 @@ public boolean isBoardComplete(Board board) {
* @param board the board that has changed
*/
@Override
- public void onBoardChange(Board board) {
+ public void onBoardChange(Board board) {}
- }
-//
-// @Override
-// public void onTreeSelectionChange(ArrayList newSelection)
-// {
-//
-// }
+ //
+ // @Override
+ // public void onTreeSelectionChange(ArrayList newSelection)
+ // {
+ //
+ // }
@Override
public void importPuzzle(String fileName) {
-// if(fileName != null)
-// {
-// InputStream inputStream = new FileInputStream(fileName);
-// DocumentBuilder builder = null;//factory.newDocumentBuilder();
-// Document document = builder.parse(inputStream);
-//
-// BattleShipBoard battleShipBoard;
-//
-// PuzzleElement rootNode = document.getDocumentElement();
-// PuzzleElement puzzleElement = (PuzzleElement) rootNode.getElementsByTagName("edu.rpi.legup.puzzle").item(0);
-// PuzzleElement boardElement = (PuzzleElement) puzzleElement.getElementsByTagName("board").item(0);
-// PuzzleElement axesElement = (PuzzleElement) boardElement.getElementsByTagName("axes").item(0);
-// PuzzleElement shipElement = (PuzzleElement) boardElement.getElementsByTagName("ships").item(0);
-// PuzzleElement cellElement = (PuzzleElement) boardElement.getElementsByTagName("cells").item(0);
-// PuzzleElement rightElement = (PuzzleElement) axesElement.getElementsByTagName("right").item(0);
-// PuzzleElement bottomElement = (PuzzleElement) axesElement.getElementsByTagName("bottom").item(0);
-// NodeList rightClueList = rightElement.getElementsByTagName("clue");
-// NodeList bottomClueList = bottomElement.getElementsByTagName("clue");
-// NodeList shipList = shipElement.getElementsByTagName("ship");
-// NodeList cells = cellElement.getElementsByTagName("cell");
-//
-// int size = Integer.valueOf(boardElement.getAttribute("size"));
-// battleShipBoard = new BattleShipBoard(size);
-//
-// ArrayList battleShipData = new ArrayList<>();
-// for(int i = 0; i < size * size; i++)
-// {
-// battleShipData.add(null);
-// }
-//
-// for (int i = 0; i < rightClueList.getLength(); i++) {
-// battleShipBoard.getRight()[i] = Integer.valueOf(rightClueList.item(i).getAttributes().getNamedItem("value").getNodeValue());
-// }
-//
-// for (int i = 0; i < bottomClueList.getLength(); i++) {
-// battleShipBoard.getBottom()[i] = Integer.valueOf(bottomClueList.item(i).getAttributes().getNamedItem("value").getNodeValue());
-// }
-//
-// for (int i = 0; i < shipList.getLength(); i++) {
-// int length = Integer.valueOf(shipList.item(i).getAttributes().getNamedItem("length").getNodeValue());
-// int count = Integer.valueOf(shipList.item(i).getAttributes().getNamedItem("count").getNodeValue());
-// battleShipBoard.getShips().add(new Ship(length, count));
-// }
-//
-// for (int i = 0; i < cells.getLength(); i++) {
-// int x = Integer.valueOf(cells.item(i).getAttributes().getNamedItem("x").getNodeValue());
-// int y = Integer.valueOf(cells.item(i).getAttributes().getNamedItem("y").getNodeValue());
-// String value = cells.item(i).getAttributes().getNamedItem("value").getNodeValue().toUpperCase();
-//
-// BattleShipCell cell = new BattleShipCell(BattleShipType.valueOf(value).ordinal(), new Point(x, y));
-// battleShipBoard.setCell(x, y, cell);
-// cell.setModifiable(false);
-// cell.setGiven(true);
-// }
-//
-// for (int x = 0; x < size; x++) {
-// for (int y = 0; y < size; y++) {
-// if (battleShipBoard.getCell(x, y) == null) {
-// BattleShipCell cell = new BattleShipCell(9, new Point(x, y));
-// cell.setModifiable(true);
-// battleShipBoard.setCell(x, y, cell);
-// }
-// }
-// }
-// this.currentBoard = battleShipBoard;
-// this.tree = new Tree(currentBoard);
-// }
+ // if(fileName != null)
+ // {
+ // InputStream inputStream = new FileInputStream(fileName);
+ // DocumentBuilder builder = null;//factory.newDocumentBuilder();
+ // Document document = builder.parse(inputStream);
+ //
+ // BattleShipBoard battleShipBoard;
+ //
+ // PuzzleElement rootNode = document.getDocumentElement();
+ // PuzzleElement puzzleElement = (PuzzleElement)
+ // rootNode.getElementsByTagName("edu.rpi.legup.puzzle").item(0);
+ // PuzzleElement boardElement = (PuzzleElement)
+ // puzzleElement.getElementsByTagName("board").item(0);
+ // PuzzleElement axesElement = (PuzzleElement)
+ // boardElement.getElementsByTagName("axes").item(0);
+ // PuzzleElement shipElement = (PuzzleElement)
+ // boardElement.getElementsByTagName("ships").item(0);
+ // PuzzleElement cellElement = (PuzzleElement)
+ // boardElement.getElementsByTagName("cells").item(0);
+ // PuzzleElement rightElement = (PuzzleElement)
+ // axesElement.getElementsByTagName("right").item(0);
+ // PuzzleElement bottomElement = (PuzzleElement)
+ // axesElement.getElementsByTagName("bottom").item(0);
+ // NodeList rightClueList = rightElement.getElementsByTagName("clue");
+ // NodeList bottomClueList = bottomElement.getElementsByTagName("clue");
+ // NodeList shipList = shipElement.getElementsByTagName("ship");
+ // NodeList cells = cellElement.getElementsByTagName("cell");
+ //
+ // int size = Integer.valueOf(boardElement.getAttribute("size"));
+ // battleShipBoard = new BattleShipBoard(size);
+ //
+ // ArrayList battleShipData = new ArrayList<>();
+ // for(int i = 0; i < size * size; i++)
+ // {
+ // battleShipData.add(null);
+ // }
+ //
+ // for (int i = 0; i < rightClueList.getLength(); i++) {
+ // battleShipBoard.getRight()[i] =
+ // Integer.valueOf(rightClueList.item(i).getAttributes().getNamedItem("value").getNodeValue());
+ // }
+ //
+ // for (int i = 0; i < bottomClueList.getLength(); i++) {
+ // battleShipBoard.getBottom()[i] =
+ // Integer.valueOf(bottomClueList.item(i).getAttributes().getNamedItem("value").getNodeValue());
+ // }
+ //
+ // for (int i = 0; i < shipList.getLength(); i++) {
+ // int length =
+ // Integer.valueOf(shipList.item(i).getAttributes().getNamedItem("length").getNodeValue());
+ // int count =
+ // Integer.valueOf(shipList.item(i).getAttributes().getNamedItem("count").getNodeValue());
+ // battleShipBoard.getShips().add(new Ship(length, count));
+ // }
+ //
+ // for (int i = 0; i < cells.getLength(); i++) {
+ // int x =
+ // Integer.valueOf(cells.item(i).getAttributes().getNamedItem("x").getNodeValue());
+ // int y =
+ // Integer.valueOf(cells.item(i).getAttributes().getNamedItem("y").getNodeValue());
+ // String value =
+ // cells.item(i).getAttributes().getNamedItem("value").getNodeValue().toUpperCase();
+ //
+ // BattleShipCell cell = new
+ // BattleShipCell(BattleShipType.valueOf(value).ordinal(), new Point(x, y));
+ // battleShipBoard.setCell(x, y, cell);
+ // cell.setModifiable(false);
+ // cell.setGiven(true);
+ // }
+ //
+ // for (int x = 0; x < size; x++) {
+ // for (int y = 0; y < size; y++) {
+ // if (battleShipBoard.getCell(x, y) == null) {
+ // BattleShipCell cell = new BattleShipCell(9, new Point(x, y));
+ // cell.setModifiable(true);
+ // battleShipBoard.setCell(x, y, cell);
+ // }
+ // }
+ // }
+ // this.currentBoard = battleShipBoard;
+ // this.tree = new Tree(currentBoard);
+ // }
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipBoard.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipBoard.java
index 5965f7055..555c8471f 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipBoard.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipBoard.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.gameboard.GridBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
@@ -15,7 +14,7 @@ public class BattleshipBoard extends GridBoard {
/**
* Constructor for creating a rectangular battleship board.
*
- * @param width width of the board
+ * @param width width of the board
* @param height height of the board
*/
public BattleshipBoard(int width, int height) {
@@ -44,8 +43,7 @@ public BattleshipBoard(int size) {
/**
* Gets the east {@link BattleshipClue}
*
- * @return List of BattleShipClue
objects on the east
- * side of the board
+ * @return List of BattleShipClue
objects on the east side of the board
*/
public List getEast() {
return east;
@@ -90,8 +88,7 @@ public BattleshipBoard copy() {
* Get a list of all orthogonally adjacent cells.
*
* @param cell The cell to get adjacent cells from.
- * @return List of adjacent cells in clockwise order:
- * { up, right, down, left }
+ * @return List of adjacent cells in clockwise order: { up, right, down, left }
*/
public List getAdjOrthogonals(BattleshipCell cell) {
List adj = new ArrayList<>();
@@ -111,8 +108,8 @@ public List getAdjOrthogonals(BattleshipCell cell) {
* Get a list of all diagonally adjacent cells.
*
* @param cell The cell to get diagonally adjacent cells from.
- * @return List of diagonally adjacent cells in clockwise order:
- * { upRight, downRight, downLeft, upLeft }
+ * @return List of diagonally adjacent cells in clockwise order:
+ * { upRight, downRight, downLeft, upLeft }
*/
public List getAdjDiagonals(BattleshipCell cell) {
List dia = new ArrayList<>();
@@ -155,4 +152,4 @@ public List getColumn(int x) {
}
return column;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCell.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCell.java
index 5f2c5b975..5a5b86094 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCell.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCell.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.puzzle.battleship;
import edu.rpi.legup.model.gameboard.GridCell;
-
import java.awt.*;
public class BattleshipCell extends GridCell {
@@ -9,7 +8,7 @@ public class BattleshipCell extends GridCell {
/**
* BattleShipCell Constructor - creates a BattleShipCell from the specified value and location
*
- * @param value value of the BattleShipCell
+ * @param value value of the BattleShipCell
* @param location position of the BattleShipCell
*/
public BattleshipCell(BattleshipType value, Point location) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellController.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellController.java
index 89b5fa19a..9db0cca84 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellController.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellController.java
@@ -2,39 +2,39 @@
import edu.rpi.legup.controller.ElementController;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-
import java.awt.event.MouseEvent;
public class BattleshipCellController extends ElementController {
/**
- * Controller class for the Battleship puzzle -
- * receives user mouse input and changes what's shown on the GUI
+ * Controller class for the Battleship puzzle - receives user mouse input and changes what's
+ * shown on the GUI
*
* @param data the PuzzleElement to be changed
- * @param e the user mouse input
+ * @param e the user mouse input
*/
@Override
public void changeCell(MouseEvent e, PuzzleElement data) {
BattleshipCell cell = (BattleshipCell) data;
if (e.getButton() == MouseEvent.BUTTON1) {
if (e.isControlDown()) {
- this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY());
- }
- else {
+ this.boardView
+ .getSelectionPopupMenu()
+ .show(
+ boardView,
+ this.boardView.getCanvas().getX() + e.getX(),
+ this.boardView.getCanvas().getY() + e.getY());
+ } else {
if (cell.getData() == BattleshipType.SHIP_MIDDLE) {
cell.setData(BattleshipType.UNKNOWN);
- }
- else {
+ } else {
cell.setData(BattleshipType.getType(cell.getData().value + 1));
}
}
- }
- else {
+ } else {
if (e.getButton() == MouseEvent.BUTTON3) {
if (cell.getData() == BattleshipType.UNKNOWN) {
cell.setData(BattleshipType.SHIP_MIDDLE);
- }
- else {
+ } else {
cell.setData(BattleshipType.getType(cell.getData().value - 1));
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java
index 81629c360..1b3b6c427 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java
@@ -4,23 +4,23 @@
import edu.rpi.legup.model.gameboard.ElementFactory;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.awt.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import java.awt.*;
-
public class BattleshipCellFactory extends ElementFactory {
/**
* Creates a puzzleElement based on the xml document Node and adds it to the board
*
- * @param node node that represents the puzzleElement
+ * @param node node that represents the puzzleElement
* @param board board to add the newly created cell
* @return newly created cell from the xml document Node
* @throws InvalidFileFormatException if file is invalid
*/
@Override
- public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormatException {
+ public PuzzleElement importCell(Node node, Board board)
+ throws InvalidFileFormatException {
try {
BattleshipBoard battleShipBoard = (BattleshipBoard) board;
int width = battleShipBoard.getWidth();
@@ -32,24 +32,25 @@ public PuzzleElement importCell(Node node, Board board) throws I
int x = Integer.parseInt(attributeList.getNamedItem("x").getNodeValue());
int y = Integer.parseInt(attributeList.getNamedItem("y").getNodeValue());
if (x >= width || y >= height) {
- throw new InvalidFileFormatException("BattleShip Factory: cell location out of bounds");
+ throw new InvalidFileFormatException(
+ "BattleShip Factory: cell location out of bounds");
}
if (value < 0 || value > 3) {
throw new InvalidFileFormatException("BattleShip Factory: cell unknown value");
}
- BattleshipCell cell = new BattleshipCell(BattleshipType.getType(value), new Point(x, y));
+ BattleshipCell cell =
+ new BattleshipCell(BattleshipType.getType(value), new Point(x, y));
cell.setIndex(y * height + x);
return cell;
+ } else {
+ throw new InvalidFileFormatException(
+ "BattleShip Factory: unknown puzzleElement puzzleElement");
}
- else {
- throw new InvalidFileFormatException("BattleShip Factory: unknown puzzleElement puzzleElement");
- }
- }
- catch (NumberFormatException e) {
- throw new InvalidFileFormatException("BattleShip Factory: unknown value where integer expected");
- }
- catch (NullPointerException e) {
+ } catch (NumberFormatException e) {
+ throw new InvalidFileFormatException(
+ "BattleShip Factory: unknown value where integer expected");
+ } catch (NullPointerException e) {
throw new InvalidFileFormatException("BattleShip Factory: could not find attribute(s)");
}
}
@@ -57,7 +58,7 @@ public PuzzleElement importCell(Node node, Board board) throws I
/**
* Creates a xml document puzzleElement from a cell for exporting
*
- * @param document xml document
+ * @param document xml document
* @param puzzleElement PuzzleElement cell
* @return xml PuzzleElement
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipClueView.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipClueView.java
index 6a29eb7a3..788c860f3 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipClueView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipClueView.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.puzzle.battleship;
import edu.rpi.legup.ui.boardview.ElementView;
-
import java.awt.*;
public class BattleshipClueView extends ElementView {
@@ -26,6 +25,7 @@ public BattleshipClue getPuzzleElement() {
@Override
/**
* Draws the clue from the PuzzleElement associated with this view on the given frame
+ *
* @param graphics2D the frame the clue is to be drawn on
*/
public void draw(Graphics2D graphics2D) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipElementView.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipElementView.java
index d66f159d7..1898468ce 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipElementView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipElementView.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.puzzle.battleship;
import edu.rpi.legup.ui.boardview.GridElementView;
-
import java.awt.*;
public class BattleshipElementView extends GridElementView {
@@ -22,6 +21,7 @@ public BattleshipElementView(BattleshipCell cell) {
@Override
/**
* Draws on the given frame based on the type of the cell of the current puzzleElement
+ *
* @param graphics2D the frame to be drawn on
*/
public void drawElement(Graphics2D graphics2D) {
@@ -39,37 +39,60 @@ public void drawElement(Graphics2D graphics2D) {
break;
case SHIP_UNKNOWN:
graphics2D.setColor(SHIP_COLOR);
- graphics2D.fillRect(location.x + 3 * size.width / 8, location.y + 3 * size.height / 8,
- size.width / 4, size.height / 4);
+ graphics2D.fillRect(
+ location.x + 3 * size.width / 8,
+ location.y + 3 * size.height / 8,
+ size.width / 4,
+ size.height / 4);
graphics2D.setColor(FONT_COLOR);
graphics2D.setFont(FONT);
FontMetrics metrics = graphics2D.getFontMetrics(FONT);
String value = "?";
int xText = location.x + (size.width - metrics.stringWidth(value)) / 2;
- int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent();
+ int yText =
+ location.y
+ + ((size.height - metrics.getHeight()) / 2)
+ + metrics.getAscent();
graphics2D.drawString(value, xText, yText);
break;
case SUBMARINE:
graphics2D.setColor(SHIP_COLOR);
- graphics2D.fillOval(location.x + size.width / 4, location.y + size.width / 4,
- size.width / 2, size.height / 2);
+ graphics2D.fillOval(
+ location.x + size.width / 4,
+ location.y + size.width / 4,
+ size.width / 2,
+ size.height / 2);
break;
case SHIP_TOP:
graphics2D.setColor(SHIP_COLOR);
- graphics2D.fillArc(location.x, location.y - size.height / 2, size.width, size.height, 180, 180);
+ graphics2D.fillArc(
+ location.x,
+ location.y - size.height / 2,
+ size.width,
+ size.height,
+ 180,
+ 180);
break;
case SHIP_RIGHT:
graphics2D.setColor(SHIP_COLOR);
- graphics2D.fillArc(location.x + size.height / 2, location.y, size.width, size.height, 90, 180);
+ graphics2D.fillArc(
+ location.x + size.height / 2, location.y, size.width, size.height, 90, 180);
break;
case SHIP_BOTTOM:
graphics2D.setColor(SHIP_COLOR);
- graphics2D.fillArc(location.x, location.y + size.height / 2, size.width, size.height, 0, 180);
+ graphics2D.fillArc(
+ location.x, location.y + size.height / 2, size.width, size.height, 0, 180);
break;
case SHIP_LEFT:
graphics2D.setColor(SHIP_COLOR);
- graphics2D.fillArc(location.x - size.height / 2, location.y, size.width, size.height, 270, 180);
+ graphics2D.fillArc(
+ location.x - size.height / 2,
+ location.y,
+ size.width,
+ size.height,
+ 270,
+ 180);
break;
case SHIP_MIDDLE:
graphics2D.setColor(SHIP_COLOR);
@@ -84,4 +107,4 @@ public void drawElement(Graphics2D graphics2D) {
graphics2D.setStroke(OUTLINE_STROKE);
graphics2D.drawRect(location.x, location.y, size.width, size.height);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java
index 4205d0125..cbc364842 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.PuzzleExporter;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard;
import org.w3c.dom.Document;
public class BattleshipExporter extends PuzzleExporter {
@@ -22,8 +21,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
BattleshipBoard board;
if (puzzle.getTree() != null) {
board = (BattleshipBoard) puzzle.getTree().getRootNode().getBoard();
- }
- else {
+ } else {
board = (BattleshipBoard) puzzle.getBoardView().getBoard();
}
@@ -35,7 +33,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
for (PuzzleElement puzzleElement : board.getPuzzleElements()) {
BattleshipCell cell = (BattleshipCell) puzzleElement;
if (cell.getData() != BattleshipType.getType(0)) {
- org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement);
+ org.w3c.dom.Element cellElement =
+ puzzle.getFactory().exportCell(newDocument, puzzleElement);
cellsElement.appendChild(cellElement);
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java
index 749ceaaa9..cbc1dd02b 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java
@@ -2,12 +2,11 @@
import edu.rpi.legup.model.PuzzleImporter;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.awt.*;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import java.awt.*;
-
public class BattleshipImporter extends PuzzleImporter {
public BattleshipImporter(Battleship battleShip) {
super(battleShip);
@@ -26,14 +25,12 @@ public boolean acceptsTextInput() {
/**
* Creates an empty board for building
*
- * @param rows the number of rows on the board
+ * @param rows the number of rows on the board
* @param columns the number of columns on the board
* @throws RuntimeException if board can not be created
*/
@Override
- public void initializeBoard(int rows, int columns) {
-
- }
+ public void initializeBoard(int rows, int columns) {}
/**
* Creates the board for building
@@ -45,46 +42,43 @@ public void initializeBoard(int rows, int columns) {
public void initializeBoard(Node node) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("board")) {
- throw new InvalidFileFormatException("BattleShip Importer: " +
- "cannot find board puzzleElement");
+ throw new InvalidFileFormatException(
+ "BattleShip Importer: " + "cannot find board puzzleElement");
}
Element boardElement = (Element) node;
if (boardElement.getElementsByTagName("cells").getLength() == 0) {
- throw new InvalidFileFormatException("BattleShip Importer: " +
- "no puzzleElement found for board");
+ throw new InvalidFileFormatException(
+ "BattleShip Importer: " + "no puzzleElement found for board");
}
- Element dataElement = (Element) boardElement.getElementsByTagName(
- "cells").item(0);
+ Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0);
NodeList elementDataList = dataElement.getElementsByTagName("cell");
BattleshipBoard battleShipBoard = null;
if (!boardElement.getAttribute("size").isEmpty()) {
- int size = Integer.valueOf(boardElement.getAttribute(
- "size"));
+ int size = Integer.valueOf(boardElement.getAttribute("size"));
battleShipBoard = new BattleshipBoard(size);
- }
- else {
+ } else {
if (!boardElement.getAttribute("width").isEmpty()
&& !boardElement.getAttribute("height").isEmpty()) {
- int width = Integer.valueOf(boardElement.getAttribute(
- "width"));
- int height = Integer.valueOf(boardElement.getAttribute(
- "height"));
+ int width = Integer.valueOf(boardElement.getAttribute("width"));
+ int height = Integer.valueOf(boardElement.getAttribute("height"));
battleShipBoard = new BattleshipBoard(width, height);
}
}
if (battleShipBoard == null) {
- throw new InvalidFileFormatException("BattleShip Importer: " +
- "invalid board dimensions");
+ throw new InvalidFileFormatException(
+ "BattleShip Importer: " + "invalid board dimensions");
}
int width = battleShipBoard.getWidth();
int height = battleShipBoard.getHeight();
for (int i = 0; i < elementDataList.getLength(); i++) {
- BattleshipCell cell = (BattleshipCell) puzzle.getFactory()
- .importCell(elementDataList.item(i), battleShipBoard);
+ BattleshipCell cell =
+ (BattleshipCell)
+ puzzle.getFactory()
+ .importCell(elementDataList.item(i), battleShipBoard);
Point loc = cell.getLocation();
if (cell.getData() != BattleshipType.getType(0)) {
cell.setModifiable(false);
@@ -96,8 +90,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (battleShipBoard.getCell(x, y) == null) {
- BattleshipCell cell = new BattleshipCell(
- BattleshipType.UNKNOWN, new Point(x, y));
+ BattleshipCell cell =
+ new BattleshipCell(BattleshipType.UNKNOWN, new Point(x, y));
cell.setIndex(y * height + x);
cell.setModifiable(true);
battleShipBoard.setCell(x, y, cell);
@@ -107,59 +101,58 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
NodeList axes = boardElement.getElementsByTagName("axis");
if (axes.getLength() != 2) {
- throw new InvalidFileFormatException("BattleShip Importer: " +
- "cannot find axes");
+ throw new InvalidFileFormatException("BattleShip Importer: " + "cannot find axes");
}
Element axis1 = (Element) axes.item(0);
Element axis2 = (Element) axes.item(1);
- if (!axis1.hasAttribute("side") || !axis2.hasAttribute(
- "side")) {
- throw new InvalidFileFormatException("BattleShip Importer: " +
- "side attribute of axis not specified");
+ if (!axis1.hasAttribute("side") || !axis2.hasAttribute("side")) {
+ throw new InvalidFileFormatException(
+ "BattleShip Importer: " + "side attribute of axis not specified");
}
String side1 = axis1.getAttribute("side");
String side2 = axis2.getAttribute("side");
if (side1.equalsIgnoreCase(side2)
- || !(side1.equalsIgnoreCase("east")
- || side1.equalsIgnoreCase("south"))
- || !(side2.equalsIgnoreCase("east")
- || side2.equalsIgnoreCase("south"))) {
- throw new InvalidFileFormatException("BattleShip Importer: " +
- "axes must be different and be {east | south}");
+ || !(side1.equalsIgnoreCase("east") || side1.equalsIgnoreCase("south"))
+ || !(side2.equalsIgnoreCase("east") || side2.equalsIgnoreCase("south"))) {
+ throw new InvalidFileFormatException(
+ "BattleShip Importer: " + "axes must be different and be {east | south}");
}
- NodeList eastClues = side1.equalsIgnoreCase("east")
- ? axis1.getElementsByTagName("clue") :
- axis2.getElementsByTagName("clue");
- NodeList southClues = side1.equalsIgnoreCase("south")
- ? axis1.getElementsByTagName("clue") :
- axis2.getElementsByTagName("clue");
+ NodeList eastClues =
+ side1.equalsIgnoreCase("east")
+ ? axis1.getElementsByTagName("clue")
+ : axis2.getElementsByTagName("clue");
+ NodeList southClues =
+ side1.equalsIgnoreCase("south")
+ ? axis1.getElementsByTagName("clue")
+ : axis2.getElementsByTagName("clue");
if (eastClues.getLength() != battleShipBoard.getHeight()
|| southClues.getLength() != battleShipBoard.getWidth()) {
- throw new InvalidFileFormatException("BattleShip Importer: " +
- "there must be same number of clues as the dimension " +
- "of the board");
+ throw new InvalidFileFormatException(
+ "BattleShip Importer: "
+ + "there must be same number of clues as the dimension "
+ + "of the board");
}
for (int i = 0; i < eastClues.getLength(); i++) {
Element clue = (Element) eastClues.item(i);
int value = Integer.valueOf(clue.getAttribute("value"));
- int index = BattleshipClue.colStringToColNum(
- clue.getAttribute("index"));
+ int index = BattleshipClue.colStringToColNum(clue.getAttribute("index"));
if (index - 1 < 0 || index - 1 > battleShipBoard.getHeight()) {
- throw new InvalidFileFormatException("BattleShip Importer: " +
- "clue index out of bounds");
+ throw new InvalidFileFormatException(
+ "BattleShip Importer: " + "clue index out of bounds");
}
if (battleShipBoard.getEast().get(index - 1) != null) {
- throw new InvalidFileFormatException("BattleShip Importer: " +
- "duplicate clue index");
+ throw new InvalidFileFormatException(
+ "BattleShip Importer: " + "duplicate clue index");
}
- battleShipBoard.getEast().set(index - 1, new BattleshipClue(
- value, index, BattleshipType.CLUE_EAST));
+ battleShipBoard
+ .getEast()
+ .set(index - 1, new BattleshipClue(value, index, BattleshipType.CLUE_EAST));
}
for (int i = 0; i < southClues.getLength(); i++) {
@@ -168,23 +161,25 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
int index = Integer.valueOf(clue.getAttribute("index"));
if (index - 1 < 0 || index - 1 > battleShipBoard.getWidth()) {
- throw new InvalidFileFormatException("BattleShip Importer: " +
- "clue index out of bounds");
+ throw new InvalidFileFormatException(
+ "BattleShip Importer: " + "clue index out of bounds");
}
if (battleShipBoard.getSouth().get(index - 1) != null) {
- throw new InvalidFileFormatException("BattleShip Importer: " +
- "duplicate clue index");
+ throw new InvalidFileFormatException(
+ "BattleShip Importer: " + "duplicate clue index");
}
- battleShipBoard.getSouth().set(index - 1, new BattleshipClue(
- value, index, BattleshipType.CLUE_SOUTH));
+ battleShipBoard
+ .getSouth()
+ .set(
+ index - 1,
+ new BattleshipClue(value, index, BattleshipType.CLUE_SOUTH));
}
puzzle.setCurrentBoard(battleShipBoard);
- }
- catch (NumberFormatException e) {
- throw new InvalidFileFormatException("BattleShip Importer: " +
- "unknown value where integer expected");
+ } catch (NumberFormatException e) {
+ throw new InvalidFileFormatException(
+ "BattleShip Importer: " + "unknown value where integer expected");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java
index 6994222e3..0d505f43c 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java
@@ -1,9 +1,19 @@
package edu.rpi.legup.puzzle.battleship;
public enum BattleshipType {
- UNKNOWN, WATER, SUBMARINE, SHIP_UNKNOWN,
- SHIP_TOP, SHIP_RIGHT, SHIP_BOTTOM, SHIP_LEFT, SHIP_MIDDLE,
- CLUE_NORTH, CLUE_EAST, CLUE_SOUTH, CLUE_WEST;
+ UNKNOWN,
+ WATER,
+ SUBMARINE,
+ SHIP_UNKNOWN,
+ SHIP_TOP,
+ SHIP_RIGHT,
+ SHIP_BOTTOM,
+ SHIP_LEFT,
+ SHIP_MIDDLE,
+ CLUE_NORTH,
+ CLUE_EAST,
+ CLUE_SOUTH,
+ CLUE_WEST;
public int value;
@@ -13,6 +23,7 @@ public enum BattleshipType {
/**
* Gets the enum of this BattleShipType
+ *
* @param value the integer value input
* @return enum equivalent BattleShipType of integer value
*/
@@ -31,7 +42,11 @@ public static BattleshipType getType(int value) {
* @return true if the type is a ship, false otherwise
*/
public static boolean isShip(BattleshipType type) {
- return type == SHIP_UNKNOWN || type == SHIP_TOP || type == SHIP_RIGHT
- || type == SHIP_BOTTOM || type == SHIP_LEFT || type == SHIP_MIDDLE;
+ return type == SHIP_UNKNOWN
+ || type == SHIP_TOP
+ || type == SHIP_RIGHT
+ || type == SHIP_BOTTOM
+ || type == SHIP_LEFT
+ || type == SHIP_MIDDLE;
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipView.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipView.java
index fbae2fa99..4095db54a 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipView.java
@@ -3,7 +3,6 @@
import edu.rpi.legup.controller.BoardController;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.ui.boardview.GridBoardView;
-
import java.awt.*;
public class BattleshipView extends GridBoardView {
@@ -17,7 +16,8 @@ public BattleshipView(BattleshipBoard board) {
BattleshipElementView elementView = new BattleshipElementView(cell);
elementView.setIndex(cell.getIndex());
elementView.setSize(elementSize);
- elementView.setLocation(new Point(loc.x * elementSize.width, loc.y * elementSize.height));
+ elementView.setLocation(
+ new Point(loc.x * elementSize.width, loc.y * elementSize.height));
elementViews.add(elementView);
}
}
@@ -26,4 +26,4 @@ public BattleshipView(BattleshipBoard board) {
public void drawBoard(Graphics2D graphics2D) {
super.drawBoard(graphics2D);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/AdjacentShipsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/AdjacentShipsContradictionRule.java
index 49bee101a..f1ecd6685 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/AdjacentShipsContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/AdjacentShipsContradictionRule.java
@@ -6,31 +6,29 @@
import edu.rpi.legup.puzzle.battleship.BattleshipBoard;
import edu.rpi.legup.puzzle.battleship.BattleshipCell;
import edu.rpi.legup.puzzle.battleship.BattleshipType;
-
import java.util.List;
public class AdjacentShipsContradictionRule extends ContradictionRule {
- private final String NO_CONTRADICTION_MESSAGE
- = "No instance of the contradiction " + this.ruleName + " here";
+ private final String NO_CONTRADICTION_MESSAGE =
+ "No instance of the contradiction " + this.ruleName + " here";
public AdjacentShipsContradictionRule() {
- super("BTSP-CONT-0001",
+ super(
+ "BTSP-CONT-0001",
"Adjacent Ships",
"Cells next to the battleship must be water.",
- "edu/rpi/legup/images/battleship/contradictions" +
- "/AdjacentShips.png");
+ "edu/rpi/legup/images/battleship/contradictions" + "/AdjacentShips.png");
}
/**
- * Checks whether the transition has a contradiction at the specific
- * {@link PuzzleElement} index using this rule.
+ * Checks whether the transition has a contradiction at the specific {@link PuzzleElement} index
+ * using this rule.
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent {@link PuzzleElement}
- * @return null
if the transition contains a
- * contradiction at the specified {@link PuzzleElement},
- * otherwise return a no contradiction message.
+ * @return null
if the transition contains a contradiction at the specified {@link
+ * PuzzleElement}, otherwise return a no contradiction message.
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
@@ -43,19 +41,20 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
}
// check orthogonally adjacent cells
- List orthoAdjCells
- = bsBoard.getAdjOrthogonals(cell);
+ List orthoAdjCells = bsBoard.getAdjOrthogonals(cell);
BattleshipCell up = orthoAdjCells.get(0);
BattleshipCell right = orthoAdjCells.get(1);
BattleshipCell down = orthoAdjCells.get(2);
BattleshipCell left = orthoAdjCells.get(3);
- boolean isVertical = (up != null && BattleshipType.isShip(up.getData()))
- || (down != null && BattleshipType.isShip(down.getData()));
+ boolean isVertical =
+ (up != null && BattleshipType.isShip(up.getData()))
+ || (down != null && BattleshipType.isShip(down.getData()));
- boolean isHorizontal = (left != null && BattleshipType.isShip(left.getData()))
- || (right != null && BattleshipType.isShip(right.getData()));
+ boolean isHorizontal =
+ (left != null && BattleshipType.isShip(left.getData()))
+ || (right != null && BattleshipType.isShip(right.getData()));
// ships cannot be both vertical and horizontal
if (isVertical && isHorizontal) {
@@ -63,8 +62,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
}
// check diagonally adjacent cells
- List diagAdjCells
- = bsBoard.getAdjDiagonals(cell);
+ List diagAdjCells = bsBoard.getAdjDiagonals(cell);
BattleshipCell upRight = diagAdjCells.get(0);
BattleshipCell downRight = diagAdjCells.get(1);
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ContinueShipDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ContinueShipDirectRule.java
index 18c55d635..670a136a4 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ContinueShipDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ContinueShipDirectRule.java
@@ -1,43 +1,45 @@
-package edu.rpi.legup.puzzle.battleship.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class ContinueShipDirectRule extends DirectRule {
-
- public ContinueShipDirectRule() {
- super("BTSP-BASC-0001",
- "Continue Ship",
- "",
- "edu/rpi/legup/images/battleship/rules/ContinueShip.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should be overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.battleship.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class ContinueShipDirectRule extends DirectRule {
+
+ public ContinueShipDirectRule() {
+ super(
+ "BTSP-BASC-0001",
+ "Continue Ship",
+ "",
+ "edu/rpi/legup/images/battleship/rules/ContinueShip.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should be overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithShipsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithShipsDirectRule.java
index 3374d1806..9bc4065aa 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithShipsDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithShipsDirectRule.java
@@ -1,116 +1,108 @@
-package edu.rpi.legup.puzzle.battleship.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.battleship.BattleshipBoard;
-import edu.rpi.legup.puzzle.battleship.BattleshipCell;
-import edu.rpi.legup.puzzle.battleship.BattleshipClue;
-import edu.rpi.legup.puzzle.battleship.BattleshipType;
-
-import java.awt.*;
-import java.util.List;
-
-public class FinishWithShipsDirectRule extends DirectRule {
-
- public FinishWithShipsDirectRule() {
- super("BTSP-BASC-0002",
- "Finish with Ships",
- "The number of undetermined squares is equal to the number " +
- "of segments remaining for each clue.",
- "edu/rpi/legup/images/battleship/rules/finishShip.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should be overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node
- * at the specified puzzleElement, otherwise error message.
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition,
- PuzzleElement puzzleElement) {
- BattleshipBoard initBoard = (BattleshipBoard) transition.getParents()
- .get(0).getBoard();
- BattleshipCell initCell = (BattleshipCell) initBoard
- .getPuzzleElement(puzzleElement);
- BattleshipBoard finalBoard = (BattleshipBoard) transition.getBoard();
- BattleshipCell finalCell = (BattleshipCell) finalBoard
- .getPuzzleElement(puzzleElement);
- if (!(initCell.getType() == BattleshipType.UNKNOWN
- && BattleshipType.isShip(finalCell.getType()))) {
- return super.getInvalidUseOfRuleMessage() + ": This cell must be a ship.";
- }
-
- if (isForced(initBoard, initCell)) {
- return null;
- }
- else {
- return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to" +
- "be a ship segment.";
- }
- }
-
- private boolean isForced(BattleshipBoard board, BattleshipCell cell) {
- Point loc = cell.getLocation();
-
- // count the number of ship segments and unknowns in the row
- List row = board.getRow(loc.y);
- int rowCount = 0;
- for (BattleshipCell c : row) {
- if (c.getType() == BattleshipType.SHIP_UNKNOWN
- || BattleshipType.isShip(c.getType())) {
- rowCount++;
- }
- }
-
- // count the number of ship segments and unknowns in the column
- List col = board.getColumn(loc.x);
- int colCount = 0;
- for (BattleshipCell c : col) {
- if (c.getType() == BattleshipType.SHIP_UNKNOWN
- || BattleshipType.isShip(c.getType())) {
- colCount++;
- }
- }
-
- // compare the counts with the clues
- BattleshipClue east = board.getEast().get(loc.y);
- BattleshipClue south = board.getSouth().get(loc.x);
-
- return rowCount <= east.getData() && colCount <= south.getData();
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the
- * {@link TreeNode}.
- *
- * @param node tree node used to create default transition board.
- * @return default board or null if this rule cannot be applied to this tree
- * node.
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- BattleshipBoard board = (BattleshipBoard) node.getBoard().copy();
- for (PuzzleElement element : board.getPuzzleElements()) {
- BattleshipCell cell = (BattleshipCell) element;
- if (cell.getType() == BattleshipType.UNKNOWN && isForced(board, cell)) {
- cell.setData(BattleshipType.SHIP_UNKNOWN);
- board.addModifiedData(cell);
- }
- }
-
- if (board.getModifiedData().isEmpty()) {
- return null;
- }
- else {
- return board;
- }
- }
-}
+package edu.rpi.legup.puzzle.battleship.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.battleship.BattleshipBoard;
+import edu.rpi.legup.puzzle.battleship.BattleshipCell;
+import edu.rpi.legup.puzzle.battleship.BattleshipClue;
+import edu.rpi.legup.puzzle.battleship.BattleshipType;
+import java.awt.*;
+import java.util.List;
+
+public class FinishWithShipsDirectRule extends DirectRule {
+
+ public FinishWithShipsDirectRule() {
+ super(
+ "BTSP-BASC-0002",
+ "Finish with Ships",
+ "The number of undetermined squares is equal to the number "
+ + "of segments remaining for each clue.",
+ "edu/rpi/legup/images/battleship/rules/finishShip.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should be overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message.
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ BattleshipBoard initBoard = (BattleshipBoard) transition.getParents().get(0).getBoard();
+ BattleshipCell initCell = (BattleshipCell) initBoard.getPuzzleElement(puzzleElement);
+ BattleshipBoard finalBoard = (BattleshipBoard) transition.getBoard();
+ BattleshipCell finalCell = (BattleshipCell) finalBoard.getPuzzleElement(puzzleElement);
+ if (!(initCell.getType() == BattleshipType.UNKNOWN
+ && BattleshipType.isShip(finalCell.getType()))) {
+ return super.getInvalidUseOfRuleMessage() + ": This cell must be a ship.";
+ }
+
+ if (isForced(initBoard, initCell)) {
+ return null;
+ } else {
+ return super.getInvalidUseOfRuleMessage()
+ + ": This cell is not forced to"
+ + "be a ship segment.";
+ }
+ }
+
+ private boolean isForced(BattleshipBoard board, BattleshipCell cell) {
+ Point loc = cell.getLocation();
+
+ // count the number of ship segments and unknowns in the row
+ List row = board.getRow(loc.y);
+ int rowCount = 0;
+ for (BattleshipCell c : row) {
+ if (c.getType() == BattleshipType.SHIP_UNKNOWN || BattleshipType.isShip(c.getType())) {
+ rowCount++;
+ }
+ }
+
+ // count the number of ship segments and unknowns in the column
+ List col = board.getColumn(loc.x);
+ int colCount = 0;
+ for (BattleshipCell c : col) {
+ if (c.getType() == BattleshipType.SHIP_UNKNOWN || BattleshipType.isShip(c.getType())) {
+ colCount++;
+ }
+ }
+
+ // compare the counts with the clues
+ BattleshipClue east = board.getEast().get(loc.y);
+ BattleshipClue south = board.getSouth().get(loc.x);
+
+ return rowCount <= east.getData() && colCount <= south.getData();
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board.
+ * @return default board or null if this rule cannot be applied to this tree node.
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ BattleshipBoard board = (BattleshipBoard) node.getBoard().copy();
+ for (PuzzleElement element : board.getPuzzleElements()) {
+ BattleshipCell cell = (BattleshipCell) element;
+ if (cell.getType() == BattleshipType.UNKNOWN && isForced(board, cell)) {
+ cell.setData(BattleshipType.SHIP_UNKNOWN);
+ board.addModifiedData(cell);
+ }
+ }
+
+ if (board.getModifiedData().isEmpty()) {
+ return null;
+ } else {
+ return board;
+ }
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithWaterDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithWaterDirectRule.java
index 157b13d01..99e5925e0 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithWaterDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithWaterDirectRule.java
@@ -1,43 +1,45 @@
-package edu.rpi.legup.puzzle.battleship.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class FinishWithWaterDirectRule extends DirectRule {
-
- public FinishWithWaterDirectRule() {
- super("BTSP-BASC-0003",
- "Finish with Water",
- "",
- "edu/rpi/legup/images/battleship/rules/finishWater.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.battleship.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class FinishWithWaterDirectRule extends DirectRule {
+
+ public FinishWithWaterDirectRule() {
+ super(
+ "BTSP-BASC-0003",
+ "Finish with Water",
+ "",
+ "edu/rpi/legup/images/battleship/rules/finishWater.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/IncompleteShipContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/IncompleteShipContradictionRule.java
index 4a6cb3d15..e8cfebb90 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/IncompleteShipContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/IncompleteShipContradictionRule.java
@@ -7,19 +7,21 @@
public class IncompleteShipContradictionRule extends ContradictionRule {
public IncompleteShipContradictionRule() {
- super("BTSP-CONT-0002",
+ super(
+ "BTSP-CONT-0002",
"Incomplete Ship",
"",
"edu/rpi/legup/images/battleship/contradictions/IncompleteShip.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeCaseRule.java
index 3850ee39f..93079fb71 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeCaseRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeCaseRule.java
@@ -5,20 +5,20 @@
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.tree.TreeTransition;
-
import java.util.List;
public class SegmentTypeCaseRule extends CaseRule {
public SegmentTypeCaseRule() {
- super("BTSP-CASE-0001",
+ super(
+ "BTSP-CASE-0001",
"Segment Type",
"",
"edu/rpi/legup/images/battleship/cases/SegmentType.png");
}
/**
- * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is
- * the one that should overridden in child classes.
+ * Checks whether the {@link TreeTransition} logically follows from the parent node using this
+ * rule. This method is the one that should overridden in child classes.
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
@@ -29,13 +29,14 @@ public String checkRuleRaw(TreeTransition transition) {
}
/**
- * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using
- * this rule. This method is the one that should overridden in child classes.
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule. This method is the one that should overridden in child
+ * classes.
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
@@ -43,7 +44,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
}
/**
- * Gets the case board that indicates where this case rule can be applied on the given {@link Board}.
+ * Gets the case board that indicates where this case rule can be applied on the given {@link
+ * Board}.
*
* @param board board to find locations where this case rule can be applied
* @return a case board
@@ -54,9 +56,10 @@ public CaseBoard getCaseBoard(Board board) {
}
/**
- * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule.
+ * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on
+ * this case rule.
*
- * @param board the current board state
+ * @param board the current board state
* @param puzzleElement equivalent puzzleElement
* @return a list of elements the specified could be
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeDirectRule.java
index f90dea1bd..8576ef722 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeDirectRule.java
@@ -1,43 +1,45 @@
-package edu.rpi.legup.puzzle.battleship.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class SegmentTypeDirectRule extends DirectRule {
-
- public SegmentTypeDirectRule() {
- super("BTSP-BASC-0004",
- "Segment Type",
- "",
- "edu/rpi/legup/images/battleship/rules/SegmentChoice.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.battleship.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class SegmentTypeDirectRule extends DirectRule {
+
+ public SegmentTypeDirectRule() {
+ super(
+ "BTSP-BASC-0004",
+ "Segment Type",
+ "",
+ "edu/rpi/legup/images/battleship/rules/SegmentChoice.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipLocationCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipLocationCaseRule.java
index f21488cca..da8f33cc2 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipLocationCaseRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipLocationCaseRule.java
@@ -5,21 +5,21 @@
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.tree.TreeTransition;
-
import java.util.List;
public class ShipLocationCaseRule extends CaseRule {
public ShipLocationCaseRule() {
- super("BTSP-CASE-0002",
+ super(
+ "BTSP-CASE-0002",
"Ship Location",
"",
"edu/rpi/legup/images/battleship/cases/ShipLocations.png");
}
/**
- * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is
- * the one that should overridden in child classes.
+ * Checks whether the {@link TreeTransition} logically follows from the parent node using this
+ * rule. This method is the one that should overridden in child classes.
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
@@ -30,13 +30,14 @@ public String checkRuleRaw(TreeTransition transition) {
}
/**
- * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using
- * this rule. This method is the one that should overridden in child classes.
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule. This method is the one that should overridden in child
+ * classes.
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
@@ -44,7 +45,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
}
/**
- * Gets the case board that indicates where this case rule can be applied on the given {@link Board}.
+ * Gets the case board that indicates where this case rule can be applied on the given {@link
+ * Board}.
*
* @param board board to find locations where this case rule can be applied
* @return a case board
@@ -55,9 +57,10 @@ public CaseBoard getCaseBoard(Board board) {
}
/**
- * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule.
+ * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on
+ * this case rule.
*
- * @param board the current board state
+ * @param board the current board state
* @param puzzleElement equivalent puzzleElement
* @return a list of elements the specified could be
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipOrWaterCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipOrWaterCaseRule.java
index a419b831f..3c123d7c1 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipOrWaterCaseRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipOrWaterCaseRule.java
@@ -5,21 +5,21 @@
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.tree.TreeTransition;
-
import java.util.List;
public class ShipOrWaterCaseRule extends CaseRule {
public ShipOrWaterCaseRule() {
- super("BTSP-CASE-0003",
+ super(
+ "BTSP-CASE-0003",
"Ship or Water",
"",
"edu/rpi/legup/images/battleship/cases/ShipOrWater.png");
}
/**
- * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is
- * the one that should overridden in child classes.
+ * Checks whether the {@link TreeTransition} logically follows from the parent node using this
+ * rule. This method is the one that should overridden in child classes.
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
@@ -30,13 +30,14 @@ public String checkRuleRaw(TreeTransition transition) {
}
/**
- * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using
- * this rule. This method is the one that should overridden in child classes.
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule. This method is the one that should overridden in child
+ * classes.
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
@@ -44,7 +45,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
}
/**
- * Gets the case board that indicates where this case rule can be applied on the given {@link Board}.
+ * Gets the case board that indicates where this case rule can be applied on the given {@link
+ * Board}.
*
* @param board board to find locations where this case rule can be applied
* @return a case board
@@ -55,9 +57,10 @@ public CaseBoard getCaseBoard(Board board) {
}
/**
- * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule.
+ * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on
+ * this case rule.
*
- * @param board the current board state
+ * @param board the current board state
* @param puzzleElement equivalent puzzleElement
* @return a list of elements the specified could be
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SurroundShipDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SurroundShipDirectRule.java
index 57ad42121..d26c3ed29 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SurroundShipDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SurroundShipDirectRule.java
@@ -1,43 +1,45 @@
-package edu.rpi.legup.puzzle.battleship.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class SurroundShipDirectRule extends DirectRule {
-
- public SurroundShipDirectRule() {
- super("BTSP-BASC-0005",
- "Surround Ship",
- "",
- "edu/rpi/legup/images/battleship/rules/SurroundShip.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.battleship.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class SurroundShipDirectRule extends DirectRule {
+
+ public SurroundShipDirectRule() {
+ super(
+ "BTSP-BASC-0005",
+ "Surround Ship",
+ "",
+ "edu/rpi/legup/images/battleship/rules/SurroundShip.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewInFleetContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewInFleetContradictionRule.java
index 5a4eb187e..d10e086d2 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewInFleetContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewInFleetContradictionRule.java
@@ -7,19 +7,21 @@
public class TooFewInFleetContradictionRule extends ContradictionRule {
public TooFewInFleetContradictionRule() {
- super("BTSP-CONT-0003",
+ super(
+ "BTSP-CONT-0003",
"Too Few in Fleet",
"",
"edu/rpi/legup/images/battleship/contradictions/too_few_in_fleet.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewRowColContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewRowColContradictionRule.java
index 7c2fa7819..382ba6e39 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewRowColContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewRowColContradictionRule.java
@@ -7,19 +7,21 @@
public class TooFewRowColContradictionRule extends ContradictionRule {
public TooFewRowColContradictionRule() {
- super("BTSP-CONT-0004",
+ super(
+ "BTSP-CONT-0004",
"Too few in row/col",
"",
"edu/rpi/legup/images/battleship/contradictions/too_few_segments.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyInFleetContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyInFleetContradictionRule.java
index 3aad88613..d58701c0b 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyInFleetContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyInFleetContradictionRule.java
@@ -7,19 +7,21 @@
public class TooManyInFleetContradictionRule extends ContradictionRule {
public TooManyInFleetContradictionRule() {
- super("BTSP-CONT-0005",
+ super(
+ "BTSP-CONT-0005",
"Too Many in Fleet",
"",
"edu/rpi/legup/images/battleship/contradictions/too_many_in_fleet.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyRowColContradiction.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyRowColContradiction.java
index 0970c9c69..27caa0524 100644
--- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyRowColContradiction.java
+++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyRowColContradiction.java
@@ -7,19 +7,21 @@
public class TooManyRowColContradiction extends ContradictionRule {
public TooManyRowColContradiction() {
- super("BTSP-CONT-0006",
+ super(
+ "BTSP-CONT-0006",
"Too Many row/col",
"",
"edu/rpi/legup/images/battleship/contradictions/too_many_segments.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/Fillapix.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/Fillapix.java
index ef78f66aa..79574caa6 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/Fillapix.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/Fillapix.java
@@ -6,9 +6,7 @@
import edu.rpi.legup.model.rules.ContradictionRule;
public class Fillapix extends Puzzle {
- /**
- * Fillapix Constructor
- */
+ /** Fillapix Constructor */
public Fillapix() {
super();
@@ -20,9 +18,7 @@ public Fillapix() {
this.factory = new FillapixCellFactory();
}
- /**
- * Initializes the game board
- */
+ /** Initializes the game board */
@Override
public void initializeView() {
boardView = new FillapixView((FillapixBoard) currentBoard);
@@ -39,8 +35,8 @@ public Board generatePuzzle(int difficulty) {
/**
* Determines if the given dimensions are valid for Fillapix
*
- * @param rows the number of rows
- * @param columns the number of columns
+ * @param rows the number of rows
+ * @param columns the number of columns
* @return true if the given dimensions are valid for Fillapix, false otherwise
*/
public boolean isValidDimensions(int rows, int columns) {
@@ -65,7 +61,5 @@ public boolean isBoardComplete(Board board) {
}
@Override
- public void onBoardChange(Board board) {
-
- }
-}
\ No newline at end of file
+ public void onBoardChange(Board board) {}
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixBoard.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixBoard.java
index 67987a6fd..a6672bd4f 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixBoard.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixBoard.java
@@ -2,12 +2,11 @@
import edu.rpi.legup.model.gameboard.GridBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-
import java.awt.*;
import java.util.logging.Logger;
public class FillapixBoard extends GridBoard {
- private final static Logger LOGGER = Logger.getLogger(FillapixBoard.class.getName());
+ private static final Logger LOGGER = Logger.getLogger(FillapixBoard.class.getName());
public FillapixBoard(int width, int height) {
super(width, height);
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCell.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCell.java
index 5e6d4b9ed..a9e5aa2df 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCell.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCell.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.elements.Element;
import edu.rpi.legup.model.gameboard.GridCell;
-
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.Objects;
@@ -42,7 +41,7 @@ public void setCellType(FillapixCellType type) {
@Override
public void setType(Element e, MouseEvent m) {
- switch(e.getElementID()) {
+ switch (e.getElementID()) {
case "FPIX-PLAC-0001":
this.setCellType(FillapixCellType.BLACK);
break;
@@ -88,9 +87,11 @@ public FillapixCell copy() {
}
public boolean equals(FillapixCell otherCell) {
-// return this.location.equals(otherCell.location) && this.index == otherCell.index && this.data == otherCell.data;
- //return this.index == otherCell.index && this.data == otherCell.data;
- //return this.index == otherCell.index;
+ // return this.location.equals(otherCell.location) && this.index == otherCell.index
+ // &&
+ // this.data == otherCell.data;
+ // return this.index == otherCell.index && this.data == otherCell.data;
+ // return this.index == otherCell.index;
return this.location.x == otherCell.location.x && this.location.y == otherCell.location.y;
}
@@ -101,4 +102,4 @@ public int compareTo(FillapixCell otherCell) {
public int hashCode() {
return Objects.hash(this.index);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellController.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellController.java
index df3bba403..f59c0df47 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellController.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellController.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.controller.ElementController;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-
import java.awt.event.MouseEvent;
public class FillapixCellController extends ElementController {
@@ -11,34 +10,33 @@ public void changeCell(MouseEvent e, PuzzleElement puzzleElement) {
FillapixCell cell = (FillapixCell) puzzleElement;
if (e.getButton() == MouseEvent.BUTTON1) {
if (e.isControlDown()) {
- this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY());
- }
- else {
+ this.boardView
+ .getSelectionPopupMenu()
+ .show(
+ boardView,
+ this.boardView.getCanvas().getX() + e.getX(),
+ this.boardView.getCanvas().getY() + e.getY());
+ } else {
if (cell.getType() == FillapixCellType.UNKNOWN) {
cell.setCellType(FillapixCellType.BLACK);
- }
- else {
+ } else {
if (cell.getType() == FillapixCellType.BLACK) {
cell.setCellType(FillapixCellType.WHITE);
- }
- else {
+ } else {
if (cell.getType() == FillapixCellType.WHITE) {
cell.setCellType(FillapixCellType.UNKNOWN);
}
}
}
}
- }
- else {
+ } else {
if (e.getButton() == MouseEvent.BUTTON3) {
if (cell.getType() == FillapixCellType.UNKNOWN) {
cell.setCellType(FillapixCellType.WHITE);
- }
- else {
+ } else {
if (cell.getType() == FillapixCellType.BLACK) {
cell.setCellType(FillapixCellType.UNKNOWN);
- }
- else {
+ } else {
if (cell.getType() == FillapixCellType.WHITE) {
cell.setCellType(FillapixCellType.BLACK);
}
@@ -47,4 +45,4 @@ public void changeCell(MouseEvent e, PuzzleElement puzzleElement) {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java
index fcc48bccd..9f689bc96 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java
@@ -4,17 +4,16 @@
import edu.rpi.legup.model.gameboard.ElementFactory;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.awt.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import java.awt.*;
-
public class FillapixCellFactory extends ElementFactory {
/**
* Creates a puzzleElement based on the xml document Node and adds it to the board
*
- * @param node node that represents the puzzleElement
+ * @param node node that represents the puzzleElement
* @param board board to add the newly created cell
* @return newly created cell from the xml document Node
* @throws InvalidFileFormatException if file is invalid
@@ -23,7 +22,8 @@ public class FillapixCellFactory extends ElementFactory {
public FillapixCell importCell(Node node, Board board) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("cell")) {
- throw new InvalidFileFormatException("Fillapix Factory: unknown puzzleElement puzzleElement");
+ throw new InvalidFileFormatException(
+ "Fillapix Factory: unknown puzzleElement puzzleElement");
}
FillapixBoard fillapixBoard = (FillapixBoard) board;
@@ -35,7 +35,8 @@ public FillapixCell importCell(Node node, Board board) throws InvalidFileFormatE
int x = Integer.valueOf(attributeList.getNamedItem("x").getNodeValue());
int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue());
if (x >= width || y >= height) {
- throw new InvalidFileFormatException("Fillapix Factory: cell location out of bounds");
+ throw new InvalidFileFormatException(
+ "Fillapix Factory: cell location out of bounds");
}
if (value / 100 > 2 || value % 100 > 10) {
throw new InvalidFileFormatException("Fillapix Factory: cell unknown value");
@@ -44,11 +45,10 @@ public FillapixCell importCell(Node node, Board board) throws InvalidFileFormatE
FillapixCell cell = new FillapixCell(value, new Point(x, y));
cell.setIndex(y * height + x);
return cell;
- }
- catch (NumberFormatException e) {
- throw new InvalidFileFormatException("Fillapix Factory: unknown value where integer expected");
- }
- catch (NullPointerException e) {
+ } catch (NumberFormatException e) {
+ throw new InvalidFileFormatException(
+ "Fillapix Factory: unknown value where integer expected");
+ } catch (NullPointerException e) {
throw new InvalidFileFormatException("Fillapix Factory: could not find attribute(s)");
}
}
@@ -56,7 +56,7 @@ public FillapixCell importCell(Node node, Board board) throws InvalidFileFormatE
/**
* Creates a xml document puzzleElement from a cell for exporting
*
- * @param document xml document
+ * @param document xml document
* @param puzzleElement PuzzleElement cell
* @return xml PuzzleElement
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellType.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellType.java
index 3789fe339..28a263467 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellType.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellType.java
@@ -1,7 +1,9 @@
package edu.rpi.legup.puzzle.fillapix;
public enum FillapixCellType {
- UNKNOWN(0), BLACK(1), WHITE(2);
+ UNKNOWN(0),
+ BLACK(1),
+ WHITE(2);
public int value;
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixElementView.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixElementView.java
index 93fa0d451..47465a522 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixElementView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixElementView.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.puzzle.fillapix;
import edu.rpi.legup.ui.boardview.GridElementView;
-
import java.awt.*;
public class FillapixElementView extends GridElementView {
@@ -53,10 +52,11 @@ public void drawElement(Graphics2D graphics2D) {
FontMetrics metrics = graphics2D.getFontMetrics(FONT);
String value = String.valueOf(cell.getNumber());
int xText = location.x + (size.width - metrics.stringWidth(value)) / 2;
- int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent();
+ int yText =
+ location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent();
graphics2D.drawString(value, xText, yText);
}
graphics2D.setColor(BLACK_COLOR);
graphics2D.drawRect(location.x, location.y, size.width, size.height);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java
index 757d14cd8..ffabd8762 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.PuzzleExporter;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard;
import org.w3c.dom.Document;
public class FillapixExporter extends PuzzleExporter {
@@ -16,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
FillapixBoard board;
if (puzzle.getTree() != null) {
board = (FillapixBoard) puzzle.getTree().getRootNode().getBoard();
- }
- else {
+ } else {
board = (FillapixBoard) puzzle.getBoardView().getBoard();
}
@@ -29,7 +27,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
for (PuzzleElement puzzleElement : board.getPuzzleElements()) {
FillapixCell cell = (FillapixCell) puzzleElement;
if (cell.getNumber() != -1 || cell.getType() != FillapixCellType.UNKNOWN) {
- org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement);
+ org.w3c.dom.Element cellElement =
+ puzzle.getFactory().exportCell(newDocument, puzzleElement);
cellsElement.appendChild(cellElement);
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java
index 5213e7139..d16bc8219 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java
@@ -2,12 +2,11 @@
import edu.rpi.legup.model.PuzzleImporter;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.awt.*;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import java.awt.*;
-
public class FillapixImporter extends PuzzleImporter {
public FillapixImporter(Fillapix fillapix) {
super(fillapix);
@@ -26,7 +25,7 @@ public boolean acceptsTextInput() {
/**
* Creates an empty board for building
*
- * @param rows the number of rows on the board
+ * @param rows the number of rows on the board
* @param columns the number of columns on the board
* @throws RuntimeException if board can not be made
*/
@@ -36,7 +35,8 @@ public void initializeBoard(int rows, int columns) {
for (int y = 0; y < rows; y++) {
for (int x = 0; x < columns; x++) {
- FillapixCell cell = new FillapixCell(FillapixCellType.UNKNOWN.value, new Point(x, y));
+ FillapixCell cell =
+ new FillapixCell(FillapixCellType.UNKNOWN.value, new Point(x, y));
cell.setIndex(y * columns + x);
cell.setNumber(FillapixCell.DEFAULT_VALUE);
cell.setModifiable(true);
@@ -56,11 +56,13 @@ public void initializeBoard(int rows, int columns) {
public void initializeBoard(Node node) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("board")) {
- throw new InvalidFileFormatException("Fillapix Importer: cannot find board puzzleElement");
+ throw new InvalidFileFormatException(
+ "Fillapix Importer: cannot find board puzzleElement");
}
Element boardElement = (Element) node;
if (boardElement.getElementsByTagName("cells").getLength() == 0) {
- throw new InvalidFileFormatException("Fillapix Importer: no puzzleElement found for board");
+ throw new InvalidFileFormatException(
+ "Fillapix Importer: no puzzleElement found for board");
}
Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0);
NodeList elementDataList = dataElement.getElementsByTagName("cell");
@@ -69,9 +71,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
if (!boardElement.getAttribute("size").isEmpty()) {
int size = Integer.valueOf(boardElement.getAttribute("size"));
fillapixBoard = new FillapixBoard(size);
- }
- else {
- if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) {
+ } else {
+ if (!boardElement.getAttribute("width").isEmpty()
+ && !boardElement.getAttribute("height").isEmpty()) {
int width = Integer.valueOf(boardElement.getAttribute("width"));
int height = Integer.valueOf(boardElement.getAttribute("height"));
fillapixBoard = new FillapixBoard(width, height);
@@ -86,7 +88,10 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
int height = fillapixBoard.getHeight();
for (int i = 0; i < elementDataList.getLength(); i++) {
- FillapixCell cell = (FillapixCell) puzzle.getFactory().importCell(elementDataList.item(i), fillapixBoard);
+ FillapixCell cell =
+ (FillapixCell)
+ puzzle.getFactory()
+ .importCell(elementDataList.item(i), fillapixBoard);
Point loc = cell.getLocation();
cell.setModifiable(true);
cell.setGiven(true);
@@ -96,7 +101,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (fillapixBoard.getCell(x, y) == null) {
- FillapixCell cell = new FillapixCell(FillapixCell.DEFAULT_VALUE, new Point(x, y));
+ FillapixCell cell =
+ new FillapixCell(FillapixCell.DEFAULT_VALUE, new Point(x, y));
cell.setIndex(y * height + x);
cell.setModifiable(true);
fillapixBoard.setCell(x, y, cell);
@@ -104,9 +110,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
}
}
puzzle.setCurrentBoard(fillapixBoard);
- }
- catch (NumberFormatException e) {
- throw new InvalidFileFormatException("Fillapix Importer: unknown value where integer expected");
+ } catch (NumberFormatException e) {
+ throw new InvalidFileFormatException(
+ "Fillapix Importer: unknown value where integer expected");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixUtilities.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixUtilities.java
index a7feac91d..571a0c7f7 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixUtilities.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixUtilities.java
@@ -3,14 +3,14 @@
import edu.rpi.legup.model.rules.ContradictionRule;
import edu.rpi.legup.puzzle.fillapix.rules.TooFewBlackCellsContradictionRule;
import edu.rpi.legup.puzzle.fillapix.rules.TooManyBlackCellsContradictionRule;
-
import java.awt.*;
import java.util.ArrayList;
public class FillapixUtilities {
public static boolean isForcedBlack(FillapixBoard board, FillapixCell cell) {
- TooFewBlackCellsContradictionRule tooManyBlackCells = new TooFewBlackCellsContradictionRule();
+ TooFewBlackCellsContradictionRule tooManyBlackCells =
+ new TooFewBlackCellsContradictionRule();
FillapixBoard whiteCaseBoard = board.copy();
FillapixCell whiteCell = (FillapixCell) whiteCaseBoard.getPuzzleElement(cell);
whiteCell.setCellType(FillapixCellType.WHITE);
@@ -24,7 +24,8 @@ public static boolean isForcedBlack(FillapixBoard board, FillapixCell cell) {
}
public static boolean isForcedWhite(FillapixBoard board, FillapixCell cell) {
- TooManyBlackCellsContradictionRule tooManyBlackCells = new TooManyBlackCellsContradictionRule();
+ TooManyBlackCellsContradictionRule tooManyBlackCells =
+ new TooManyBlackCellsContradictionRule();
FillapixBoard blackCaseBoard = board.copy();
FillapixCell blackCell = (FillapixCell) blackCaseBoard.getPuzzleElement(cell);
blackCell.setCellType(FillapixCellType.BLACK);
@@ -59,15 +60,16 @@ public static boolean hasEmptyAdjacent(FillapixBoard board, FillapixCell cell) {
return false;
}
- /**
- * Gets all cells adjacent to a specific cell. The cell itself will be included.
- */
+ /** Gets all cells adjacent to a specific cell. The cell itself will be included. */
public static ArrayList getAdjacentCells(FillapixBoard board, FillapixCell cell) {
ArrayList adjCells = new ArrayList();
Point cellLoc = cell.getLocation();
- for (int i=-1; i <= 1; i++) {
- for (int j=-1; j <= 1; j++) {
- if (cellLoc.getX() + i < 0 || cellLoc.y + j < 0 || cellLoc.x + i >= board.getWidth() || cellLoc.y + j >= board.getHeight()) {
+ for (int i = -1; i <= 1; i++) {
+ for (int j = -1; j <= 1; j++) {
+ if (cellLoc.getX() + i < 0
+ || cellLoc.y + j < 0
+ || cellLoc.x + i >= board.getWidth()
+ || cellLoc.y + j >= board.getHeight()) {
continue;
}
FillapixCell adjCell = board.getCell(cellLoc.x + i, cellLoc.y + j);
@@ -81,22 +83,34 @@ public static ArrayList getAdjacentCells(FillapixBoard board, Fill
}
/**
- * Gets all cells that are contained in the square defined as having 'distance'
- * cells between the center and the outer wall. For example, distance = 1:
- * |X|X|X|X|X|
- * |X| | | |X|
- * |X| |O| |X|
- * |X| | | |X|
- * |X|X|X|X|X|
- * O is 'cell', and all 'X' will be returned in the ArrayList
+ * Gets all cells that are contained in the square defined as having 'distance' cells between
+ * the center and the outer wall. For example, distance = 1:
+ *
+ *
|X|X|X|X|X|
+ *
+ *
|X| | | |X|
+ *
+ *
|X| |O| |X|
+ *
+ *
|X| | | |X|
+ *
+ *
|X|X|X|X|X|
+ *
+ *
O is 'cell', and all 'X' will be returned in the ArrayList
*/
- public static ArrayList getCellsAtDistance(FillapixBoard board, FillapixCell cell, int distance) {
+ public static ArrayList getCellsAtDistance(
+ FillapixBoard board, FillapixCell cell, int distance) {
ArrayList adjCells = new ArrayList();
Point cellLoc = cell.getLocation();
int i = 0, j = 0;
// top line
- for (i = cellLoc.x - (distance), j = cellLoc.y - (distance+1); i <= cellLoc.x + (distance+1); i++) {
- if (cellLoc.getX() + i < 0 || cellLoc.y + j < 0 || cellLoc.x + i >= board.getWidth() || cellLoc.y + j >= board.getHeight()) {
+ for (i = cellLoc.x - (distance), j = cellLoc.y - (distance + 1);
+ i <= cellLoc.x + (distance + 1);
+ i++) {
+ if (cellLoc.getX() + i < 0
+ || cellLoc.y + j < 0
+ || cellLoc.x + i >= board.getWidth()
+ || cellLoc.y + j >= board.getHeight()) {
continue;
}
FillapixCell adjCell = board.getCell(cellLoc.x + i, cellLoc.y + j);
@@ -106,8 +120,13 @@ public static ArrayList getCellsAtDistance(FillapixBoard board, Fi
adjCells.add(adjCell);
}
// right line
- for (i = cellLoc.x + (distance+1), j = cellLoc.y - (distance); j <= cellLoc.y + (distance+1); j++) {
- if (cellLoc.getX() + i < 0 || cellLoc.y + j < 0 || cellLoc.x + i >= board.getWidth() || cellLoc.y + j >= board.getHeight()) {
+ for (i = cellLoc.x + (distance + 1), j = cellLoc.y - (distance);
+ j <= cellLoc.y + (distance + 1);
+ j++) {
+ if (cellLoc.getX() + i < 0
+ || cellLoc.y + j < 0
+ || cellLoc.x + i >= board.getWidth()
+ || cellLoc.y + j >= board.getHeight()) {
continue;
}
FillapixCell adjCell = board.getCell(cellLoc.x + i, cellLoc.y + j);
@@ -115,10 +134,15 @@ public static ArrayList getCellsAtDistance(FillapixBoard board, Fi
continue;
}
adjCells.add(adjCell);
- }
+ }
// bottom line
- for (i = cellLoc.x + (distance), j = cellLoc.y + (distance+1); i <= cellLoc.x - (distance+1); i--) {
- if (cellLoc.getX() + i < 0 || cellLoc.y + j < 0 || cellLoc.x + i >= board.getWidth() || cellLoc.y + j >= board.getHeight()) {
+ for (i = cellLoc.x + (distance), j = cellLoc.y + (distance + 1);
+ i <= cellLoc.x - (distance + 1);
+ i--) {
+ if (cellLoc.getX() + i < 0
+ || cellLoc.y + j < 0
+ || cellLoc.x + i >= board.getWidth()
+ || cellLoc.y + j >= board.getHeight()) {
continue;
}
FillapixCell adjCell = board.getCell(cellLoc.x + i, cellLoc.y + j);
@@ -126,10 +150,15 @@ public static ArrayList getCellsAtDistance(FillapixBoard board, Fi
continue;
}
adjCells.add(adjCell);
- }
+ }
// left line
- for (i = cellLoc.x - (distance+1), j = cellLoc.y + (distance); j <= cellLoc.y - (distance+1); j--) {
- if (cellLoc.getX() + i < 0 || cellLoc.y + j < 0 || cellLoc.x + i >= board.getWidth() || cellLoc.y + j >= board.getHeight()) {
+ for (i = cellLoc.x - (distance + 1), j = cellLoc.y + (distance);
+ j <= cellLoc.y - (distance + 1);
+ j--) {
+ if (cellLoc.getX() + i < 0
+ || cellLoc.y + j < 0
+ || cellLoc.x + i >= board.getWidth()
+ || cellLoc.y + j >= board.getHeight()) {
continue;
}
FillapixCell adjCell = board.getCell(cellLoc.x + i, cellLoc.y + j);
@@ -137,25 +166,25 @@ public static ArrayList getCellsAtDistance(FillapixBoard board, Fi
continue;
}
adjCells.add(adjCell);
- }
+ }
return adjCells;
- }
+ }
/**
- * Finds all possible combinations of chosenNumObj
items can be
- * chosen from totalNumObj
total items.
- * For example, if 1 item is chosen from 2 possible items, the combinations
- * are:
+ * Finds all possible combinations of chosenNumObj
items can be chosen from
+ * totalNumObj
total items. For example, if 1 item is chosen from 2 possible items, the
+ * combinations are:
+ *
* [ [true,false], [false,true] ]
- *
+ *
* @param totalNumItems the total number of items that can possibly be chosen
* @param chosenNumItems the number of items to be chosen
- *
- * @return an ArrayList of Boolean arrays. Each index in the ArrayList represents
- * a distinct combination. Each Boolean array will be totalNumItems
- * long and each index will be true
if the corresponding item is
- * included in that combination, and false
otherwise.
+ * @return an ArrayList of Boolean arrays. Each index in the ArrayList represents a distinct
+ * combination. Each Boolean array will be totalNumItems
long and each index
+ * will be true
if the corresponding item is included in that combination, and
+ *
+ * false
otherwise.
*/
public static ArrayList getCombinations(int chosenNumItems, int totalNumItems) {
ArrayList combinations = new ArrayList();
@@ -165,9 +194,15 @@ public static ArrayList getCombinations(int chosenNumItems, int total
recurseCombinations(combinations, 0, chosenNumItems, 0, totalNumItems, array);
return combinations;
- }
+ }
- private static void recurseCombinations(ArrayList result, int curIndex, int maxBlack, int numBlack, int len, boolean[] workingArray) {
+ private static void recurseCombinations(
+ ArrayList result,
+ int curIndex,
+ int maxBlack,
+ int numBlack,
+ int len,
+ boolean[] workingArray) {
if (curIndex == len) {
// complete, but not valid solution
if (numBlack != maxBlack) {
@@ -184,19 +219,19 @@ private static void recurseCombinations(ArrayList result, int curInde
if (numBlack < maxBlack) {
workingArray[curIndex] = true;
- recurseCombinations(result, curIndex+1, maxBlack, numBlack+1, len, workingArray);
+ recurseCombinations(result, curIndex + 1, maxBlack, numBlack + 1, len, workingArray);
}
workingArray[curIndex] = false;
- recurseCombinations(result, curIndex+1, maxBlack, numBlack, len, workingArray);
+ recurseCombinations(result, curIndex + 1, maxBlack, numBlack, len, workingArray);
}
-
+
public static boolean checkBoardForContradiction(FillapixBoard board) {
ContradictionRule tooManyBlack = new TooManyBlackCellsContradictionRule();
ContradictionRule tooManyWhite = new TooFewBlackCellsContradictionRule();
- for (int i= 0; i < board.getWidth(); i++) {
- for (int j=0; j < board.getHeight(); j++) {
- if (tooManyBlack.checkContradictionAt(board, board.getCell(i, j)) == null ||
- tooManyWhite.checkContradictionAt(board, board.getCell(i, j)) == null) {
+ for (int i = 0; i < board.getWidth(); i++) {
+ for (int j = 0; j < board.getHeight(); j++) {
+ if (tooManyBlack.checkContradictionAt(board, board.getCell(i, j)) == null
+ || tooManyWhite.checkContradictionAt(board, board.getCell(i, j)) == null) {
return true;
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixView.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixView.java
index 7e6453f58..55332e47d 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixView.java
@@ -3,7 +3,6 @@
import edu.rpi.legup.controller.BoardController;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.ui.boardview.GridBoardView;
-
import java.awt.*;
public class FillapixView extends GridBoardView {
@@ -16,8 +15,9 @@ public FillapixView(FillapixBoard board) {
FillapixElementView elementView = new FillapixElementView(cell);
elementView.setIndex(cell.getIndex());
elementView.setSize(elementSize);
- elementView.setLocation(new Point(loc.x * elementSize.width, loc.y * elementSize.height));
+ elementView.setLocation(
+ new Point(loc.x * elementSize.width, loc.y * elementSize.height));
elementViews.add(elementView);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/BlackTile.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/BlackTile.java
index 7e43fc6b4..1d7c038a3 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/BlackTile.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/BlackTile.java
@@ -4,6 +4,10 @@
public class BlackTile extends PlaceableElement {
public BlackTile() {
- super("FPIX-PLAC-0001", "Black Tile", "The black tile", "edu/rpi/legup/images/fillapix/tiles/BlackTile.png");
+ super(
+ "FPIX-PLAC-0001",
+ "Black Tile",
+ "The black tile",
+ "edu/rpi/legup/images/fillapix/tiles/BlackTile.png");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/NumberTile.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/NumberTile.java
index beee70e21..e869aeaf9 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/NumberTile.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/NumberTile.java
@@ -6,7 +6,11 @@ public class NumberTile extends NonPlaceableElement {
private int object_num;
public NumberTile() {
- super("FPIX-UNPL-0001", "Number Tile", "A numbered tile", "edu/rpi/legup/images/fillapix/tiles/NumberTile.png");
+ super(
+ "FPIX-UNPL-0001",
+ "Number Tile",
+ "A numbered tile",
+ "edu/rpi/legup/images/fillapix/tiles/NumberTile.png");
object_num = 0;
}
@@ -23,5 +27,4 @@ public int getTileNumber() {
public void setTileNumber(int num) {
object_num = num;
}
-
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/UnknownTile.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/UnknownTile.java
index ef754782f..6778c1758 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/UnknownTile.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/UnknownTile.java
@@ -4,6 +4,10 @@
public class UnknownTile extends NonPlaceableElement {
public UnknownTile() {
- super("FPIX-UNPL-0002", "Unknown Tile", "A blank tile", "edu/rpi/legup/images/fillapix/tiles/UnknownTile.png");
+ super(
+ "FPIX-UNPL-0002",
+ "Unknown Tile",
+ "A blank tile",
+ "edu/rpi/legup/images/fillapix/tiles/UnknownTile.png");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/WhiteTile.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/WhiteTile.java
index dd27d2834..67065a7e9 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/WhiteTile.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/WhiteTile.java
@@ -4,6 +4,10 @@
public class WhiteTile extends PlaceableElement {
public WhiteTile() {
- super("FPIX-PLAC-0002", "White Tile", "The white tile", "edu/rpi/legup/images/fillapix/tiles/WhiteTile.png");
+ super(
+ "FPIX-PLAC-0002",
+ "White Tile",
+ "The white tile",
+ "edu/rpi/legup/images/fillapix/tiles/WhiteTile.png");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/BlackOrWhiteCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/BlackOrWhiteCaseRule.java
index 1e5151c48..860a6c011 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/BlackOrWhiteCaseRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/BlackOrWhiteCaseRule.java
@@ -8,13 +8,13 @@
import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
import edu.rpi.legup.puzzle.fillapix.FillapixCell;
import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
-
import java.util.ArrayList;
import java.util.List;
public class BlackOrWhiteCaseRule extends CaseRule {
public BlackOrWhiteCaseRule() {
- super("FPIX-CASE-0001",
+ super(
+ "FPIX-CASE-0001",
"Black or White",
"Each cell is either black or white.",
"edu/rpi/legup/images/fillapix/cases/BlackOrWhite.png");
@@ -62,20 +62,24 @@ public String checkRuleRaw(TreeTransition transition) {
TreeTransition case1 = childTransitions.get(0);
TreeTransition case2 = childTransitions.get(1);
- if (case1.getBoard().getModifiedData().size() != 1 ||
- case2.getBoard().getModifiedData().size() != 1) {
- return super.getInvalidUseOfRuleMessage() + ": This case rule must have 1 modified cell for each case.";
+ if (case1.getBoard().getModifiedData().size() != 1
+ || case2.getBoard().getModifiedData().size() != 1) {
+ return super.getInvalidUseOfRuleMessage()
+ + ": This case rule must have 1 modified cell for each case.";
}
FillapixCell mod1 = (FillapixCell) case1.getBoard().getModifiedData().iterator().next();
FillapixCell mod2 = (FillapixCell) case2.getBoard().getModifiedData().iterator().next();
if (!mod1.getLocation().equals(mod2.getLocation())) {
- return super.getInvalidUseOfRuleMessage() + ": This case rule must modify the same cell for each case.";
+ return super.getInvalidUseOfRuleMessage()
+ + ": This case rule must modify the same cell for each case.";
}
if (!((mod1.getType() == FillapixCellType.BLACK && mod2.getType() == FillapixCellType.WHITE)
- || (mod2.getType() == FillapixCellType.BLACK && mod1.getType() == FillapixCellType.WHITE))) {
- return super.getInvalidUseOfRuleMessage() + ": This case rule must an empty cell and a lit cell.";
+ || (mod2.getType() == FillapixCellType.BLACK
+ && mod1.getType() == FillapixCellType.WHITE))) {
+ return super.getInvalidUseOfRuleMessage()
+ + ": This case rule must an empty cell and a lit cell.";
}
return null;
@@ -85,4 +89,4 @@ public String checkRuleRaw(TreeTransition transition) {
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
return null;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackDirectRule.java
index 06a8045ed..ccc002f46 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackDirectRule.java
@@ -1,63 +1,66 @@
-package edu.rpi.legup.puzzle.fillapix.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
-import edu.rpi.legup.puzzle.fillapix.FillapixCell;
-import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
-import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
-
-public class FinishWithBlackDirectRule extends DirectRule {
- public FinishWithBlackDirectRule() {
- 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");
- }
-
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- FillapixBoard board = (FillapixBoard) transition.getBoard();
- FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard();
- FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement);
- FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);
-
- if (!(parentCell.getType() == FillapixCellType.UNKNOWN && cell.getType() == FillapixCellType.BLACK)) {
- return super.getInvalidUseOfRuleMessage() + ": This cell must be black to be applicable with this rule.";
- }
-
- if (FillapixUtilities.isForcedBlack(parentBoard, cell)) {
- return null;
- }
- else {
- return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be black";
- }
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- FillapixBoard fillapixBoard = (FillapixBoard) node.getBoard().copy();
- for (PuzzleElement element : fillapixBoard.getPuzzleElements()) {
- FillapixCell cell = (FillapixCell) element;
- if (cell.getType() == FillapixCellType.UNKNOWN && FillapixUtilities.isForcedBlack((FillapixBoard) node.getBoard(), cell)) {
- cell.setCellType(FillapixCellType.BLACK);
- fillapixBoard.addModifiedData(cell);
- }
- }
- if (fillapixBoard.getModifiedData().isEmpty()) {
- return null;
- }
- else {
- return fillapixBoard;
- }
- }
-}
\ No newline at end of file
+package edu.rpi.legup.puzzle.fillapix.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
+import edu.rpi.legup.puzzle.fillapix.FillapixCell;
+import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
+import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
+
+public class FinishWithBlackDirectRule extends DirectRule {
+ public FinishWithBlackDirectRule() {
+ 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");
+ }
+
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ FillapixBoard board = (FillapixBoard) transition.getBoard();
+ FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard();
+ FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement);
+ FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);
+
+ if (!(parentCell.getType() == FillapixCellType.UNKNOWN
+ && cell.getType() == FillapixCellType.BLACK)) {
+ return super.getInvalidUseOfRuleMessage()
+ + ": This cell must be black to be applicable with this rule.";
+ }
+
+ if (FillapixUtilities.isForcedBlack(parentBoard, cell)) {
+ return null;
+ } else {
+ return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be black";
+ }
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ FillapixBoard fillapixBoard = (FillapixBoard) node.getBoard().copy();
+ for (PuzzleElement element : fillapixBoard.getPuzzleElements()) {
+ FillapixCell cell = (FillapixCell) element;
+ if (cell.getType() == FillapixCellType.UNKNOWN
+ && FillapixUtilities.isForcedBlack((FillapixBoard) node.getBoard(), cell)) {
+ cell.setCellType(FillapixCellType.BLACK);
+ fillapixBoard.addModifiedData(cell);
+ }
+ }
+ if (fillapixBoard.getModifiedData().isEmpty()) {
+ return null;
+ } else {
+ return fillapixBoard;
+ }
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteDirectRule.java
index 7e213a59c..6735fb8f4 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteDirectRule.java
@@ -1,63 +1,66 @@
-package edu.rpi.legup.puzzle.fillapix.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
-import edu.rpi.legup.puzzle.fillapix.FillapixCell;
-import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
-import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
-
-public class FinishWithWhiteDirectRule extends DirectRule {
- public FinishWithWhiteDirectRule() {
- super("FPIX-BASC-0002",
- "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");
- }
-
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- FillapixBoard board = (FillapixBoard) transition.getBoard();
- FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard();
- FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement);
- FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);
-
- if (!(parentCell.getType() == FillapixCellType.UNKNOWN && cell.getType() == FillapixCellType.WHITE)) {
- return super.getInvalidUseOfRuleMessage() + ": This cell must be white to be applicable with this rule";
- }
-
- if (FillapixUtilities.isForcedWhite(parentBoard, cell)) {
- return null;
- }
- else {
- return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be white";
- }
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- FillapixBoard fillapixBoard = (FillapixBoard) node.getBoard().copy();
- for (PuzzleElement element : fillapixBoard.getPuzzleElements()) {
- FillapixCell cell = (FillapixCell) element;
- if (cell.getType() == FillapixCellType.UNKNOWN && FillapixUtilities.isForcedWhite((FillapixBoard) node.getBoard(), cell)) {
- cell.setCellType(FillapixCellType.WHITE);
- fillapixBoard.addModifiedData(cell);
- }
- }
- if (fillapixBoard.getModifiedData().isEmpty()) {
- return null;
- }
- else {
- return fillapixBoard;
- }
- }
-}
\ No newline at end of file
+package edu.rpi.legup.puzzle.fillapix.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
+import edu.rpi.legup.puzzle.fillapix.FillapixCell;
+import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
+import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
+
+public class FinishWithWhiteDirectRule extends DirectRule {
+ public FinishWithWhiteDirectRule() {
+ super(
+ "FPIX-BASC-0002",
+ "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");
+ }
+
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ FillapixBoard board = (FillapixBoard) transition.getBoard();
+ FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard();
+ FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement);
+ FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);
+
+ if (!(parentCell.getType() == FillapixCellType.UNKNOWN
+ && cell.getType() == FillapixCellType.WHITE)) {
+ return super.getInvalidUseOfRuleMessage()
+ + ": This cell must be white to be applicable with this rule";
+ }
+
+ if (FillapixUtilities.isForcedWhite(parentBoard, cell)) {
+ return null;
+ } else {
+ return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be white";
+ }
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ FillapixBoard fillapixBoard = (FillapixBoard) node.getBoard().copy();
+ for (PuzzleElement element : fillapixBoard.getPuzzleElements()) {
+ FillapixCell cell = (FillapixCell) element;
+ if (cell.getType() == FillapixCellType.UNKNOWN
+ && FillapixUtilities.isForcedWhite((FillapixBoard) node.getBoard(), cell)) {
+ cell.setCellType(FillapixCellType.WHITE);
+ fillapixBoard.addModifiedData(cell);
+ }
+ }
+ if (fillapixBoard.getModifiedData().isEmpty()) {
+ return null;
+ } else {
+ return fillapixBoard;
+ }
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/MirrorDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/MirrorDirectRule.java
index 656cedb3f..e91931bd4 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/MirrorDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/MirrorDirectRule.java
@@ -1,103 +1,107 @@
-package edu.rpi.legup.puzzle.fillapix.rules;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.CaseRule;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
-import edu.rpi.legup.puzzle.fillapix.FillapixCell;
-import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
-import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
-
-public class MirrorDirectRule extends DirectRule {
- public MirrorDirectRule() {
- super("FPIX-BASC-0003",
- "Mirror",
- "Two adjacent clues with the same value must have the same number of black squares in their unshared regions",
- "edu/rpi/legup/images/fillapix/rules/Mirror.png");
- }
-
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- FillapixBoard board = (FillapixBoard) transition.getBoard();
- FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard().copy();
- FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement);
- FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);
-
- // cell has to have been empty before
- if (parentCell.getType() != FillapixCellType.UNKNOWN) {
- return super.getInvalidUseOfRuleMessage();
- }
-
- // parentBoard cannot have any contradictions
- if (FillapixUtilities.checkBoardForContradiction(parentBoard)) {
- return super.getInvalidUseOfRuleMessage();
- }
-
- // find all cells adjacent to cell that are numbered
- ArrayList adjCells = FillapixUtilities.getAdjacentCells(parentBoard, parentCell);
- ArrayList adjNums = new ArrayList();
- for (int i=0; i < adjCells.size(); i++) {
- if ((adjCells.get(i)).getNumber() >= 0 && adjCells.get(i).getNumber() < 10) {
- adjNums.add(adjCells.get(i));
- }
- }
- // the numbered cells must be next to another numbered cell of the same value
- Iterator itr = adjNums.iterator();
- while (itr.hasNext()) {
- FillapixCell adjNum = itr.next();
- adjCells = FillapixUtilities.getAdjacentCells(parentBoard, adjNum);
- boolean found = false;
- for (FillapixCell adjCell : adjCells) {
- if (adjCell.getNumber() == adjNum.getNumber() && adjCell.getIndex() != adjNum.getIndex()) {
- found = true;
- }
- }
- if (!found) {
- itr.remove();
- }
- }
-
- // change the color of the parentCell, and check if there exists a valid board
- if (cell.getType() == FillapixCellType.BLACK) {
- parentCell.setCellType(FillapixCellType.WHITE);
- }
- else {
- parentCell.setCellType(FillapixCellType.BLACK);
- }
- parentBoard.addModifiedData(parentCell);
- CaseRule completeClue = new SatisfyClueCaseRule();
- List caseBoards;
- for (FillapixCell adjNum : adjNums) {
- caseBoards = completeClue.getCases(parentBoard, adjNum);
- boolean found = true;
- for (Board b : caseBoards) {
- if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) {
- found = false;
- }
- }
- if (found) {
- return null;
- }
- }
-
- return super.getInvalidUseOfRuleMessage();
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
\ No newline at end of file
+package edu.rpi.legup.puzzle.fillapix.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.CaseRule;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
+import edu.rpi.legup.puzzle.fillapix.FillapixCell;
+import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
+import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class MirrorDirectRule extends DirectRule {
+ public MirrorDirectRule() {
+ super(
+ "FPIX-BASC-0003",
+ "Mirror",
+ "Two adjacent clues with the same value must have the same number of black squares"
+ + " in their unshared regions",
+ "edu/rpi/legup/images/fillapix/rules/Mirror.png");
+ }
+
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ FillapixBoard board = (FillapixBoard) transition.getBoard();
+ FillapixBoard parentBoard =
+ (FillapixBoard) transition.getParents().get(0).getBoard().copy();
+ FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement);
+ FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);
+
+ // cell has to have been empty before
+ if (parentCell.getType() != FillapixCellType.UNKNOWN) {
+ return super.getInvalidUseOfRuleMessage();
+ }
+
+ // parentBoard cannot have any contradictions
+ if (FillapixUtilities.checkBoardForContradiction(parentBoard)) {
+ return super.getInvalidUseOfRuleMessage();
+ }
+
+ // find all cells adjacent to cell that are numbered
+ ArrayList adjCells =
+ FillapixUtilities.getAdjacentCells(parentBoard, parentCell);
+ ArrayList adjNums = new ArrayList();
+ for (int i = 0; i < adjCells.size(); i++) {
+ if ((adjCells.get(i)).getNumber() >= 0 && adjCells.get(i).getNumber() < 10) {
+ adjNums.add(adjCells.get(i));
+ }
+ }
+ // the numbered cells must be next to another numbered cell of the same value
+ Iterator itr = adjNums.iterator();
+ while (itr.hasNext()) {
+ FillapixCell adjNum = itr.next();
+ adjCells = FillapixUtilities.getAdjacentCells(parentBoard, adjNum);
+ boolean found = false;
+ for (FillapixCell adjCell : adjCells) {
+ if (adjCell.getNumber() == adjNum.getNumber()
+ && adjCell.getIndex() != adjNum.getIndex()) {
+ found = true;
+ }
+ }
+ if (!found) {
+ itr.remove();
+ }
+ }
+
+ // change the color of the parentCell, and check if there exists a valid board
+ if (cell.getType() == FillapixCellType.BLACK) {
+ parentCell.setCellType(FillapixCellType.WHITE);
+ } else {
+ parentCell.setCellType(FillapixCellType.BLACK);
+ }
+ parentBoard.addModifiedData(parentCell);
+ CaseRule completeClue = new SatisfyClueCaseRule();
+ List caseBoards;
+ for (FillapixCell adjNum : adjNums) {
+ caseBoards = completeClue.getCases(parentBoard, adjNum);
+ boolean found = true;
+ for (Board b : caseBoards) {
+ if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) {
+ found = false;
+ }
+ }
+ if (found) {
+ return null;
+ }
+ }
+
+ return super.getInvalidUseOfRuleMessage();
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/NonTouchingSharedDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/NonTouchingSharedDirectRule.java
index fe94dbcb4..71a85a95b 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/NonTouchingSharedDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/NonTouchingSharedDirectRule.java
@@ -1,99 +1,103 @@
-package edu.rpi.legup.puzzle.fillapix.rules;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.CaseRule;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
-import edu.rpi.legup.puzzle.fillapix.FillapixCell;
-import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
-import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
-
-public class NonTouchingSharedDirectRule extends DirectRule {
- public NonTouchingSharedDirectRule() {
- super("FPIX-BASC-0005",
- "NonTouching Shared",
- "Clues with shared cells have the same difference in black cells in their unshared regions as the difference in their numbers",
- "edu/rpi/legup/images/fillapix/rules/TouchingSides.png");
- }
-
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- FillapixBoard board = (FillapixBoard) transition.getBoard();
- FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard().copy();
- FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement);
- FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);
-
- // cell has to have been empty before
- if (parentCell.getType() != FillapixCellType.UNKNOWN) {
- return super.getInvalidUseOfRuleMessage();
- }
-
- // parentBoard cannot have any contradictions
- if (FillapixUtilities.checkBoardForContradiction(parentBoard)) {
- return super.getInvalidUseOfRuleMessage();
- }
-
- // get all adjCells that have a number
- ArrayList adjCells = FillapixUtilities.getAdjacentCells(parentBoard, parentCell);
- adjCells.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10);
- /* remove any number cell that does not have another number cell not
- * touching, but sharing cells */
- Iterator itr = adjCells.iterator();
- while (itr.hasNext()) {
- ArrayList sharingCells = FillapixUtilities.getCellsAtDistance(parentBoard, parentCell, 1);
- boolean found = false;
- for (FillapixCell sharingCell : sharingCells) {
- if (sharingCell.getNumber() >= 0 && sharingCell.getNumber() < 10) {
- found = true;
- }
- }
- if (!found) {
- itr.remove();
- }
- }
-
- // change the cell to the opposite color
- if (cell.getType() == FillapixCellType.BLACK) {
- parentCell.setCellType(FillapixCellType.WHITE);
- }
- else {
- parentCell.setCellType(FillapixCellType.BLACK);
- }
- // check for some contradiction in all cases
- parentBoard.addModifiedData(parentCell);
- CaseRule completeClue = new SatisfyClueCaseRule();
- List caseBoards;
- for (FillapixCell adjCell : adjCells) {
- caseBoards = completeClue.getCases(parentBoard, adjCell);
- boolean found = true;
- for (Board b : caseBoards) {
- if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) {
- found = false;
- }
- }
- if (found) {
- return null;
- }
- }
-
- return super.getInvalidUseOfRuleMessage();
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
\ No newline at end of file
+package edu.rpi.legup.puzzle.fillapix.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.CaseRule;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
+import edu.rpi.legup.puzzle.fillapix.FillapixCell;
+import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
+import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class NonTouchingSharedDirectRule extends DirectRule {
+ public NonTouchingSharedDirectRule() {
+ super(
+ "FPIX-BASC-0005",
+ "NonTouching Shared",
+ "Clues with shared cells have the same difference in black cells in their unshared"
+ + " regions as the difference in their numbers",
+ "edu/rpi/legup/images/fillapix/rules/TouchingSides.png");
+ }
+
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ FillapixBoard board = (FillapixBoard) transition.getBoard();
+ FillapixBoard parentBoard =
+ (FillapixBoard) transition.getParents().get(0).getBoard().copy();
+ FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement);
+ FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);
+
+ // cell has to have been empty before
+ if (parentCell.getType() != FillapixCellType.UNKNOWN) {
+ return super.getInvalidUseOfRuleMessage();
+ }
+
+ // parentBoard cannot have any contradictions
+ if (FillapixUtilities.checkBoardForContradiction(parentBoard)) {
+ return super.getInvalidUseOfRuleMessage();
+ }
+
+ // get all adjCells that have a number
+ ArrayList adjCells =
+ FillapixUtilities.getAdjacentCells(parentBoard, parentCell);
+ adjCells.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10);
+ /* remove any number cell that does not have another number cell not
+ * touching, but sharing cells */
+ Iterator itr = adjCells.iterator();
+ while (itr.hasNext()) {
+ ArrayList sharingCells =
+ FillapixUtilities.getCellsAtDistance(parentBoard, parentCell, 1);
+ boolean found = false;
+ for (FillapixCell sharingCell : sharingCells) {
+ if (sharingCell.getNumber() >= 0 && sharingCell.getNumber() < 10) {
+ found = true;
+ }
+ }
+ if (!found) {
+ itr.remove();
+ }
+ }
+
+ // change the cell to the opposite color
+ if (cell.getType() == FillapixCellType.BLACK) {
+ parentCell.setCellType(FillapixCellType.WHITE);
+ } else {
+ parentCell.setCellType(FillapixCellType.BLACK);
+ }
+ // check for some contradiction in all cases
+ parentBoard.addModifiedData(parentCell);
+ CaseRule completeClue = new SatisfyClueCaseRule();
+ List caseBoards;
+ for (FillapixCell adjCell : adjCells) {
+ caseBoards = completeClue.getCases(parentBoard, adjCell);
+ boolean found = true;
+ for (Board b : caseBoards) {
+ if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) {
+ found = false;
+ }
+ }
+ if (found) {
+ return null;
+ }
+ }
+
+ return super.getInvalidUseOfRuleMessage();
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/SatisfyClueCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/SatisfyClueCaseRule.java
index 4520add31..7db833f76 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/SatisfyClueCaseRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/SatisfyClueCaseRule.java
@@ -1,12 +1,5 @@
package edu.rpi.legup.puzzle.fillapix.rules;
-import java.awt.Point;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.CaseBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;
@@ -17,13 +10,20 @@
import edu.rpi.legup.puzzle.fillapix.FillapixCell;
import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
+import java.awt.Point;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
public class SatisfyClueCaseRule extends CaseRule {
public SatisfyClueCaseRule() {
- super("FPIX-CASE-0002",
- "Satisfy Clue",
- "Each clue must touch that number of squares.",
- "edu/rpi/legup/images/fillapix/cases/SatisfyClue.png");
+ super(
+ "FPIX-CASE-0002",
+ "Satisfy Clue",
+ "Each clue must touch that number of squares.",
+ "edu/rpi/legup/images/fillapix/cases/SatisfyClue.png");
}
@Override
@@ -33,7 +33,9 @@ public CaseBoard getCaseBoard(Board board) {
fillapixBoard.setModifiable(false);
for (PuzzleElement data : fillapixBoard.getPuzzleElements()) {
FillapixCell cell = (FillapixCell) data;
- if (cell.getNumber() >= 0 && cell.getNumber() <= 9 && FillapixUtilities.hasEmptyAdjacent(fillapixBoard, cell)) {
+ if (cell.getNumber() >= 0
+ && cell.getNumber() <= 9
+ && FillapixUtilities.hasEmptyAdjacent(fillapixBoard, cell)) {
caseBoard.addPickableElement(data);
}
}
@@ -70,26 +72,25 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) {
if (cellNumBlack > cellMaxBlack || cellNumEmpty == 0) {
return cases;
}
-
+
// generate all cases as boolean expressions
ArrayList combinations;
combinations = FillapixUtilities.getCombinations(cellMaxBlack - cellNumBlack, cellNumEmpty);
- for (int i=0; i < combinations.size(); i++) {
+ for (int i = 0; i < combinations.size(); i++) {
Board case_ = board.copy();
- for (int j=0; j < combinations.get(i).length; j++) {
+ for (int j = 0; j < combinations.get(i).length; j++) {
cell = (FillapixCell) case_.getPuzzleElement(emptyCells.get(j));
if (combinations.get(i)[j]) {
cell.setCellType(FillapixCellType.BLACK);
- }
- else {
+ } else {
cell.setCellType(FillapixCellType.WHITE);
}
case_.addModifiedData(cell);
}
cases.add(case_);
}
-
+
return cases;
}
@@ -99,26 +100,24 @@ public String checkRuleRaw(TreeTransition transition) {
List childTransitions = parent.getChildren();
/*
- * In order for the transition to be valid, it can only be applied to
+ * In order for the transition to be valid, it can only be applied to
* one cell, thus:
* * there must be modified cells
* * all modified cells must share at least one common adjacent
* cell
* * all modified cells must fit within a 3X3 square
- * * the center of one of the possible squaress must be a cell
+ * * the center of one of the possible squaress must be a cell
* with a number
* * that cells possible combinations must match the transitions
* If all the above is verified, then the transition is valid
*/
-
/* ensure there are modified cells */
Set modCells = transition.getBoard().getModifiedData();
if (modCells.size() <= 0) {
return super.getInvalidUseOfRuleMessage();
}
-
/* ensure modified cells occur within a 3X3 square */
int minVertLoc = Integer.MAX_VALUE, maxVertLoc = Integer.MIN_VALUE;
int minHorzLoc = Integer.MAX_VALUE, maxHorzLoc = Integer.MIN_VALUE;
@@ -141,14 +140,16 @@ public String checkRuleRaw(TreeTransition transition) {
return super.getInvalidUseOfRuleMessage();
}
-
- /* get the center of all possible 3X3 squares,
+ /* get the center of all possible 3X3 squares,
* and collect all that have numbers */
FillapixBoard board = (FillapixBoard) transition.getParents().get(0).getBoard();
Set possibleCenters = new TreeSet();
- possibleCenters.addAll(FillapixUtilities.getAdjacentCells(board, (FillapixCell) modCells.iterator().next()));
+ possibleCenters.addAll(
+ FillapixUtilities.getAdjacentCells(
+ board, (FillapixCell) modCells.iterator().next()));
for (PuzzleElement modCell : modCells) {
- possibleCenters.retainAll((FillapixUtilities.getAdjacentCells(board, (FillapixCell) modCell)));
+ possibleCenters.retainAll(
+ (FillapixUtilities.getAdjacentCells(board, (FillapixCell) modCell)));
}
// removing all elements without a valid number
possibleCenters.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10);
@@ -156,7 +157,6 @@ public String checkRuleRaw(TreeTransition transition) {
return super.getInvalidUseOfRuleMessage();
}
-
/* Now go through the remaining centers, and check if their combinations
* match the transitions */
for (FillapixCell possibleCenter : possibleCenters) {
@@ -176,7 +176,8 @@ public String checkRuleRaw(TreeTransition transition) {
continue;
}
- ArrayList combinations = FillapixUtilities.getCombinations(maxBlack - numBlack, numEmpty);
+ ArrayList combinations =
+ FillapixUtilities.getCombinations(maxBlack - numBlack, numEmpty);
if (combinations.size() != childTransitions.size()) {
// not this center because combinations do not match transitions
continue;
@@ -192,11 +193,10 @@ public String checkRuleRaw(TreeTransition transition) {
}
boolean[] translatedModCells = new boolean[transModCells.size()];
- for (int i=0; i < transModCells.size(); i++) {
+ for (int i = 0; i < transModCells.size(); i++) {
if (transModCells.get(i).getType() == FillapixCellType.BLACK) {
translatedModCells[i] = true;
- }
- else {
+ } else {
translatedModCells[i] = false;
}
}
@@ -226,9 +226,8 @@ public String checkRuleRaw(TreeTransition transition) {
return super.getInvalidUseOfRuleMessage();
}
-
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
return null;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooFewBlackCellsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooFewBlackCellsContradictionRule.java
index c37050978..df5954d63 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooFewBlackCellsContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooFewBlackCellsContradictionRule.java
@@ -7,25 +7,26 @@
import edu.rpi.legup.puzzle.fillapix.FillapixCell;
import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
-
import java.util.ArrayList;
public class TooFewBlackCellsContradictionRule extends ContradictionRule {
public TooFewBlackCellsContradictionRule() {
- super("FPIX-CONT-0001",
+ 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");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooManyBlackCellsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooManyBlackCellsContradictionRule.java
index 68395ce7f..38b47c972 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooManyBlackCellsContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooManyBlackCellsContradictionRule.java
@@ -7,25 +7,26 @@
import edu.rpi.legup.puzzle.fillapix.FillapixCell;
import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
-
import java.util.ArrayList;
public class TooManyBlackCellsContradictionRule extends ContradictionRule {
public TooManyBlackCellsContradictionRule() {
- super("FPIX-CONT-0002",
+ super(
+ "FPIX-CONT-0002",
"Too Many Black Cells",
"There may not be more black cells than the number",
"edu/rpi/legup/images/fillapix/contradictions/TooManyBlackCells.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
@@ -45,8 +46,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
}
if (numBlack > cellNum) {
return null;
- }
-
+ }
+
return super.getNoContradictionMessage();
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingCornersDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingCornersDirectRule.java
index 6f4be7842..72e2def47 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingCornersDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingCornersDirectRule.java
@@ -1,108 +1,113 @@
-package edu.rpi.legup.puzzle.fillapix.rules;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.CaseRule;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
-import edu.rpi.legup.puzzle.fillapix.FillapixCell;
-import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
-import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
-
-public class TouchingCornersDirectRule extends DirectRule {
- public TouchingCornersDirectRule() {
- super("FPIX-BASC-0005",
- "Touching Corners",
- "Clues with touching corners have the same difference in black cells in their unshared regions as the difference in their numbers",
- "edu/rpi/legup/images/fillapix/rules/TouchingCorners.png");
- }
-
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- FillapixBoard board = (FillapixBoard) transition.getBoard();
- FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard().copy();
- FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement);
- FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);
-
- // cell has to have been empty before
- if (parentCell.getType() != FillapixCellType.UNKNOWN) {
- return super.getInvalidUseOfRuleMessage();
- }
-
- // parentBoard cannot have any contradictions
- if (FillapixUtilities.checkBoardForContradiction(parentBoard)) {
- return super.getInvalidUseOfRuleMessage();
- }
-
- // get all adjCells that have a number
- ArrayList adjCells = FillapixUtilities.getAdjacentCells(parentBoard, parentCell);
- adjCells.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10);
- /* remove any number cell that does not have another number cell diagonally
- * adjacent to it on the opposite side of the modified cell */
- Iterator itr = adjCells.iterator();
- while (itr.hasNext()) {
- FillapixCell adjCell = itr.next();
-
- boolean found = false;
- ArrayList adjAdjCells = FillapixUtilities.getAdjacentCells(parentBoard, adjCell);
- for (FillapixCell adjAdjCell : adjAdjCells) {
- if (adjAdjCell.getLocation().x != adjCell.getLocation().x &&
- adjAdjCell.getLocation().y != adjCell.getLocation().y &&
- adjAdjCell.getNumber() >= 0 && adjAdjCell.getNumber() < 10 &&
- adjAdjCell.getIndex() != parentCell.getIndex()) {
- // adjAdjCell is diagonally adjacent to adjCell && it has a
- // number && it is not parentCell
- found = true;
- }
- }
-
- // does not qualify for this rule
- if (!found) {
- itr.remove();
- }
- }
-
- // change the cell to the opposite color
- if (cell.getType() == FillapixCellType.BLACK) {
- parentCell.setCellType(FillapixCellType.WHITE);
- }
- else {
- parentCell.setCellType(FillapixCellType.BLACK);
- }
- // check for some contradiction in all cases
- parentBoard.addModifiedData(parentCell);
- CaseRule completeClue = new SatisfyClueCaseRule();
- List caseBoards;
- for (FillapixCell adjCell : adjCells) {
- caseBoards = completeClue.getCases(parentBoard, adjCell);
- boolean found = true;
- for (Board b : caseBoards) {
- if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) {
- found = false;
- }
- }
- if (found) {
- return null;
- }
- }
-
- return super.getInvalidUseOfRuleMessage();
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
\ No newline at end of file
+package edu.rpi.legup.puzzle.fillapix.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.CaseRule;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
+import edu.rpi.legup.puzzle.fillapix.FillapixCell;
+import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
+import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class TouchingCornersDirectRule extends DirectRule {
+ public TouchingCornersDirectRule() {
+ super(
+ "FPIX-BASC-0005",
+ "Touching Corners",
+ "Clues with touching corners have the same difference in black cells in their"
+ + " unshared regions as the difference in their numbers",
+ "edu/rpi/legup/images/fillapix/rules/TouchingCorners.png");
+ }
+
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ FillapixBoard board = (FillapixBoard) transition.getBoard();
+ FillapixBoard parentBoard =
+ (FillapixBoard) transition.getParents().get(0).getBoard().copy();
+ FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement);
+ FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);
+
+ // cell has to have been empty before
+ if (parentCell.getType() != FillapixCellType.UNKNOWN) {
+ return super.getInvalidUseOfRuleMessage();
+ }
+
+ // parentBoard cannot have any contradictions
+ if (FillapixUtilities.checkBoardForContradiction(parentBoard)) {
+ return super.getInvalidUseOfRuleMessage();
+ }
+
+ // get all adjCells that have a number
+ ArrayList adjCells =
+ FillapixUtilities.getAdjacentCells(parentBoard, parentCell);
+ adjCells.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10);
+ /* remove any number cell that does not have another number cell diagonally
+ * adjacent to it on the opposite side of the modified cell */
+ Iterator itr = adjCells.iterator();
+ while (itr.hasNext()) {
+ FillapixCell adjCell = itr.next();
+
+ boolean found = false;
+ ArrayList adjAdjCells =
+ FillapixUtilities.getAdjacentCells(parentBoard, adjCell);
+ for (FillapixCell adjAdjCell : adjAdjCells) {
+ if (adjAdjCell.getLocation().x != adjCell.getLocation().x
+ && adjAdjCell.getLocation().y != adjCell.getLocation().y
+ && adjAdjCell.getNumber() >= 0
+ && adjAdjCell.getNumber() < 10
+ && adjAdjCell.getIndex() != parentCell.getIndex()) {
+ // adjAdjCell is diagonally adjacent to adjCell && it has a
+ // number && it is not parentCell
+ found = true;
+ }
+ }
+
+ // does not qualify for this rule
+ if (!found) {
+ itr.remove();
+ }
+ }
+
+ // change the cell to the opposite color
+ if (cell.getType() == FillapixCellType.BLACK) {
+ parentCell.setCellType(FillapixCellType.WHITE);
+ } else {
+ parentCell.setCellType(FillapixCellType.BLACK);
+ }
+ // check for some contradiction in all cases
+ parentBoard.addModifiedData(parentCell);
+ CaseRule completeClue = new SatisfyClueCaseRule();
+ List caseBoards;
+ for (FillapixCell adjCell : adjCells) {
+ caseBoards = completeClue.getCases(parentBoard, adjCell);
+ boolean found = true;
+ for (Board b : caseBoards) {
+ if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) {
+ found = false;
+ }
+ }
+ if (found) {
+ return null;
+ }
+ }
+
+ return super.getInvalidUseOfRuleMessage();
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingSidesDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingSidesDirectRule.java
index bd6dd0169..281dd5392 100644
--- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingSidesDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingSidesDirectRule.java
@@ -1,115 +1,126 @@
-package edu.rpi.legup.puzzle.fillapix.rules;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.CaseRule;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
-import edu.rpi.legup.puzzle.fillapix.FillapixCell;
-import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
-import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
-
-public class TouchingSidesDirectRule extends DirectRule {
- public TouchingSidesDirectRule() {
- super("FPIX-BASC-0004",
- "Touching Sides",
- "Clues with touching sides have the same difference in black cells in their unshared regions as the difference in their numbers",
- "edu/rpi/legup/images/fillapix/rules/TouchingSides.png");
- }
-
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- FillapixBoard board = (FillapixBoard) transition.getBoard();
- FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard().copy();
- FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement);
- FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);
-
- // cell has to have been empty before
- if (parentCell.getType() != FillapixCellType.UNKNOWN) {
- return super.getInvalidUseOfRuleMessage();
- }
-
- // parentBoard cannot have any contradictions
- if (FillapixUtilities.checkBoardForContradiction(parentBoard)) {
- return super.getInvalidUseOfRuleMessage();
- }
-
- // get all adjCells that have a number
- ArrayList adjCells = FillapixUtilities.getAdjacentCells(parentBoard, parentCell);
- adjCells.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10);
- /* remove any number cell that does not have another number cell adjacent
- * to it on the opposite side of the modified cell */
- Iterator itr = adjCells.iterator();
- while (itr.hasNext()) {
- // calculate x and y offset of adjCell from cell
- FillapixCell adjCell = itr.next();
- int xOffset = adjCell.getLocation().x - cell.getLocation().x;
- int yOffset = adjCell.getLocation().y - cell.getLocation().y;
-
- boolean found = false;
- // check vertically for numbered cell in opposite direction of cell
- if (adjCell.getLocation().x + xOffset >= 0 && adjCell.getLocation().x < parentBoard.getWidth()) {
- int adjNum = parentBoard.getCell(adjCell.getLocation().x + xOffset, adjCell.getLocation().y).getNumber();
- if (adjNum >= 0 && adjNum < 10) {
- found = true;
- }
- }
- // check horizontally for numbered cell in opposite direction of cell
- if (adjCell.getLocation().y + yOffset >= 0 && adjCell.getLocation().y < parentBoard.getHeight()) {
- int adjNum = parentBoard.getCell(adjCell.getLocation().x, adjCell.getLocation().y + yOffset).getNumber();
- if (adjNum >= 0 && adjNum < 10) {
- found = true;
- }
- }
-
- // if no horizontally or vertically adjacent cell on opposite side of 'cell' has number,
- // then adjCell is not valid, so should be removed
- if (!found) {
- itr.remove();
- }
- }
-
- // change the cell to the opposite color
- if (cell.getType() == FillapixCellType.BLACK) {
- parentCell.setCellType(FillapixCellType.WHITE);
- }
- else {
- parentCell.setCellType(FillapixCellType.BLACK);
- }
- // check for some contradiction in all cases
- parentBoard.addModifiedData(parentCell);
- CaseRule completeClue = new SatisfyClueCaseRule();
- List caseBoards;
- for (FillapixCell adjCell : adjCells) {
- caseBoards = completeClue.getCases(parentBoard, adjCell);
- boolean found = true;
- for (Board b : caseBoards) {
- if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) {
- found = false;
- }
- }
- if (found) {
- return null;
- }
- }
-
- return super.getInvalidUseOfRuleMessage();
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
\ No newline at end of file
+package edu.rpi.legup.puzzle.fillapix.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.CaseRule;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
+import edu.rpi.legup.puzzle.fillapix.FillapixCell;
+import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
+import edu.rpi.legup.puzzle.fillapix.FillapixUtilities;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class TouchingSidesDirectRule extends DirectRule {
+ public TouchingSidesDirectRule() {
+ super(
+ "FPIX-BASC-0004",
+ "Touching Sides",
+ "Clues with touching sides have the same difference in black cells in their"
+ + " unshared regions as the difference in their numbers",
+ "edu/rpi/legup/images/fillapix/rules/TouchingSides.png");
+ }
+
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ FillapixBoard board = (FillapixBoard) transition.getBoard();
+ FillapixBoard parentBoard =
+ (FillapixBoard) transition.getParents().get(0).getBoard().copy();
+ FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement);
+ FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);
+
+ // cell has to have been empty before
+ if (parentCell.getType() != FillapixCellType.UNKNOWN) {
+ return super.getInvalidUseOfRuleMessage();
+ }
+
+ // parentBoard cannot have any contradictions
+ if (FillapixUtilities.checkBoardForContradiction(parentBoard)) {
+ return super.getInvalidUseOfRuleMessage();
+ }
+
+ // get all adjCells that have a number
+ ArrayList adjCells =
+ FillapixUtilities.getAdjacentCells(parentBoard, parentCell);
+ adjCells.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10);
+ /* remove any number cell that does not have another number cell adjacent
+ * to it on the opposite side of the modified cell */
+ Iterator itr = adjCells.iterator();
+ while (itr.hasNext()) {
+ // calculate x and y offset of adjCell from cell
+ FillapixCell adjCell = itr.next();
+ int xOffset = adjCell.getLocation().x - cell.getLocation().x;
+ int yOffset = adjCell.getLocation().y - cell.getLocation().y;
+
+ boolean found = false;
+ // check vertically for numbered cell in opposite direction of cell
+ if (adjCell.getLocation().x + xOffset >= 0
+ && adjCell.getLocation().x < parentBoard.getWidth()) {
+ int adjNum =
+ parentBoard
+ .getCell(adjCell.getLocation().x + xOffset, adjCell.getLocation().y)
+ .getNumber();
+ if (adjNum >= 0 && adjNum < 10) {
+ found = true;
+ }
+ }
+ // check horizontally for numbered cell in opposite direction of cell
+ if (adjCell.getLocation().y + yOffset >= 0
+ && adjCell.getLocation().y < parentBoard.getHeight()) {
+ int adjNum =
+ parentBoard
+ .getCell(adjCell.getLocation().x, adjCell.getLocation().y + yOffset)
+ .getNumber();
+ if (adjNum >= 0 && adjNum < 10) {
+ found = true;
+ }
+ }
+
+ // if no horizontally or vertically adjacent cell on opposite side of 'cell' has number,
+ // then adjCell is not valid, so should be removed
+ if (!found) {
+ itr.remove();
+ }
+ }
+
+ // change the cell to the opposite color
+ if (cell.getType() == FillapixCellType.BLACK) {
+ parentCell.setCellType(FillapixCellType.WHITE);
+ } else {
+ parentCell.setCellType(FillapixCellType.BLACK);
+ }
+ // check for some contradiction in all cases
+ parentBoard.addModifiedData(parentCell);
+ CaseRule completeClue = new SatisfyClueCaseRule();
+ List caseBoards;
+ for (FillapixCell adjCell : adjCells) {
+ caseBoards = completeClue.getCases(parentBoard, adjCell);
+ boolean found = true;
+ for (Board b : caseBoards) {
+ if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) {
+ found = false;
+ }
+ }
+ if (found) {
+ return null;
+ }
+ }
+
+ return super.getInvalidUseOfRuleMessage();
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/Heyawake.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/Heyawake.java
index fc52a6fff..afe3dd652 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/Heyawake.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/Heyawake.java
@@ -16,9 +16,7 @@ public Heyawake() {
this.importer = new HeyawakeImporter(this);
}
- /**
- * Initializes the view. Called by the invoker of the class
- */
+ /** Initializes the view. Called by the invoker of the class */
@Override
public void initializeView() {
boardView = new HeyawakeView((HeyawakeBoard) currentBoard);
@@ -39,8 +37,8 @@ public Board generatePuzzle(int difficulty) {
/**
* Determines if the given dimensions are valid for HeyAwake
*
- * @param rows the number of rows
- * @param columns the number of columns
+ * @param rows the number of rows
+ * @param columns the number of columns
* @return true if the given dimensions are valid for HeyAwake, false otherwise
*/
public boolean isValidDimensions(int rows, int columns) {
@@ -65,7 +63,5 @@ public boolean isBoardComplete(Board board) {
* @param board the board that has changed
*/
@Override
- public void onBoardChange(Board board) {
-
- }
+ public void onBoardChange(Board board) {}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeBoard.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeBoard.java
index 2f15213ec..cedb3a91b 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeBoard.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeBoard.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.gameboard.GridBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeCell.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeCell.java
index ce8c73424..480e2e39b 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeCell.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeCell.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.puzzle.heyawake;
import edu.rpi.legup.model.gameboard.GridCell;
-
import java.awt.*;
public class HeyawakeCell extends GridCell {
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeController.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeController.java
index 2bad91933..2d081d7da 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeController.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeController.java
@@ -2,5 +2,4 @@
import edu.rpi.legup.controller.ElementController;
-public class HeyawakeController extends ElementController {
-}
+public class HeyawakeController extends ElementController {}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeElementView.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeElementView.java
index 5efec44ff..d30159856 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeElementView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeElementView.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.puzzle.heyawake;
import edu.rpi.legup.ui.boardview.GridElementView;
-
import java.awt.*;
public class HeyawakeElementView extends GridElementView {
@@ -39,7 +38,8 @@ public void drawElement(Graphics2D graphics2D) {
FontMetrics metrics = graphics2D.getFontMetrics(FONT);
String value = String.valueOf(puzzleElement.getData());
int xText = location.x + (size.width - metrics.stringWidth(value)) / 2;
- int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent();
+ int yText =
+ location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent();
graphics2D.drawString(String.valueOf(puzzleElement.getData()), xText, yText);
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java
index 344a0be92..4470d77be 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.PuzzleExporter;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard;
import org.w3c.dom.Document;
public class HeyawakeExporter extends PuzzleExporter {
@@ -16,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
HeyawakeBoard board;
if (puzzle.getTree() != null) {
board = (HeyawakeBoard) puzzle.getTree().getRootNode().getBoard();
- }
- else {
+ } else {
board = (HeyawakeBoard) puzzle.getBoardView().getBoard();
}
@@ -29,7 +27,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
for (PuzzleElement puzzleElement : board.getPuzzleElements()) {
HeyawakeCell cell = (HeyawakeCell) puzzleElement;
if (cell.getData() != -2) {
- org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement);
+ org.w3c.dom.Element cellElement =
+ puzzle.getFactory().exportCell(newDocument, puzzleElement);
cellsElement.appendChild(cellElement);
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java
index 96fc20e6f..8ecf24135 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java
@@ -4,17 +4,16 @@
import edu.rpi.legup.model.gameboard.ElementFactory;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.awt.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import java.awt.*;
-
public class HeyawakeFactory extends ElementFactory {
/**
* Creates a puzzleElement based on the xml document Node and adds it to the board
*
- * @param node node that represents the puzzleElement
+ * @param node node that represents the puzzleElement
* @param board board to add the newly created cell
* @return newly created cell from the xml document Node
* @throws InvalidFileFormatException if file is invalid
@@ -23,7 +22,8 @@ public class HeyawakeFactory extends ElementFactory {
public HeyawakeCell importCell(Node node, Board board) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("cell")) {
- throw new InvalidFileFormatException("Heyawake Factory: unknown puzzleElement puzzleElement");
+ throw new InvalidFileFormatException(
+ "Heyawake Factory: unknown puzzleElement puzzleElement");
}
HeyawakeBoard heyawakeBoard = (HeyawakeBoard) board;
@@ -36,7 +36,8 @@ public HeyawakeCell importCell(Node node, Board board) throws InvalidFileFormatE
int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue());
int regionIndex = Integer.valueOf(attributeList.getNamedItem("region").getNodeValue());
if (x >= width || y >= height) {
- throw new InvalidFileFormatException("Heyawake Factory: cell location out of bounds");
+ throw new InvalidFileFormatException(
+ "Heyawake Factory: cell location out of bounds");
}
if (value < -4 || value > 4) {
throw new InvalidFileFormatException("Heyawake Factory: cell unknown value");
@@ -46,11 +47,10 @@ public HeyawakeCell importCell(Node node, Board board) throws InvalidFileFormatE
cell.setIndex(y * height + x);
heyawakeBoard.getRegions();
return cell;
- }
- catch (NumberFormatException e) {
- throw new InvalidFileFormatException("Heyawake Factory: unknown value where integer expected");
- }
- catch (NullPointerException e) {
+ } catch (NumberFormatException e) {
+ throw new InvalidFileFormatException(
+ "Heyawake Factory: unknown value where integer expected");
+ } catch (NullPointerException e) {
throw new InvalidFileFormatException("Heyawake Factory: could not find attribute(s)");
}
}
@@ -58,7 +58,7 @@ public HeyawakeCell importCell(Node node, Board board) throws InvalidFileFormatE
/**
* Creates a xml document puzzleElement from a cell for exporting
*
- * @param document xml document
+ * @param document xml document
* @param puzzleElement PuzzleElement cell
* @return xml PuzzleElement
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java
index 7527c717f..6bbabd54d 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java
@@ -2,12 +2,11 @@
import edu.rpi.legup.model.PuzzleImporter;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.awt.*;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import java.awt.*;
-
public class HeyawakeImporter extends PuzzleImporter {
public HeyawakeImporter(Heyawake heyawake) {
@@ -27,14 +26,12 @@ public boolean acceptsTextInput() {
/**
* Creates an empty board for building
*
- * @param rows the number of rows on the board
+ * @param rows the number of rows on the board
* @param columns the number of columns on the board
* @throws RuntimeException if board can not be created
*/
@Override
- public void initializeBoard(int rows, int columns) {
-
- }
+ public void initializeBoard(int rows, int columns) {}
/**
* Creates the board for building
@@ -46,11 +43,13 @@ public void initializeBoard(int rows, int columns) {
public void initializeBoard(Node node) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("board")) {
- throw new InvalidFileFormatException("Heyawake Importer: cannot find board puzzleElement");
+ throw new InvalidFileFormatException(
+ "Heyawake Importer: cannot find board puzzleElement");
}
Element boardElement = (Element) node;
if (boardElement.getElementsByTagName("cells").getLength() == 0) {
- throw new InvalidFileFormatException("Heyawake Importer: no puzzleElement found for board");
+ throw new InvalidFileFormatException(
+ "Heyawake Importer: no puzzleElement found for board");
}
Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0);
NodeList elementDataList = dataElement.getElementsByTagName("cell");
@@ -59,9 +58,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
if (!boardElement.getAttribute("size").isEmpty()) {
int size = Integer.valueOf(boardElement.getAttribute("size"));
heyawakeBoard = new HeyawakeBoard(size);
- }
- else {
- if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) {
+ } else {
+ if (!boardElement.getAttribute("width").isEmpty()
+ && !boardElement.getAttribute("height").isEmpty()) {
int width = Integer.valueOf(boardElement.getAttribute("width"));
int height = Integer.valueOf(boardElement.getAttribute("height"));
heyawakeBoard = new HeyawakeBoard(width, height);
@@ -76,7 +75,10 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
int height = heyawakeBoard.getHeight();
for (int i = 0; i < elementDataList.getLength(); i++) {
- HeyawakeCell cell = (HeyawakeCell) puzzle.getFactory().importCell(elementDataList.item(i), heyawakeBoard);
+ HeyawakeCell cell =
+ (HeyawakeCell)
+ puzzle.getFactory()
+ .importCell(elementDataList.item(i), heyawakeBoard);
Point loc = cell.getLocation();
if (cell.getData() != -2) {
cell.setModifiable(false);
@@ -96,9 +98,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
}
}
puzzle.setCurrentBoard(heyawakeBoard);
- }
- catch (NumberFormatException e) {
- throw new InvalidFileFormatException("Heyawake Importer: unknown value where integer expected");
+ } catch (NumberFormatException e) {
+ throw new InvalidFileFormatException(
+ "Heyawake Importer: unknown value where integer expected");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeView.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeView.java
index 00506df0f..fba5f0eb7 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeView.java
@@ -4,7 +4,6 @@
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.ui.boardview.ElementView;
import edu.rpi.legup.ui.boardview.GridBoardView;
-
import java.awt.*;
import java.awt.geom.Area;
import java.util.HashMap;
@@ -25,14 +24,14 @@ public HeyawakeView(HeyawakeBoard board) {
HeyawakeElementView elementView = new HeyawakeElementView(cell);
elementView.setIndex(cell.getIndex());
elementView.setSize(elementSize);
- elementView.setLocation(new Point(loc.x * elementSize.width, loc.y * elementSize.height));
+ elementView.setLocation(
+ new Point(loc.x * elementSize.width, loc.y * elementSize.height));
elementViews.add(elementView);
int regionIndex = cell.getRegionIndex();
if (regionsBoundaries.get(regionIndex) == null) {
regionsBoundaries.put(regionIndex, new Area(elementView.getBounds()));
- }
- else {
+ } else {
regionsBoundaries.get(regionIndex).add(new Area(elementView.getBounds()));
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/AdjacentBlacksContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/AdjacentBlacksContradictionRule.java
index d2eceb7a1..88d293f5e 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/AdjacentBlacksContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/AdjacentBlacksContradictionRule.java
@@ -7,18 +7,21 @@
public class AdjacentBlacksContradictionRule extends ContradictionRule {
public AdjacentBlacksContradictionRule() {
- super("HEYA-CONT-0001", "Adjacent Blacks",
+ super(
+ "HEYA-CONT-0001",
+ "Adjacent Blacks",
"",
"edu/rpi/legup/images/heyawake/contradictions/adjacentBlacks.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackOrWhiteCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackOrWhiteCaseRule.java
index 0e7552dd2..251be46ee 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackOrWhiteCaseRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackOrWhiteCaseRule.java
@@ -5,21 +5,21 @@
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.tree.TreeTransition;
-
import java.util.List;
public class BlackOrWhiteCaseRule extends CaseRule {
public BlackOrWhiteCaseRule() {
- super("HEYA-CASE-0001",
+ super(
+ "HEYA-CASE-0001",
"Black or White",
"",
"edu/rpi/legup/images/heyawake/cases/BlackOrWhite.png");
}
/**
- * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is
- * the one that should overridden in child classes.
+ * Checks whether the {@link TreeTransition} logically follows from the parent node using this
+ * rule. This method is the one that should overridden in child classes.
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
@@ -30,13 +30,14 @@ public String checkRuleRaw(TreeTransition transition) {
}
/**
- * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using
- * this rule. This method is the one that should overridden in child classes.
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule. This method is the one that should overridden in child
+ * classes.
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
@@ -44,7 +45,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
}
/**
- * Gets the case board that indicates where this case rule can be applied on the given {@link Board}.
+ * Gets the case board that indicates where this case rule can be applied on the given {@link
+ * Board}.
*
* @param board board to find locations where this case rule can be applied
* @return a case board
@@ -55,9 +57,10 @@ public CaseBoard getCaseBoard(Board board) {
}
/**
- * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule.
+ * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on
+ * this case rule.
*
- * @param board the current board state
+ * @param board the current board state
* @param puzzleElement equivalent puzzleElement
* @return a list of elements the specified could be
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackPathDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackPathDirectRule.java
index 474bdccdd..1fc3d0776 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackPathDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackPathDirectRule.java
@@ -1,7 +1,7 @@
-package edu.rpi.legup.puzzle.heyawake.rules;
-
-public class BlackPathDirectRule {
- public BlackPathDirectRule() {
- throw new RuntimeException("This rule has not been implemented");
- }
-}
+package edu.rpi.legup.puzzle.heyawake.rules;
+
+public class BlackPathDirectRule {
+ public BlackPathDirectRule() {
+ throw new RuntimeException("This rule has not been implemented");
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BottleNeckDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BottleNeckDirectRule.java
index f2e7fef5c..41d950378 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BottleNeckDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BottleNeckDirectRule.java
@@ -1,7 +1,7 @@
-package edu.rpi.legup.puzzle.heyawake.rules;
-
-public class BottleNeckDirectRule {
- public BottleNeckDirectRule() {
- throw new RuntimeException("This rule has not been implemented");
- }
-}
+package edu.rpi.legup.puzzle.heyawake.rules;
+
+public class BottleNeckDirectRule {
+ public BottleNeckDirectRule() {
+ throw new RuntimeException("This rule has not been implemented");
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomBlackDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomBlackDirectRule.java
index 828739160..aee1ae4bf 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomBlackDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomBlackDirectRule.java
@@ -1,43 +1,45 @@
-package edu.rpi.legup.puzzle.heyawake.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class FillRoomBlackDirectRule extends DirectRule {
-
- public FillRoomBlackDirectRule() {
- super("HEYA-BASC-0003",
- "Fill Room Black",
- "",
- "edu/rpi/legup/images/heyawake/rules/FillRoomBlack.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.heyawake.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class FillRoomBlackDirectRule extends DirectRule {
+
+ public FillRoomBlackDirectRule() {
+ super(
+ "HEYA-BASC-0003",
+ "Fill Room Black",
+ "",
+ "edu/rpi/legup/images/heyawake/rules/FillRoomBlack.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomWhiteDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomWhiteDirectRule.java
index 6b1a11c29..c4609b239 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomWhiteDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomWhiteDirectRule.java
@@ -1,43 +1,45 @@
-package edu.rpi.legup.puzzle.heyawake.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class FillRoomWhiteDirectRule extends DirectRule {
-
- public FillRoomWhiteDirectRule() {
- super("HEYA-BASC-0004",
- "Fill Room White",
- "",
- "edu/rpi/legup/images/heyawake/rules/FillRoomWhite.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.heyawake.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class FillRoomWhiteDirectRule extends DirectRule {
+
+ public FillRoomWhiteDirectRule() {
+ super(
+ "HEYA-BASC-0004",
+ "Fill Room White",
+ "",
+ "edu/rpi/legup/images/heyawake/rules/FillRoomWhite.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/OneRowDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/OneRowDirectRule.java
index 3e8c07a4d..8b6f21564 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/OneRowDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/OneRowDirectRule.java
@@ -1,7 +1,7 @@
-package edu.rpi.legup.puzzle.heyawake.rules;
-
-public class OneRowDirectRule {
- public OneRowDirectRule() {
- throw new RuntimeException("This rule has not been implemented");
- }
-}
+package edu.rpi.legup.puzzle.heyawake.rules;
+
+public class OneRowDirectRule {
+ public OneRowDirectRule() {
+ throw new RuntimeException("This rule has not been implemented");
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/PreventWhiteLineDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/PreventWhiteLineDirectRule.java
index 0efd90694..f5d4e78b7 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/PreventWhiteLineDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/PreventWhiteLineDirectRule.java
@@ -1,7 +1,7 @@
-package edu.rpi.legup.puzzle.heyawake.rules;
-
-public class PreventWhiteLineDirectRule {
- public PreventWhiteLineDirectRule() {
- throw new RuntimeException("This rule has not been implemented");
- }
-}
+package edu.rpi.legup.puzzle.heyawake.rules;
+
+public class PreventWhiteLineDirectRule {
+ public PreventWhiteLineDirectRule() {
+ throw new RuntimeException("This rule has not been implemented");
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooEmptyContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooEmptyContradictionRule.java
index 0e0beaeb2..762b435a2 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooEmptyContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooEmptyContradictionRule.java
@@ -7,19 +7,21 @@
public class RoomTooEmptyContradictionRule extends ContradictionRule {
public RoomTooEmptyContradictionRule() {
- super("HEYA-CONT-0002",
+ super(
+ "HEYA-CONT-0002",
"Room too Empty",
"",
"edu/rpi/legup/images/heyawake/contradictions/RoomTooEmpty.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooFullContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooFullContradictionRule.java
index 1de746cb2..643f75f13 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooFullContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooFullContradictionRule.java
@@ -7,19 +7,21 @@
public class RoomTooFullContradictionRule extends ContradictionRule {
public RoomTooFullContradictionRule() {
- super("HEYA-CONT-0003",
+ super(
+ "HEYA-CONT-0003",
"Room too Full",
"",
"edu/rpi/legup/images/heyawake/contradictions/RoomTooFull.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ThreeByThreeDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ThreeByThreeDirectRule.java
index 6dee3fc83..cf2c241e3 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ThreeByThreeDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ThreeByThreeDirectRule.java
@@ -1,7 +1,7 @@
-package edu.rpi.legup.puzzle.heyawake.rules;
-
-public class ThreeByThreeDirectRule {
- public ThreeByThreeDirectRule() {
- throw new RuntimeException("This rule has not been implemented");
- }
-}
+package edu.rpi.legup.puzzle.heyawake.rules;
+
+public class ThreeByThreeDirectRule {
+ public ThreeByThreeDirectRule() {
+ throw new RuntimeException("This rule has not been implemented");
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/TwoInCornerDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/TwoInCornerDirectRule.java
index 8e2776fc7..83f1ca72f 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/TwoInCornerDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/TwoInCornerDirectRule.java
@@ -1,7 +1,7 @@
-package edu.rpi.legup.puzzle.heyawake.rules;
-
-public class TwoInCornerDirectRule {
- public TwoInCornerDirectRule() {
- throw new RuntimeException("This rule has not been implemented");
- }
-}
+package edu.rpi.legup.puzzle.heyawake.rules;
+
+public class TwoInCornerDirectRule {
+ public TwoInCornerDirectRule() {
+ throw new RuntimeException("This rule has not been implemented");
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAreaContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAreaContradictionRule.java
index a287d9c78..c0987d4f9 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAreaContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAreaContradictionRule.java
@@ -7,19 +7,21 @@
public class WhiteAreaContradictionRule extends ContradictionRule {
public WhiteAreaContradictionRule() {
- super("HEYA-CONT-0004",
+ super(
+ "HEYA-CONT-0004",
"White Area",
"",
"edu/rpi/legup/images/heyawake/contradictions/WhiteArea.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAroundBlackDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAroundBlackDirectRule.java
index 21a698d41..2e3bc1812 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAroundBlackDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAroundBlackDirectRule.java
@@ -1,43 +1,45 @@
-package edu.rpi.legup.puzzle.heyawake.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class WhiteAroundBlackDirectRule extends DirectRule {
-
- public WhiteAroundBlackDirectRule() {
- super("HEYA-BASC-0009",
- "White Around Black",
- "",
- "edu/rpi/legup/images/heyawake/rules/WhiteAroundBlack.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.heyawake.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class WhiteAroundBlackDirectRule extends DirectRule {
+
+ public WhiteAroundBlackDirectRule() {
+ super(
+ "HEYA-BASC-0009",
+ "White Around Black",
+ "",
+ "edu/rpi/legup/images/heyawake/rules/WhiteAroundBlack.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteEscapeDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteEscapeDirectRule.java
index 231d353e6..f151ec12a 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteEscapeDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteEscapeDirectRule.java
@@ -1,7 +1,7 @@
-package edu.rpi.legup.puzzle.heyawake.rules;
-
-public class WhiteEscapeDirectRule {
- public WhiteEscapeDirectRule() {
- throw new RuntimeException("This rule has not been implemented");
- }
-}
+package edu.rpi.legup.puzzle.heyawake.rules;
+
+public class WhiteEscapeDirectRule {
+ public WhiteEscapeDirectRule() {
+ throw new RuntimeException("This rule has not been implemented");
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteLineContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteLineContradictionRule.java
index 835bce98c..b695b8206 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteLineContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteLineContradictionRule.java
@@ -7,20 +7,21 @@
public class WhiteLineContradictionRule extends ContradictionRule {
public WhiteLineContradictionRule() {
- super("HEYA-CONT-0005",
+ super(
+ "HEYA-CONT-0005",
"White Line",
"",
"edu/rpi/legup/images/heyawake/contradictions/WhiteLine.png");
-
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagWhiteDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagWhiteDirectRule.java
index 22a76b9a9..9df735b0b 100644
--- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagWhiteDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagWhiteDirectRule.java
@@ -1,7 +1,7 @@
-package edu.rpi.legup.puzzle.heyawake.rules;
-
-public class ZigZagWhiteDirectRule {
- public ZigZagWhiteDirectRule() {
- throw new RuntimeException("This rule has not been implemented");
- }
-}
+package edu.rpi.legup.puzzle.heyawake.rules;
+
+public class ZigZagWhiteDirectRule {
+ public ZigZagWhiteDirectRule() {
+ throw new RuntimeException("This rule has not been implemented");
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java
index 6a67d28ca..ab95c4658 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java
@@ -19,9 +19,7 @@ public LightUp() {
this.factory = new LightUpCellFactory();
}
- /**
- * Initializes the game board. Called by the invoker of the class
- */
+ /** Initializes the game board. Called by the invoker of the class */
@Override
public void initializeView() {
boardView = new LightUpView((LightUpBoard) currentBoard);
@@ -44,8 +42,8 @@ public Board generatePuzzle(int difficulty) {
/**
* Determines if the given dimensions are valid for Light Up
*
- * @param rows the number of rows
- * @param columns the number of columns
+ * @param rows the number of rows
+ * @param columns the number of columns
* @return true if the given dimensions are valid for Light Up, false otherwise
*/
public boolean isValidDimensions(int rows, int columns) {
@@ -71,7 +69,9 @@ public boolean isBoardComplete(Board board) {
}
for (PuzzleElement data : lightUpBoard.getPuzzleElements()) {
LightUpCell cell = (LightUpCell) data;
- if ((cell.getType() == LightUpCellType.UNKNOWN || cell.getType() == LightUpCellType.EMPTY) && !cell.isLite()) {
+ if ((cell.getType() == LightUpCellType.UNKNOWN
+ || cell.getType() == LightUpCellType.EMPTY)
+ && !cell.isLite()) {
return false;
}
}
@@ -84,7 +84,5 @@ public boolean isBoardComplete(Board board) {
* @param board the board that has changed
*/
@Override
- public void onBoardChange(Board board) {
-
- }
+ public void onBoardChange(Board board) {}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpBoard.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpBoard.java
index b15f49919..217ef79a8 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpBoard.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpBoard.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.gameboard.GridBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-
import java.awt.*;
import java.util.HashSet;
import java.util.Set;
@@ -17,7 +16,8 @@ public LightUpBoard(int size) {
}
/**
- * Sets cells in board to lite depending on whether there is a bulb cell in the current row or column
+ * Sets cells in board to lite depending on whether there is a bulb cell in the current row or
+ * column
*/
public void fillWithLight() {
for (int y = 0; y < this.dimension.height; y++) {
@@ -33,28 +33,32 @@ public void fillWithLight() {
cell.setLite(true);
for (int i = x + 1; i < this.dimension.width; i++) {
LightUpCell c = getCell(i, y);
- if (c.getType() == LightUpCellType.NUMBER || c.getType() == LightUpCellType.BLACK) {
+ if (c.getType() == LightUpCellType.NUMBER
+ || c.getType() == LightUpCellType.BLACK) {
break;
}
c.setLite(true);
}
for (int i = x - 1; i >= 0; i--) {
LightUpCell c = getCell(i, y);
- if (c.getType() == LightUpCellType.NUMBER || c.getType() == LightUpCellType.BLACK) {
+ if (c.getType() == LightUpCellType.NUMBER
+ || c.getType() == LightUpCellType.BLACK) {
break;
}
c.setLite(true);
}
for (int i = y + 1; i < this.dimension.height; i++) {
LightUpCell c = getCell(x, i);
- if (c.getType() == LightUpCellType.NUMBER || c.getType() == LightUpCellType.BLACK) {
+ if (c.getType() == LightUpCellType.NUMBER
+ || c.getType() == LightUpCellType.BLACK) {
break;
}
c.setLite(true);
}
for (int i = y - 1; i >= 0; i--) {
LightUpCell c = getCell(x, i);
- if (c.getType() == LightUpCellType.NUMBER || c.getType() == LightUpCellType.BLACK) {
+ if (c.getType() == LightUpCellType.NUMBER
+ || c.getType() == LightUpCellType.BLACK) {
break;
}
c.setLite(true);
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java
index 36e5a5088..8adf84cb4 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.elements.Element;
import edu.rpi.legup.model.gameboard.GridCell;
-
import java.awt.*;
import java.awt.event.MouseEvent;
@@ -27,20 +26,18 @@ public void setType(Element e, MouseEvent m) {
this.data = -2;
break;
case "LTUP-UNPL-0001":
- switch (m.getButton()){
+ switch (m.getButton()) {
case MouseEvent.BUTTON1:
if (this.data < 0 || this.data > 3) {
this.data = 0;
- }
- else {
+ } else {
this.data = this.data + 1;
}
break;
case MouseEvent.BUTTON3:
if (this.data > 0) {
this.data = this.data - 1;
- }
- else {
+ } else {
this.data = 4;
}
break;
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellController.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellController.java
index 9c94b24f7..d4049897d 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellController.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellController.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.controller.ElementController;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-
import java.awt.event.MouseEvent;
public class LightUpCellController extends ElementController {
@@ -11,32 +10,31 @@ public void changeCell(MouseEvent e, PuzzleElement data) {
LightUpCell cell = (LightUpCell) data;
if (e.getButton() == MouseEvent.BUTTON1) {
if (e.isControlDown()) {
- this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY());
- }
- else {
+ this.boardView
+ .getSelectionPopupMenu()
+ .show(
+ boardView,
+ this.boardView.getCanvas().getX() + e.getX(),
+ this.boardView.getCanvas().getY() + e.getY());
+ } else {
if (cell.getData() == -2) {
data.setData(-4);
- }
- else {
+ } else {
if (cell.getData() == -4) {
data.setData(-3);
- }
- else {
+ } else {
data.setData(-2);
}
}
}
- }
- else {
+ } else {
if (e.getButton() == MouseEvent.BUTTON3) {
if (cell.getData() == -4) {
data.setData(-2);
- }
- else {
+ } else {
if (cell.getData() == -2) {
data.setData(-3);
- }
- else {
+ } else {
data.setData(-4);
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java
index 4914facfa..384aa2b74 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java
@@ -4,17 +4,16 @@
import edu.rpi.legup.model.gameboard.ElementFactory;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.awt.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import java.awt.*;
-
public class LightUpCellFactory extends ElementFactory {
/**
* Creates a puzzleElement based on the xml document Node and adds it to the board
*
- * @param node node that represents the puzzleElement
+ * @param node node that represents the puzzleElement
* @param board board to add the newly created cell
* @return newly created cell from the xml document Node
* @throws InvalidFileFormatException if file is invalid
@@ -23,7 +22,8 @@ public class LightUpCellFactory extends ElementFactory {
public LightUpCell importCell(Node node, Board board) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("cell")) {
- throw new InvalidFileFormatException("lightup Factory: unknown puzzleElement puzzleElement");
+ throw new InvalidFileFormatException(
+ "lightup Factory: unknown puzzleElement puzzleElement");
}
LightUpBoard lightUpBoard = (LightUpBoard) board;
@@ -35,7 +35,8 @@ public LightUpCell importCell(Node node, Board board) throws InvalidFileFormatEx
int x = Integer.valueOf(attributeList.getNamedItem("x").getNodeValue());
int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue());
if (x >= width || y >= height) {
- throw new InvalidFileFormatException("lightup Factory: cell location out of bounds");
+ throw new InvalidFileFormatException(
+ "lightup Factory: cell location out of bounds");
}
if (value < -4 || value > 4) {
throw new InvalidFileFormatException("lightup Factory: cell unknown value");
@@ -44,11 +45,10 @@ public LightUpCell importCell(Node node, Board board) throws InvalidFileFormatEx
LightUpCell cell = new LightUpCell(value, new Point(x, y));
cell.setIndex(y * height + x);
return cell;
- }
- catch (NumberFormatException e) {
- throw new InvalidFileFormatException("lightup Factory: unknown value where integer expected");
- }
- catch (NullPointerException e) {
+ } catch (NumberFormatException e) {
+ throw new InvalidFileFormatException(
+ "lightup Factory: unknown value where integer expected");
+ } catch (NullPointerException e) {
throw new InvalidFileFormatException("lightup Factory: could not find attribute(s)");
}
}
@@ -56,7 +56,7 @@ public LightUpCell importCell(Node node, Board board) throws InvalidFileFormatEx
/**
* Creates a xml document puzzleElement from a cell for exporting
*
- * @param document xml document
+ * @param document xml document
* @param puzzleElement PuzzleElement cell
* @return xml PuzzleElement
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellType.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellType.java
index b0825910d..8472be7a6 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellType.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellType.java
@@ -1,7 +1,11 @@
package edu.rpi.legup.puzzle.lightup;
public enum LightUpCellType {
- BULB(-4), EMPTY(-3), UNKNOWN(-2), BLACK(-1), NUMBER(0);
+ BULB(-4),
+ EMPTY(-3),
+ UNKNOWN(-2),
+ BLACK(-1),
+ NUMBER(0);
public int value;
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpElementView.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpElementView.java
index 7f35d46a6..1b00b007d 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpElementView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpElementView.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.puzzle.lightup;
import edu.rpi.legup.ui.boardview.GridElementView;
-
import java.awt.*;
public class LightUpElementView extends GridElementView {
@@ -40,37 +39,45 @@ public void drawElement(Graphics2D graphics2D) {
FontMetrics metrics = graphics2D.getFontMetrics(FONT);
String value = String.valueOf(puzzleElement.getData());
int xText = location.x + (size.width - metrics.stringWidth(value)) / 2;
- int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent();
+ int yText =
+ location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent();
graphics2D.drawString(String.valueOf(puzzleElement.getData()), xText, yText);
- }
- else {
+ } else {
if (type == LightUpCellType.BLACK) {
graphics2D.setStroke(new BasicStroke(1));
graphics2D.setColor(BLACK_COLOR);
graphics2D.fillRect(location.x, location.y, size.width, size.height);
- }
- else {
+ } else {
if (type == LightUpCellType.EMPTY) {
graphics2D.setStroke(new BasicStroke(1));
graphics2D.setColor(cell.isLite() ? LITE : WHITE_COLOR);
graphics2D.fillRect(location.x, location.y, size.width, size.height);
graphics2D.setColor(BLACK_COLOR);
- graphics2D.fillRect(location.x + size.width * 7 / 16, location.y + size.height * 7 / 16, size.width / 8, size.height / 8);
+ graphics2D.fillRect(
+ location.x + size.width * 7 / 16,
+ location.y + size.height * 7 / 16,
+ size.width / 8,
+ size.height / 8);
graphics2D.drawRect(location.x, location.y, size.width, size.height);
- }
- else {
+ } else {
if (type == LightUpCellType.UNKNOWN) {
graphics2D.setStroke(new BasicStroke(1));
graphics2D.setColor(cell.isLite() ? LITE : Color.LIGHT_GRAY);
graphics2D.fillRect(location.x, location.y, size.width, size.height);
graphics2D.setColor(Color.BLACK);
graphics2D.drawRect(location.x, location.y, size.width, size.height);
- }
- else {
+ } else {
if (type == LightUpCellType.BULB) {
graphics2D.setColor(Color.LIGHT_GRAY);
graphics2D.fillRect(location.x, location.y, size.width, size.height);
- graphics2D.drawImage(LightUpView.lightImage, location.x, location.y, size.width, size.height, LITE, null);
+ graphics2D.drawImage(
+ LightUpView.lightImage,
+ location.x,
+ location.y,
+ size.width,
+ size.height,
+ LITE,
+ null);
graphics2D.setColor(BLACK_COLOR);
graphics2D.drawRect(location.x, location.y, size.width, size.height);
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java
index 89024ad6c..0e8987020 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.PuzzleExporter;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard;
import org.w3c.dom.Document;
public class LightUpExporter extends PuzzleExporter {
@@ -16,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
LightUpBoard board;
if (puzzle.getTree() != null) {
board = (LightUpBoard) puzzle.getTree().getRootNode().getBoard();
- }
- else {
+ } else {
board = (LightUpBoard) puzzle.getBoardView().getBoard();
}
@@ -29,7 +27,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
for (PuzzleElement puzzleElement : board.getPuzzleElements()) {
LightUpCell cell = (LightUpCell) puzzleElement;
if (cell.getData() != -2) {
- org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement);
+ org.w3c.dom.Element cellElement =
+ puzzle.getFactory().exportCell(newDocument, puzzleElement);
cellsElement.appendChild(cellElement);
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java
index 7ef24ca69..336b063f6 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java
@@ -2,12 +2,11 @@
import edu.rpi.legup.model.PuzzleImporter;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.awt.*;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import java.awt.*;
-
public class LightUpImporter extends PuzzleImporter {
public LightUpImporter(LightUp lightUp) {
super(lightUp);
@@ -26,7 +25,7 @@ public boolean acceptsTextInput() {
/**
* Creates an empty board for building
*
- * @param rows the number of rows on the board
+ * @param rows the number of rows on the board
* @param columns the number of columns on the board
* @throws RuntimeException if board can not be created
*/
@@ -57,11 +56,13 @@ public void initializeBoard(int rows, int columns) {
public void initializeBoard(Node node) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("board")) {
- throw new InvalidFileFormatException("lightup Importer: cannot find board puzzleElement");
+ throw new InvalidFileFormatException(
+ "lightup Importer: cannot find board puzzleElement");
}
Element boardElement = (Element) node;
if (boardElement.getElementsByTagName("cells").getLength() == 0) {
- throw new InvalidFileFormatException("lightup Importer: no puzzleElement found for board");
+ throw new InvalidFileFormatException(
+ "lightup Importer: no puzzleElement found for board");
}
Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0);
NodeList elementDataList = dataElement.getElementsByTagName("cell");
@@ -70,9 +71,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
if (!boardElement.getAttribute("size").isEmpty()) {
int size = Integer.valueOf(boardElement.getAttribute("size"));
lightUpBoard = new LightUpBoard(size);
- }
- else {
- if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) {
+ } else {
+ if (!boardElement.getAttribute("width").isEmpty()
+ && !boardElement.getAttribute("height").isEmpty()) {
int width = Integer.valueOf(boardElement.getAttribute("width"));
int height = Integer.valueOf(boardElement.getAttribute("height"));
lightUpBoard = new LightUpBoard(width, height);
@@ -87,7 +88,10 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
int height = lightUpBoard.getHeight();
for (int i = 0; i < elementDataList.getLength(); i++) {
- LightUpCell cell = (LightUpCell) puzzle.getFactory().importCell(elementDataList.item(i), lightUpBoard);
+ LightUpCell cell =
+ (LightUpCell)
+ puzzle.getFactory()
+ .importCell(elementDataList.item(i), lightUpBoard);
Point loc = cell.getLocation();
if (cell.getData() != -2) {
cell.setModifiable(false);
@@ -107,9 +111,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
}
}
puzzle.setCurrentBoard(lightUpBoard);
- }
- catch (NumberFormatException e) {
- throw new InvalidFileFormatException("lightup Importer: unknown value where integer expected");
+ } catch (NumberFormatException e) {
+ throw new InvalidFileFormatException(
+ "lightup Importer: unknown value where integer expected");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpView.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpView.java
index 0fd57e705..ebce6a682 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpView.java
@@ -7,23 +7,24 @@
import edu.rpi.legup.ui.boardview.DataSelectionView;
import edu.rpi.legup.ui.boardview.GridBoardView;
import edu.rpi.legup.ui.boardview.SelectionItemView;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import javax.imageio.ImageIO;
-import javax.swing.*;
import java.awt.*;
import java.io.IOException;
+import javax.imageio.ImageIO;
+import javax.swing.*;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
public class LightUpView extends GridBoardView {
- private final static Logger LOGGER = LogManager.getLogger(LightUpView.class.getName());
+ private static final Logger LOGGER = LogManager.getLogger(LightUpView.class.getName());
static Image lightImage;
static {
try {
- lightImage = ImageIO.read(ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/lightup/light.png"));
- }
- catch (IOException e) {
+ lightImage =
+ ImageIO.read(
+ ClassLoader.getSystemClassLoader()
+ .getResource("edu/rpi/legup/images/lightup/light.png"));
+ } catch (IOException e) {
LOGGER.error("Failed to open TreeTent images");
}
}
@@ -37,7 +38,8 @@ public LightUpView(LightUpBoard board) {
LightUpElementView elementView = new LightUpElementView(cell);
elementView.setIndex(cell.getIndex());
elementView.setSize(elementSize);
- elementView.setLocation(new Point(loc.x * elementSize.width, loc.y * elementSize.height));
+ elementView.setLocation(
+ new Point(loc.x * elementSize.width, loc.y * elementSize.height));
elementViews.add(elementView);
}
}
@@ -50,14 +52,15 @@ public LightUpView(LightUpBoard board) {
@Override
public void onTreeElementChanged(TreeElement treeElement) {
super.onTreeElementChanged(treeElement);
- LightUpBoard lightUpBoard = board instanceof CaseBoard ? (LightUpBoard) ((CaseBoard) board).getBaseBoard() : (LightUpBoard) board;
+ LightUpBoard lightUpBoard =
+ board instanceof CaseBoard
+ ? (LightUpBoard) ((CaseBoard) board).getBaseBoard()
+ : (LightUpBoard) board;
lightUpBoard.fillWithLight();
repaint();
}
- /**
- * Returns a DataSelectionView popup menu
- */
+ /** Returns a DataSelectionView popup menu */
public DataSelectionView getSelectionPopupMenu() {
DataSelectionView selectionView = new DataSelectionView(elementController);
GridLayout layout = new GridLayout(3, 1);
@@ -69,7 +72,9 @@ public DataSelectionView getSelectionPopupMenu() {
LightUpElementView element1 = new LightUpElementView(new LightUpCell(-2, null));
element1.setSize(iconSize);
element1.setLocation(loc);
- SelectionItemView item1 = new SelectionItemView(element1.getPuzzleElement(), new ImageIcon(element1.getImage()));
+ SelectionItemView item1 =
+ new SelectionItemView(
+ element1.getPuzzleElement(), new ImageIcon(element1.getImage()));
item1.addActionListener(elementController);
item1.setHorizontalTextPosition(SwingConstants.CENTER);
selectionView.add(item1);
@@ -77,7 +82,9 @@ public DataSelectionView getSelectionPopupMenu() {
LightUpElementView element2 = new LightUpElementView(new LightUpCell(-4, null));
element2.setSize(iconSize);
element2.setLocation(loc);
- SelectionItemView item2 = new SelectionItemView(element2.getPuzzleElement(), new ImageIcon(element2.getImage()));
+ SelectionItemView item2 =
+ new SelectionItemView(
+ element2.getPuzzleElement(), new ImageIcon(element2.getImage()));
item2.addActionListener(elementController);
item2.setHorizontalTextPosition(SwingConstants.CENTER);
selectionView.add(item2);
@@ -85,7 +92,9 @@ public DataSelectionView getSelectionPopupMenu() {
LightUpElementView element3 = new LightUpElementView(new LightUpCell(-3, null));
element3.setSize(iconSize);
element3.setLocation(loc);
- SelectionItemView item3 = new SelectionItemView(element3.getPuzzleElement(), new ImageIcon(element3.getImage()));
+ SelectionItemView item3 =
+ new SelectionItemView(
+ element3.getPuzzleElement(), new ImageIcon(element3.getImage()));
item3.addActionListener(elementController);
item3.setHorizontalTextPosition(SwingConstants.CENTER);
selectionView.add(item3);
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BlackTile.java b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BlackTile.java
index d3e8cf506..2ddb4f754 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BlackTile.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BlackTile.java
@@ -4,6 +4,10 @@
public class BlackTile extends NonPlaceableElement {
public BlackTile() {
- super("LTUP-UNPL-0002", "Black Tile", "The black tile", "edu/rpi/legup/images/lightup/black.gif");
+ super(
+ "LTUP-UNPL-0002",
+ "Black Tile",
+ "The black tile",
+ "edu/rpi/legup/images/lightup/black.gif");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BulbTile.java b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BulbTile.java
index 5fc4a334f..d238baa56 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BulbTile.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BulbTile.java
@@ -4,6 +4,10 @@
public class BulbTile extends PlaceableElement {
public BulbTile() {
- super("LTUP-PLAC-0001", "Bulb Tile", "The bulb tile", "edu/rpi/legup/images/lightup/light.png");
+ super(
+ "LTUP-PLAC-0001",
+ "Bulb Tile",
+ "The bulb tile",
+ "edu/rpi/legup/images/lightup/light.png");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/NumberTile.java b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/NumberTile.java
index e96a969e5..ae314a4cf 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/NumberTile.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/NumberTile.java
@@ -8,11 +8,19 @@ public class NumberTile extends NonPlaceableElement {
// Follow the default format and resolves the NoSuchMethod error
public NumberTile() {
- super("LTUP-UNPL-0001", "Number Tile", "The number tile", "edu/rpi/legup/images/lightup/1.gif");
+ super(
+ "LTUP-UNPL-0001",
+ "Number Tile",
+ "The number tile",
+ "edu/rpi/legup/images/lightup/1.gif");
}
public NumberTile(int num) {
- super("LTUP-UNPL-0001", "Number Tile", "The number tile", "edu/rpi/legup/images/lightup/" + num + ".gif");
+ super(
+ "LTUP-UNPL-0001",
+ "Number Tile",
+ "The number tile",
+ "edu/rpi/legup/images/lightup/" + num + ".gif");
if (num > 3 || num < 1) num = 1;
object_number = num;
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/UnknownTile.java b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/UnknownTile.java
index 6839e70de..24d420fe8 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/UnknownTile.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/UnknownTile.java
@@ -4,6 +4,10 @@
public class UnknownTile extends NonPlaceableElement {
public UnknownTile() {
- super("LTUP-UNPL-0003", "Unknown Tile", "A blank tile", "edu/rpi/legup/images/lightup/UnknownTile.png");
+ super(
+ "LTUP-UNPL-0003",
+ "Unknown Tile",
+ "A blank tile",
+ "edu/rpi/legup/images/lightup/UnknownTile.png");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java
index 2804e6eab..90652888c 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java
@@ -6,24 +6,26 @@
import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import edu.rpi.legup.puzzle.lightup.LightUpCell;
import edu.rpi.legup.puzzle.lightup.LightUpCellType;
-
import java.awt.*;
public class BulbsInPathContradictionRule extends ContradictionRule {
public BulbsInPathContradictionRule() {
- super("LTUP-CONT-0001", "Bulbs In Path",
+ super(
+ "LTUP-CONT-0001",
+ "Bulbs In Path",
"A bulb cannot be placed in another bulb's path.",
"edu/rpi/legup/images/lightup/contradictions/BulbsInPath.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
@@ -38,8 +40,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
LightUpCell c = lightUpBoard.getCell(i, location.y);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
- }
- else {
+ } else {
if (c.getType() == LightUpCellType.BULB) {
return null;
}
@@ -49,8 +50,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
LightUpCell c = lightUpBoard.getCell(i, location.y);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
- }
- else {
+ } else {
if (c.getType() == LightUpCellType.BULB) {
return null;
}
@@ -60,8 +60,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
LightUpCell c = lightUpBoard.getCell(location.x, i);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
- }
- else {
+ } else {
if (c.getType() == LightUpCellType.BULB) {
return null;
}
@@ -71,8 +70,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
LightUpCell c = lightUpBoard.getCell(location.x, i);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
- }
- else {
+ } else {
if (c.getType() == LightUpCellType.BULB) {
return null;
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java
index 011bf1c0a..0ed88636c 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java
@@ -6,24 +6,26 @@
import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import edu.rpi.legup.puzzle.lightup.LightUpCell;
import edu.rpi.legup.puzzle.lightup.LightUpCellType;
-
import java.awt.*;
public class CannotLightACellContradictionRule extends ContradictionRule {
public CannotLightACellContradictionRule() {
- super("LTUP-CONT-0002", "Cannot Light A Cell",
+ super(
+ "LTUP-CONT-0002",
+ "Cannot Light A Cell",
"All cells must be able to be lit.",
"edu/rpi/legup/images/lightup/contradictions/CannotLightACell.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
@@ -42,8 +44,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
LightUpCell c = lightUpBoard.getCell(i, location.y);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
- }
- else {
+ } else {
if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) {
hor_count += 1;
}
@@ -53,8 +54,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
LightUpCell c = lightUpBoard.getCell(i, location.y);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
- }
- else {
+ } else {
if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) {
hor_count += 1;
}
@@ -64,8 +64,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
LightUpCell c = lightUpBoard.getCell(location.x, i);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
- }
- else {
+ } else {
if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) {
ver_count += 1;
}
@@ -75,8 +74,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
LightUpCell c = lightUpBoard.getCell(location.x, i);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
- }
- else {
+ } else {
if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) {
ver_count += 1;
}
@@ -88,4 +86,4 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
}
return super.getNoContradictionMessage();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightDirectRule.java
index a40ede284..269ef0ad5 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightDirectRule.java
@@ -1,64 +1,68 @@
-package edu.rpi.legup.puzzle.lightup.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.lightup.LightUpBoard;
-import edu.rpi.legup.puzzle.lightup.LightUpCell;
-import edu.rpi.legup.puzzle.lightup.LightUpCellType;
-
-public class EmptyCellinLightDirectRule extends DirectRule {
-
- public EmptyCellinLightDirectRule() {
- super("LTUP-BASC-0002", "Empty Cells in Light",
- "Cells in light must be empty.",
- "edu/rpi/legup/images/lightup/rules/EmptyCellInLight.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement index of the puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard();
- initialBoard.fillWithLight();
- LightUpCell initCell = (LightUpCell) initialBoard.getPuzzleElement(puzzleElement);
- LightUpCell finalCell = (LightUpCell) transition.getBoard().getPuzzleElement(puzzleElement);
- if (finalCell.getType() == LightUpCellType.EMPTY && initCell.getType() == LightUpCellType.UNKNOWN && initCell.isLite()) {
- return null;
- }
- return super.getInvalidUseOfRuleMessage() + ": Cell is not forced to be empty";
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy();
- for (PuzzleElement element : lightUpBoard.getPuzzleElements()) {
- LightUpCell cell = (LightUpCell) element;
- if (cell.getType() == LightUpCellType.UNKNOWN && cell.isLite()) {
- cell.setData(LightUpCellType.EMPTY.value);
- lightUpBoard.addModifiedData(cell);
- }
- }
- if (lightUpBoard.getModifiedData().isEmpty()) {
- return null;
- }
- else {
- return lightUpBoard;
- }
- }
-}
+package edu.rpi.legup.puzzle.lightup.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.lightup.LightUpBoard;
+import edu.rpi.legup.puzzle.lightup.LightUpCell;
+import edu.rpi.legup.puzzle.lightup.LightUpCellType;
+
+public class EmptyCellinLightDirectRule extends DirectRule {
+
+ public EmptyCellinLightDirectRule() {
+ super(
+ "LTUP-BASC-0002",
+ "Empty Cells in Light",
+ "Cells in light must be empty.",
+ "edu/rpi/legup/images/lightup/rules/EmptyCellInLight.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement index of the puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard();
+ initialBoard.fillWithLight();
+ LightUpCell initCell = (LightUpCell) initialBoard.getPuzzleElement(puzzleElement);
+ LightUpCell finalCell = (LightUpCell) transition.getBoard().getPuzzleElement(puzzleElement);
+ if (finalCell.getType() == LightUpCellType.EMPTY
+ && initCell.getType() == LightUpCellType.UNKNOWN
+ && initCell.isLite()) {
+ return null;
+ }
+ return super.getInvalidUseOfRuleMessage() + ": Cell is not forced to be empty";
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy();
+ for (PuzzleElement element : lightUpBoard.getPuzzleElements()) {
+ LightUpCell cell = (LightUpCell) element;
+ if (cell.getType() == LightUpCellType.UNKNOWN && cell.isLite()) {
+ cell.setData(LightUpCellType.EMPTY.value);
+ lightUpBoard.addModifiedData(cell);
+ }
+ }
+ if (lightUpBoard.getModifiedData().isEmpty()) {
+ return null;
+ } else {
+ return lightUpBoard;
+ }
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersDirectRule.java
index 04c493f08..702c116c1 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersDirectRule.java
@@ -1,115 +1,117 @@
-package edu.rpi.legup.puzzle.lightup.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.lightup.LightUpBoard;
-import edu.rpi.legup.puzzle.lightup.LightUpCell;
-import edu.rpi.legup.puzzle.lightup.LightUpCellType;
-
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.List;
-
-public class EmptyCornersDirectRule extends DirectRule {
-
- public EmptyCornersDirectRule() {
- super("LTUP-BASC-0003", "Empty Corners",
- "Cells on the corners of a number must be empty if placing bulbs would prevent the number from being satisfied.",
- "edu/rpi/legup/images/lightup/rules/EmptyCorners.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement index of the puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard();
- LightUpCell cell = (LightUpCell) initialBoard.getPuzzleElement(puzzleElement);
- LightUpBoard finalBoard = (LightUpBoard) transition.getBoard();
- LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement);
-
- if (!(cell.getType() == LightUpCellType.UNKNOWN && finalCell.getType() == LightUpCellType.EMPTY)) {
- return super.getInvalidUseOfRuleMessage() + ": This cell must be an empty cell";
- }
-
- Point loc = finalCell.getLocation();
- List numberedCells = new ArrayList<>();
- LightUpCell upperRight = finalBoard.getCell(loc.x + 1, loc.y - 1);
- if (upperRight != null && upperRight.getType() == LightUpCellType.NUMBER) {
- numberedCells.add(upperRight);
- }
- LightUpCell upperLeft = finalBoard.getCell(loc.x - 1, loc.y - 1);
- if (upperLeft != null && upperLeft.getType() == LightUpCellType.NUMBER) {
- numberedCells.add(upperLeft);
- }
- LightUpCell lowerRight = finalBoard.getCell(loc.x + 1, loc.y + 1);
- if (lowerRight != null && lowerRight.getType() == LightUpCellType.NUMBER) {
- numberedCells.add(lowerRight);
- }
- LightUpCell lowerLeft = finalBoard.getCell(loc.x - 1, loc.y + 1);
- if (lowerLeft != null && lowerLeft.getType() == LightUpCellType.NUMBER) {
- numberedCells.add(lowerLeft);
- }
- if (numberedCells.isEmpty()) {
- return super.getInvalidUseOfRuleMessage() + ": This cell must diagonal to a numbered cell";
- }
-
- TooFewBulbsContradictionRule tooFew = new TooFewBulbsContradictionRule();
- LightUpBoard bulbCaseBoard = finalBoard.copy();
- LightUpCell bulbCaseCell = (LightUpCell) bulbCaseBoard.getPuzzleElement(puzzleElement);
- bulbCaseCell.setData(LightUpCellType.BULB.value);
- bulbCaseBoard.fillWithLight();
-
- boolean createsContra = false;
- for (LightUpCell c : numberedCells) {
- createsContra |= tooFew.checkContradictionAt(bulbCaseBoard, c) == null;
- }
- if (createsContra) {
- return null;
- }
- else {
- return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be empty";
- }
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy();
- LightUpBoard lightUpBoardCopy = (LightUpBoard) node.getBoard().copy();
- TreeTransition transition = new TreeTransition(node, lightUpBoardCopy);
- for (PuzzleElement element : lightUpBoardCopy.getPuzzleElements()) {
- LightUpCell cell = (LightUpCell) element;
- int temp = cell.getData();
- cell.setData(LightUpCellType.EMPTY.value);
- if (checkRuleRawAt(transition, cell) == null) {
- LightUpCell modCell = (LightUpCell) lightUpBoard.getPuzzleElement(cell);
- modCell.setData(LightUpCellType.EMPTY.value);
- lightUpBoard.addModifiedData(modCell);
- }
- else {
- cell.setData(temp);
- }
- }
- if (lightUpBoard.getModifiedData().isEmpty()) {
- return null;
- }
- else {
- return lightUpBoard;
- }
- }
-}
+package edu.rpi.legup.puzzle.lightup.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.lightup.LightUpBoard;
+import edu.rpi.legup.puzzle.lightup.LightUpCell;
+import edu.rpi.legup.puzzle.lightup.LightUpCellType;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+
+public class EmptyCornersDirectRule extends DirectRule {
+
+ public EmptyCornersDirectRule() {
+ super(
+ "LTUP-BASC-0003",
+ "Empty Corners",
+ "Cells on the corners of a number must be empty if placing bulbs would prevent the"
+ + " number from being satisfied.",
+ "edu/rpi/legup/images/lightup/rules/EmptyCorners.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement index of the puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard();
+ LightUpCell cell = (LightUpCell) initialBoard.getPuzzleElement(puzzleElement);
+ LightUpBoard finalBoard = (LightUpBoard) transition.getBoard();
+ LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement);
+
+ if (!(cell.getType() == LightUpCellType.UNKNOWN
+ && finalCell.getType() == LightUpCellType.EMPTY)) {
+ return super.getInvalidUseOfRuleMessage() + ": This cell must be an empty cell";
+ }
+
+ Point loc = finalCell.getLocation();
+ List numberedCells = new ArrayList<>();
+ LightUpCell upperRight = finalBoard.getCell(loc.x + 1, loc.y - 1);
+ if (upperRight != null && upperRight.getType() == LightUpCellType.NUMBER) {
+ numberedCells.add(upperRight);
+ }
+ LightUpCell upperLeft = finalBoard.getCell(loc.x - 1, loc.y - 1);
+ if (upperLeft != null && upperLeft.getType() == LightUpCellType.NUMBER) {
+ numberedCells.add(upperLeft);
+ }
+ LightUpCell lowerRight = finalBoard.getCell(loc.x + 1, loc.y + 1);
+ if (lowerRight != null && lowerRight.getType() == LightUpCellType.NUMBER) {
+ numberedCells.add(lowerRight);
+ }
+ LightUpCell lowerLeft = finalBoard.getCell(loc.x - 1, loc.y + 1);
+ if (lowerLeft != null && lowerLeft.getType() == LightUpCellType.NUMBER) {
+ numberedCells.add(lowerLeft);
+ }
+ if (numberedCells.isEmpty()) {
+ return super.getInvalidUseOfRuleMessage()
+ + ": This cell must diagonal to a numbered cell";
+ }
+
+ TooFewBulbsContradictionRule tooFew = new TooFewBulbsContradictionRule();
+ LightUpBoard bulbCaseBoard = finalBoard.copy();
+ LightUpCell bulbCaseCell = (LightUpCell) bulbCaseBoard.getPuzzleElement(puzzleElement);
+ bulbCaseCell.setData(LightUpCellType.BULB.value);
+ bulbCaseBoard.fillWithLight();
+
+ boolean createsContra = false;
+ for (LightUpCell c : numberedCells) {
+ createsContra |= tooFew.checkContradictionAt(bulbCaseBoard, c) == null;
+ }
+ if (createsContra) {
+ return null;
+ } else {
+ return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be empty";
+ }
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy();
+ LightUpBoard lightUpBoardCopy = (LightUpBoard) node.getBoard().copy();
+ TreeTransition transition = new TreeTransition(node, lightUpBoardCopy);
+ for (PuzzleElement element : lightUpBoardCopy.getPuzzleElements()) {
+ LightUpCell cell = (LightUpCell) element;
+ int temp = cell.getData();
+ cell.setData(LightUpCellType.EMPTY.value);
+ if (checkRuleRawAt(transition, cell) == null) {
+ LightUpCell modCell = (LightUpCell) lightUpBoard.getPuzzleElement(cell);
+ modCell.setData(LightUpCellType.EMPTY.value);
+ lightUpBoard.addModifiedData(modCell);
+ } else {
+ cell.setData(temp);
+ }
+ }
+ if (lightUpBoard.getModifiedData().isEmpty()) {
+ return null;
+ } else {
+ return lightUpBoard;
+ }
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsDirectRule.java
index cdea7880f..3f884d459 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsDirectRule.java
@@ -1,107 +1,110 @@
-package edu.rpi.legup.puzzle.lightup.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.lightup.LightUpBoard;
-import edu.rpi.legup.puzzle.lightup.LightUpCell;
-import edu.rpi.legup.puzzle.lightup.LightUpCellType;
-
-import java.util.Set;
-
-public class FinishWithBulbsDirectRule extends DirectRule {
-
- public FinishWithBulbsDirectRule() {
- super("LTUP-BASC-0004", "Finish with Bulbs",
- "The remaining unknowns around a block must be bulbs to satisfy the number.",
- "edu/rpi/legup/images/lightup/rules/FinishWithBulbs.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement index of the puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard();
- LightUpCell initCell = (LightUpCell) initialBoard.getPuzzleElement(puzzleElement);
- LightUpBoard finalBoard = (LightUpBoard) transition.getBoard();
- LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement);
- if (!(initCell.getType() == LightUpCellType.UNKNOWN && finalCell.getType() == LightUpCellType.BULB)) {
- return super.getInvalidUseOfRuleMessage() + ": Modified cells must be bulbs";
- }
-
- Set adjCells = finalBoard.getAdj(finalCell);
- adjCells.removeIf(cell -> cell.getType() != LightUpCellType.NUMBER);
- if (adjCells.isEmpty()) {
- return super.getInvalidUseOfRuleMessage() + ": This cell is not adjacent to a numbered cell";
- }
-
- LightUpBoard emptyCase = initialBoard.copy();
- emptyCase.getPuzzleElement(finalCell).setData(LightUpCellType.EMPTY.value);
- TooFewBulbsContradictionRule tooFew = new TooFewBulbsContradictionRule();
- for (LightUpCell c : adjCells) {
- if (tooFew.checkContradictionAt(emptyCase, c) == null) {
- return null;
- }
- }
- return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be a bulb";
- }
-
- /**
- * Determines whether the specified cell is forced to be a bulb or not
- *
- * @param board the entire board
- * @param cell specified cell
- * @return whether cell is forced to be a bulb or not
- */
- private boolean isForced(LightUpBoard board, LightUpCell cell) {
- Set adjCells = board.getAdj(cell);
- adjCells.removeIf(c -> c.getType() != LightUpCellType.NUMBER);
- if (adjCells.isEmpty()) {
- return false;
- }
-
- LightUpBoard emptyCase = board.copy();
- emptyCase.getPuzzleElement(cell).setData(LightUpCellType.EMPTY.value);
- TooFewBulbsContradictionRule tooFew = new TooFewBulbsContradictionRule();
- for (LightUpCell c : adjCells) {
- if (tooFew.checkContradictionAt(emptyCase, c) == null) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- LightUpBoard initialBoard = (LightUpBoard) node.getBoard();
- LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy();
- for (PuzzleElement element : lightUpBoard.getPuzzleElements()) {
- LightUpCell cell = (LightUpCell) element;
- if (cell.getType() == LightUpCellType.UNKNOWN && isForced(initialBoard, cell)) {
- cell.setData(LightUpCellType.BULB.value);
- lightUpBoard.addModifiedData(cell);
- }
- }
- if (lightUpBoard.getModifiedData().isEmpty()) {
- return null;
- }
- else {
- return lightUpBoard;
- }
- }
-}
+package edu.rpi.legup.puzzle.lightup.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.lightup.LightUpBoard;
+import edu.rpi.legup.puzzle.lightup.LightUpCell;
+import edu.rpi.legup.puzzle.lightup.LightUpCellType;
+import java.util.Set;
+
+public class FinishWithBulbsDirectRule extends DirectRule {
+
+ public FinishWithBulbsDirectRule() {
+ super(
+ "LTUP-BASC-0004",
+ "Finish with Bulbs",
+ "The remaining unknowns around a block must be bulbs to satisfy the number.",
+ "edu/rpi/legup/images/lightup/rules/FinishWithBulbs.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement index of the puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard();
+ LightUpCell initCell = (LightUpCell) initialBoard.getPuzzleElement(puzzleElement);
+ LightUpBoard finalBoard = (LightUpBoard) transition.getBoard();
+ LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement);
+ if (!(initCell.getType() == LightUpCellType.UNKNOWN
+ && finalCell.getType() == LightUpCellType.BULB)) {
+ return super.getInvalidUseOfRuleMessage() + ": Modified cells must be bulbs";
+ }
+
+ Set adjCells = finalBoard.getAdj(finalCell);
+ adjCells.removeIf(cell -> cell.getType() != LightUpCellType.NUMBER);
+ if (adjCells.isEmpty()) {
+ return super.getInvalidUseOfRuleMessage()
+ + ": This cell is not adjacent to a numbered cell";
+ }
+
+ LightUpBoard emptyCase = initialBoard.copy();
+ emptyCase.getPuzzleElement(finalCell).setData(LightUpCellType.EMPTY.value);
+ TooFewBulbsContradictionRule tooFew = new TooFewBulbsContradictionRule();
+ for (LightUpCell c : adjCells) {
+ if (tooFew.checkContradictionAt(emptyCase, c) == null) {
+ return null;
+ }
+ }
+ return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be a bulb";
+ }
+
+ /**
+ * Determines whether the specified cell is forced to be a bulb or not
+ *
+ * @param board the entire board
+ * @param cell specified cell
+ * @return whether cell is forced to be a bulb or not
+ */
+ private boolean isForced(LightUpBoard board, LightUpCell cell) {
+ Set adjCells = board.getAdj(cell);
+ adjCells.removeIf(c -> c.getType() != LightUpCellType.NUMBER);
+ if (adjCells.isEmpty()) {
+ return false;
+ }
+
+ LightUpBoard emptyCase = board.copy();
+ emptyCase.getPuzzleElement(cell).setData(LightUpCellType.EMPTY.value);
+ TooFewBulbsContradictionRule tooFew = new TooFewBulbsContradictionRule();
+ for (LightUpCell c : adjCells) {
+ if (tooFew.checkContradictionAt(emptyCase, c) == null) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ LightUpBoard initialBoard = (LightUpBoard) node.getBoard();
+ LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy();
+ for (PuzzleElement element : lightUpBoard.getPuzzleElements()) {
+ LightUpCell cell = (LightUpCell) element;
+ if (cell.getType() == LightUpCellType.UNKNOWN && isForced(initialBoard, cell)) {
+ cell.setData(LightUpCellType.BULB.value);
+ lightUpBoard.addModifiedData(cell);
+ }
+ }
+ if (lightUpBoard.getModifiedData().isEmpty()) {
+ return null;
+ } else {
+ return lightUpBoard;
+ }
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyDirectRule.java
index f7433150c..678ee67a2 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyDirectRule.java
@@ -1,118 +1,122 @@
-package edu.rpi.legup.puzzle.lightup.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.lightup.LightUpBoard;
-import edu.rpi.legup.puzzle.lightup.LightUpCell;
-import edu.rpi.legup.puzzle.lightup.LightUpCellType;
-
-import java.awt.*;
-
-public class FinishWithEmptyDirectRule extends DirectRule {
-
- public FinishWithEmptyDirectRule() {
- super("LTUP-BASC-0005", "Finish with Empty",
- "The remaining unknowns around a block must be empty if the number is satisfied.",
- "edu/rpi/legup/images/lightup/rules/FinishWithEmpty.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement index of the puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard();
- LightUpBoard finalBoard = (LightUpBoard) transition.getBoard();
- LightUpCell cell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement);
- if (cell.getType() != LightUpCellType.EMPTY) {
- return super.getInvalidUseOfRuleMessage() + ": Modified cells must be empty";
- }
-
- if (isForced(initialBoard, cell.getLocation())) {
- return null;
- }
- return super.getInvalidUseOfRuleMessage() + ": Empty is not forced";
- }
-
- /**
- * Checks whether a certain cell is forced to not be a bulb
- *
- * @param board specified board
- * @param location location of cell to check
- * @return boolean value based on whether a certain cell has an adjacent cell that has the required amount of adjacent bulbs
- */
- private boolean isForced(LightUpBoard board, Point location) {
- return isForcedEmpty(board, new Point(location.x + 1, location.y)) ||
- isForcedEmpty(board, new Point(location.x, location.y + 1)) ||
- isForcedEmpty(board, new Point(location.x - 1, location.y)) ||
- isForcedEmpty(board, new Point(location.x, location.y - 1));
- }
-
- /**
- * Checks whether a certain cell has the required amount of adjacent bulbs
- *
- * @param board specified board
- * @param loc location of cell to check
- * @return boolean value based on whether a certain cell has the required amount of adjacent bulbs
- */
- private boolean isForcedEmpty(LightUpBoard board, Point loc) {
- LightUpCell cell = board.getCell(loc.x, loc.y);
- if (cell == null || cell.getType() != LightUpCellType.NUMBER) {
- return false;
- }
-
- int bulbs = 0;
- int bulbsNeeded = cell.getData();
- cell = board.getCell(loc.x + 1, loc.y);
- if (cell != null && cell.getType() == LightUpCellType.BULB) {
- bulbs++;
- }
- cell = board.getCell(loc.x, loc.y + 1);
- if (cell != null && cell.getType() == LightUpCellType.BULB) {
- bulbs++;
- }
- cell = board.getCell(loc.x - 1, loc.y);
- if (cell != null && cell.getType() == LightUpCellType.BULB) {
- bulbs++;
- }
- cell = board.getCell(loc.x, loc.y - 1);
- if (cell != null && cell.getType() == LightUpCellType.BULB) {
- bulbs++;
- }
- return bulbs == bulbsNeeded;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- LightUpBoard initialBoard = (LightUpBoard) node.getBoard();
- LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy();
- for (PuzzleElement element : lightUpBoard.getPuzzleElements()) {
- LightUpCell cell = (LightUpCell) element;
- if (cell.getType() == LightUpCellType.UNKNOWN && isForced(initialBoard, cell.getLocation())) {
- cell.setData(LightUpCellType.EMPTY.value);
- lightUpBoard.addModifiedData(cell);
- }
- }
- if (lightUpBoard.getModifiedData().isEmpty()) {
- return null;
- }
- else {
- return lightUpBoard;
- }
- }
-}
+package edu.rpi.legup.puzzle.lightup.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.lightup.LightUpBoard;
+import edu.rpi.legup.puzzle.lightup.LightUpCell;
+import edu.rpi.legup.puzzle.lightup.LightUpCellType;
+import java.awt.*;
+
+public class FinishWithEmptyDirectRule extends DirectRule {
+
+ public FinishWithEmptyDirectRule() {
+ super(
+ "LTUP-BASC-0005",
+ "Finish with Empty",
+ "The remaining unknowns around a block must be empty if the number is satisfied.",
+ "edu/rpi/legup/images/lightup/rules/FinishWithEmpty.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement index of the puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard();
+ LightUpBoard finalBoard = (LightUpBoard) transition.getBoard();
+ LightUpCell cell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement);
+ if (cell.getType() != LightUpCellType.EMPTY) {
+ return super.getInvalidUseOfRuleMessage() + ": Modified cells must be empty";
+ }
+
+ if (isForced(initialBoard, cell.getLocation())) {
+ return null;
+ }
+ return super.getInvalidUseOfRuleMessage() + ": Empty is not forced";
+ }
+
+ /**
+ * Checks whether a certain cell is forced to not be a bulb
+ *
+ * @param board specified board
+ * @param location location of cell to check
+ * @return boolean value based on whether a certain cell has an adjacent cell that has the
+ * required amount of adjacent bulbs
+ */
+ private boolean isForced(LightUpBoard board, Point location) {
+ return isForcedEmpty(board, new Point(location.x + 1, location.y))
+ || isForcedEmpty(board, new Point(location.x, location.y + 1))
+ || isForcedEmpty(board, new Point(location.x - 1, location.y))
+ || isForcedEmpty(board, new Point(location.x, location.y - 1));
+ }
+
+ /**
+ * Checks whether a certain cell has the required amount of adjacent bulbs
+ *
+ * @param board specified board
+ * @param loc location of cell to check
+ * @return boolean value based on whether a certain cell has the required amount of adjacent
+ * bulbs
+ */
+ private boolean isForcedEmpty(LightUpBoard board, Point loc) {
+ LightUpCell cell = board.getCell(loc.x, loc.y);
+ if (cell == null || cell.getType() != LightUpCellType.NUMBER) {
+ return false;
+ }
+
+ int bulbs = 0;
+ int bulbsNeeded = cell.getData();
+ cell = board.getCell(loc.x + 1, loc.y);
+ if (cell != null && cell.getType() == LightUpCellType.BULB) {
+ bulbs++;
+ }
+ cell = board.getCell(loc.x, loc.y + 1);
+ if (cell != null && cell.getType() == LightUpCellType.BULB) {
+ bulbs++;
+ }
+ cell = board.getCell(loc.x - 1, loc.y);
+ if (cell != null && cell.getType() == LightUpCellType.BULB) {
+ bulbs++;
+ }
+ cell = board.getCell(loc.x, loc.y - 1);
+ if (cell != null && cell.getType() == LightUpCellType.BULB) {
+ bulbs++;
+ }
+ return bulbs == bulbsNeeded;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ LightUpBoard initialBoard = (LightUpBoard) node.getBoard();
+ LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy();
+ for (PuzzleElement element : lightUpBoard.getPuzzleElements()) {
+ LightUpCell cell = (LightUpCell) element;
+ if (cell.getType() == LightUpCellType.UNKNOWN
+ && isForced(initialBoard, cell.getLocation())) {
+ cell.setData(LightUpCellType.EMPTY.value);
+ lightUpBoard.addModifiedData(cell);
+ }
+ }
+ if (lightUpBoard.getModifiedData().isEmpty()) {
+ return null;
+ } else {
+ return lightUpBoard;
+ }
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java
index 410c30e9c..4ba754731 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java
@@ -8,14 +8,15 @@
import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import edu.rpi.legup.puzzle.lightup.LightUpCell;
import edu.rpi.legup.puzzle.lightup.LightUpCellType;
-
import java.util.ArrayList;
import java.util.List;
public class LightOrEmptyCaseRule extends CaseRule {
public LightOrEmptyCaseRule() {
- super("LTUP-CASE-0001", "Light or Empty",
+ super(
+ "LTUP-CASE-0001",
+ "Light or Empty",
"Each blank cell is either a light or empty.",
"edu/rpi/legup/images/lightup/cases/LightOrEmpty.png");
}
@@ -36,7 +37,7 @@ public CaseBoard getCaseBoard(Board board) {
/**
* Gets the possible cases at a specific location based on this case rule
*
- * @param board the current board state
+ * @param board the current board state
* @param puzzleElement puzzleElement to determine the possible cases for
* @return a list of elements the specified could be
*/
@@ -73,33 +74,37 @@ public String checkRuleRaw(TreeTransition transition) {
TreeTransition case1 = childTransitions.get(0);
TreeTransition case2 = childTransitions.get(1);
- if (case1.getBoard().getModifiedData().size() != 1 ||
- case2.getBoard().getModifiedData().size() != 1) {
- return super.getInvalidUseOfRuleMessage() + ": This case rule must have 1 modified cell for each case";
+ if (case1.getBoard().getModifiedData().size() != 1
+ || case2.getBoard().getModifiedData().size() != 1) {
+ return super.getInvalidUseOfRuleMessage()
+ + ": This case rule must have 1 modified cell for each case";
}
LightUpCell mod1 = (LightUpCell) case1.getBoard().getModifiedData().iterator().next();
LightUpCell mod2 = (LightUpCell) case2.getBoard().getModifiedData().iterator().next();
if (!mod1.getLocation().equals(mod2.getLocation())) {
- return super.getInvalidUseOfRuleMessage() + ": This case rule must modify the same cell for each case";
+ return super.getInvalidUseOfRuleMessage()
+ + ": This case rule must modify the same cell for each case";
}
- if (!((mod1.getType() == LightUpCellType.EMPTY && mod2.getType() == LightUpCellType.BULB) ||
- (mod2.getType() == LightUpCellType.EMPTY && mod1.getType() == LightUpCellType.BULB))) {
- return super.getInvalidUseOfRuleMessage() + ": This case rule must an empty cell and a bulb cell";
+ if (!((mod1.getType() == LightUpCellType.EMPTY && mod2.getType() == LightUpCellType.BULB)
+ || (mod2.getType() == LightUpCellType.EMPTY
+ && mod1.getType() == LightUpCellType.BULB))) {
+ return super.getInvalidUseOfRuleMessage()
+ + ": This case rule must an empty cell and a bulb cell";
}
return null;
}
/**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement index of the puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightDirectRule.java
index f0f943401..bf1843728 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightDirectRule.java
@@ -1,149 +1,153 @@
-package edu.rpi.legup.puzzle.lightup.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.lightup.LightUpBoard;
-import edu.rpi.legup.puzzle.lightup.LightUpCell;
-import edu.rpi.legup.puzzle.lightup.LightUpCellType;
-
-import java.awt.*;
-
-public class MustLightDirectRule extends DirectRule {
-
- public MustLightDirectRule() {
- super("LTUP-BASC-0006", "Must Light",
- "A cell must be a bulb if it is the only cell to be able to light another.",
- "edu/rpi/legup/images/lightup/rules/MustLight.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement index of the puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- LightUpBoard parentBoard = (LightUpBoard) transition.getParents().get(0).getBoard();
- LightUpBoard finalBoard = (LightUpBoard) transition.getBoard();
- LightUpCell parentCell = (LightUpCell) parentBoard.getPuzzleElement(puzzleElement);
- LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement);
- if (!(parentCell.getType() == LightUpCellType.UNKNOWN && !parentCell.isLite() && finalCell.getType() == LightUpCellType.BULB)) {
- return super.getInvalidUseOfRuleMessage() + ": Modified cells must be bulbs";
- }
-
- finalBoard.fillWithLight();
- boolean isForced = isForcedBulb(parentBoard, parentCell.getLocation());
- finalCell.setData(LightUpCellType.BULB.value);
- finalBoard.fillWithLight();
-
- if (isForced) {
- return null;
- }
- else {
- return super.getInvalidUseOfRuleMessage() + ": This cell can be lit by another cell";
- }
- }
-
- private boolean isForcedBulb(LightUpBoard board, Point loc) {
- CannotLightACellContradictionRule cannotLite = new CannotLightACellContradictionRule();
- LightUpBoard modifiedBoard = board.copy();
- LightUpCell modifiedCell = modifiedBoard.getCell(loc.x, loc.y);
- modifiedCell.setData(LightUpCellType.EMPTY.value);
- //Check if this cell itself (the one with the bulb) has no other lighting option
- if ((modifiedCell.getType() == LightUpCellType.EMPTY || modifiedCell.getType() == LightUpCellType.UNKNOWN) &&
- !modifiedCell.isLite() && cannotLite.checkContradictionAt(modifiedBoard, modifiedCell) == null) {
- return true;
- }
- //Look right
- for (int i = loc.x + 1; i < modifiedBoard.getWidth(); i++) {
- LightUpCell c = modifiedBoard.getCell(i, loc.y);
- if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
- break;
- }
- else {
- if (c.getType() == LightUpCellType.EMPTY &&
- !c.isLite() && cannotLite.checkContradictionAt(modifiedBoard, c) == null) {
- return true;
- }
- }
- }
- //Look left
- for (int i = loc.x - 1; i >= 0; i--) {
- LightUpCell c = modifiedBoard.getCell(i, loc.y);
- if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
- break;
- }
- else {
- if (c.getType() == LightUpCellType.EMPTY &&
- !c.isLite() && cannotLite.checkContradictionAt(modifiedBoard, c) == null) {
- return true;
- }
- }
- }
- //Look down
- for (int i = loc.y + 1; i < modifiedBoard.getHeight(); i++) {
- LightUpCell c = modifiedBoard.getCell(loc.x, i);
- if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
- break;
- }
- else {
- if (c.getType() == LightUpCellType.EMPTY &&
- !c.isLite() && cannotLite.checkContradictionAt(modifiedBoard, c) == null) {
- return true;
- }
- }
- }
- //Look up
- for (int i = loc.y - 1; i >= 0; i--) {
- LightUpCell c = modifiedBoard.getCell(loc.x, i);
- if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
- break;
- }
- else {
- if (c.getType() == LightUpCellType.EMPTY &&
- !c.isLite() && cannotLite.checkContradictionAt(modifiedBoard, c) == null) {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- LightUpBoard initialBoard = (LightUpBoard) node.getBoard();
- LightUpBoard tempBoard = (LightUpBoard) node.getBoard().copy();
- LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy();
- for (PuzzleElement element : tempBoard.getPuzzleElements()) {
- LightUpCell cell = (LightUpCell) element;
- if (cell.getType() == LightUpCellType.UNKNOWN && !cell.isLite()) {
- cell.setData(LightUpCellType.EMPTY.value);
- if (isForcedBulb(initialBoard, cell.getLocation())) {
- LightUpCell modCell = (LightUpCell) lightUpBoard.getPuzzleElement(cell);
- modCell.setData(LightUpCellType.BULB.value);
- lightUpBoard.addModifiedData(modCell);
- }
- cell.setData(LightUpCellType.UNKNOWN.value);
- }
- }
- if (lightUpBoard.getModifiedData().isEmpty()) {
- return null;
- }
- else {
- return lightUpBoard;
- }
- }
-}
+package edu.rpi.legup.puzzle.lightup.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.lightup.LightUpBoard;
+import edu.rpi.legup.puzzle.lightup.LightUpCell;
+import edu.rpi.legup.puzzle.lightup.LightUpCellType;
+import java.awt.*;
+
+public class MustLightDirectRule extends DirectRule {
+
+ public MustLightDirectRule() {
+ super(
+ "LTUP-BASC-0006",
+ "Must Light",
+ "A cell must be a bulb if it is the only cell to be able to light another.",
+ "edu/rpi/legup/images/lightup/rules/MustLight.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement index of the puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ LightUpBoard parentBoard = (LightUpBoard) transition.getParents().get(0).getBoard();
+ LightUpBoard finalBoard = (LightUpBoard) transition.getBoard();
+ LightUpCell parentCell = (LightUpCell) parentBoard.getPuzzleElement(puzzleElement);
+ LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement);
+ if (!(parentCell.getType() == LightUpCellType.UNKNOWN
+ && !parentCell.isLite()
+ && finalCell.getType() == LightUpCellType.BULB)) {
+ return super.getInvalidUseOfRuleMessage() + ": Modified cells must be bulbs";
+ }
+
+ finalBoard.fillWithLight();
+ boolean isForced = isForcedBulb(parentBoard, parentCell.getLocation());
+ finalCell.setData(LightUpCellType.BULB.value);
+ finalBoard.fillWithLight();
+
+ if (isForced) {
+ return null;
+ } else {
+ return super.getInvalidUseOfRuleMessage() + ": This cell can be lit by another cell";
+ }
+ }
+
+ private boolean isForcedBulb(LightUpBoard board, Point loc) {
+ CannotLightACellContradictionRule cannotLite = new CannotLightACellContradictionRule();
+ LightUpBoard modifiedBoard = board.copy();
+ LightUpCell modifiedCell = modifiedBoard.getCell(loc.x, loc.y);
+ modifiedCell.setData(LightUpCellType.EMPTY.value);
+ // Check if this cell itself (the one with the bulb) has no other lighting option
+ if ((modifiedCell.getType() == LightUpCellType.EMPTY
+ || modifiedCell.getType() == LightUpCellType.UNKNOWN)
+ && !modifiedCell.isLite()
+ && cannotLite.checkContradictionAt(modifiedBoard, modifiedCell) == null) {
+ return true;
+ }
+ // Look right
+ for (int i = loc.x + 1; i < modifiedBoard.getWidth(); i++) {
+ LightUpCell c = modifiedBoard.getCell(i, loc.y);
+ if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
+ break;
+ } else {
+ if (c.getType() == LightUpCellType.EMPTY
+ && !c.isLite()
+ && cannotLite.checkContradictionAt(modifiedBoard, c) == null) {
+ return true;
+ }
+ }
+ }
+ // Look left
+ for (int i = loc.x - 1; i >= 0; i--) {
+ LightUpCell c = modifiedBoard.getCell(i, loc.y);
+ if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
+ break;
+ } else {
+ if (c.getType() == LightUpCellType.EMPTY
+ && !c.isLite()
+ && cannotLite.checkContradictionAt(modifiedBoard, c) == null) {
+ return true;
+ }
+ }
+ }
+ // Look down
+ for (int i = loc.y + 1; i < modifiedBoard.getHeight(); i++) {
+ LightUpCell c = modifiedBoard.getCell(loc.x, i);
+ if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
+ break;
+ } else {
+ if (c.getType() == LightUpCellType.EMPTY
+ && !c.isLite()
+ && cannotLite.checkContradictionAt(modifiedBoard, c) == null) {
+ return true;
+ }
+ }
+ }
+ // Look up
+ for (int i = loc.y - 1; i >= 0; i--) {
+ LightUpCell c = modifiedBoard.getCell(loc.x, i);
+ if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
+ break;
+ } else {
+ if (c.getType() == LightUpCellType.EMPTY
+ && !c.isLite()
+ && cannotLite.checkContradictionAt(modifiedBoard, c) == null) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ LightUpBoard initialBoard = (LightUpBoard) node.getBoard();
+ LightUpBoard tempBoard = (LightUpBoard) node.getBoard().copy();
+ LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy();
+ for (PuzzleElement element : tempBoard.getPuzzleElements()) {
+ LightUpCell cell = (LightUpCell) element;
+ if (cell.getType() == LightUpCellType.UNKNOWN && !cell.isLite()) {
+ cell.setData(LightUpCellType.EMPTY.value);
+ if (isForcedBulb(initialBoard, cell.getLocation())) {
+ LightUpCell modCell = (LightUpCell) lightUpBoard.getPuzzleElement(cell);
+ modCell.setData(LightUpCellType.BULB.value);
+ lightUpBoard.addModifiedData(modCell);
+ }
+ cell.setData(LightUpCellType.UNKNOWN.value);
+ }
+ }
+ if (lightUpBoard.getModifiedData().isEmpty()) {
+ return null;
+ } else {
+ return lightUpBoard;
+ }
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java
index cf7b70ccd..ac656721d 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java
@@ -9,7 +9,6 @@
import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import edu.rpi.legup.puzzle.lightup.LightUpCell;
import edu.rpi.legup.puzzle.lightup.LightUpCellType;
-
import java.awt.*;
import java.util.ArrayList;
import java.util.Iterator;
@@ -19,7 +18,9 @@
public class SatisfyNumberCaseRule extends CaseRule {
public SatisfyNumberCaseRule() {
- super("LTUP-CASE-0002", "Satisfy Number",
+ super(
+ "LTUP-CASE-0002",
+ "Satisfy Number",
"The different ways a blocks number can be satisfied.",
"edu/rpi/legup/images/lightup/cases/SatisfyNumber.png");
}
@@ -40,7 +41,7 @@ public CaseBoard getCaseBoard(Board board) {
/**
* Gets the possible cases at a specific location based on this case rule
*
- * @param board the current board state
+ * @param board the current board state
* @param puzzleElement puzzleElement to determine the possible cases for
* @return a list of elements the specified could be
*/
@@ -58,8 +59,7 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) {
if (checkCell != null) {
if (checkCell.getType() == LightUpCellType.UNKNOWN && !checkCell.isLite()) {
openSpots.add(checkCell);
- }
- else {
+ } else {
if (checkCell.getType() == LightUpCellType.BULB) {
numNeeded--;
}
@@ -69,8 +69,7 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) {
if (checkCell != null) {
if (checkCell.getType() == LightUpCellType.UNKNOWN && !checkCell.isLite()) {
openSpots.add(checkCell);
- }
- else {
+ } else {
if (checkCell.getType() == LightUpCellType.BULB) {
numNeeded--;
}
@@ -80,8 +79,7 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) {
if (checkCell != null) {
if (checkCell.getType() == LightUpCellType.UNKNOWN && !checkCell.isLite()) {
openSpots.add(checkCell);
- }
- else {
+ } else {
if (checkCell.getType() == LightUpCellType.BULB) {
numNeeded--;
}
@@ -91,8 +89,7 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) {
if (checkCell != null) {
if (checkCell.getType() == LightUpCellType.UNKNOWN && !checkCell.isLite()) {
openSpots.add(checkCell);
- }
- else {
+ } else {
if (checkCell.getType() == LightUpCellType.BULB) {
numNeeded--;
}
@@ -109,7 +106,11 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) {
return cases;
}
- private void generateCases(final LightUpBoard board, final int num, List openSpots, List cases) {
+ private void generateCases(
+ final LightUpBoard board,
+ final int num,
+ List openSpots,
+ List cases) {
if (num > openSpots.size()) {
return;
}
@@ -128,7 +129,13 @@ private void generateCases(final LightUpBoard board, final int num, List openSpots, List cases, LightUpBoard curBoard, int index) {
+ private void generateCases(
+ final LightUpBoard board,
+ final int num,
+ List openSpots,
+ List cases,
+ LightUpBoard curBoard,
+ int index) {
if (num <= curBoard.getModifiedData().size()) {
cases.add(curBoard);
return;
@@ -197,8 +204,9 @@ public String checkRuleRaw(TreeTransition transition) {
boolean foundCell = false;
for (PuzzleElement posEle : posCase.getModifiedData()) {
LightUpCell posCell = (LightUpCell) posEle;
- if (actCell.getType() == posCell.getType() &&
- actCell.getLocation().equals(posCell.getLocation())) {
+ if (actCell.getType() == posCell.getType()
+ && actCell.getLocation()
+ .equals(posCell.getLocation())) {
foundCell = true;
break;
}
@@ -228,13 +236,13 @@ public String checkRuleRaw(TreeTransition transition) {
}
/**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement index of the puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
@@ -245,7 +253,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
* Gets all cells in the TreeTransition board that are adjacent to all modified cells
*
* @param transition TreeTransition object
- * @return list of cells that are adjacent to all modified cells, returns null if the number of modified cells is =0 || >4
+ * @return list of cells that are adjacent to all modified cells, returns null if the number of
+ * modified cells is =0 || >4
*/
private List getPossibleSpots(TreeTransition transition) {
LightUpBoard board = (LightUpBoard) transition.getBoard();
@@ -254,8 +263,7 @@ private List getPossibleSpots(TreeTransition transition) {
int size = modCells.size();
if (size == 0 || size > 4) {
return null;
- }
- else {
+ } else {
Iterator it = modCells.iterator();
List spots = getAdjacentCells(board, (LightUpCell) it.next());
@@ -289,33 +297,32 @@ private List getAdjacentCells(LightUpBoard board, LightUpCell cell)
}
/**
- * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid
- * Overridden by case rules dependent on more than just the modified data
+ * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be
+ * valid Overridden by case rules dependent on more than just the modified data
*
- * @param board board state at application
+ * @param board board state at application
* @param puzzleElement selected puzzleElement
- * @return List of puzzle elements (typically cells) this application of the case rule depends upon.
- * Defaults to any element modified by any case
+ * @return List of puzzle elements (typically cells) this application of the case rule depends
+ * upon. Defaults to any element modified by any case
*/
@Override
public List dependentElements(Board board, PuzzleElement puzzleElement) {
List elements = new ArrayList<>();
LightUpBoard puzzleBoard = (LightUpBoard) board;
- LightUpCell point = (LightUpCell)puzzleBoard.getPuzzleElement(puzzleElement);
+ LightUpCell point = (LightUpCell) puzzleBoard.getPuzzleElement(puzzleElement);
- List cells = getAdjacentCells(puzzleBoard,point);
+ List cells = getAdjacentCells(puzzleBoard, point);
for (LightUpCell cell : cells) {
- //add cells that can light adjacents from any direction
+ // add cells that can light adjacents from any direction
Point location = cell.getLocation();
for (int i = location.x; i < puzzleBoard.getWidth(); i++) {
System.out.println(i);
LightUpCell c = puzzleBoard.getCell(i, location.y);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
- }
- else if (!elements.contains(board.getPuzzleElement(c))) {
+ } else if (!elements.contains(board.getPuzzleElement(c))) {
elements.add(board.getPuzzleElement(c));
}
}
@@ -323,8 +330,7 @@ else if (!elements.contains(board.getPuzzleElement(c))) {
LightUpCell c = puzzleBoard.getCell(i, location.y);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
- }
- else if (!elements.contains(board.getPuzzleElement(c))) {
+ } else if (!elements.contains(board.getPuzzleElement(c))) {
elements.add(board.getPuzzleElement(c));
}
}
@@ -332,8 +338,7 @@ else if (!elements.contains(board.getPuzzleElement(c))) {
LightUpCell c = puzzleBoard.getCell(location.x, i);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
- }
- else if (!elements.contains(board.getPuzzleElement(c))) {
+ } else if (!elements.contains(board.getPuzzleElement(c))) {
elements.add(board.getPuzzleElement(c));
}
}
@@ -341,8 +346,7 @@ else if (!elements.contains(board.getPuzzleElement(c))) {
LightUpCell c = puzzleBoard.getCell(location.x, i);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
- }
- else if (!elements.contains(board.getPuzzleElement(c))) {
+ } else if (!elements.contains(board.getPuzzleElement(c))) {
elements.add(board.getPuzzleElement(c));
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooFewBulbsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooFewBulbsContradictionRule.java
index f36c4ca57..8cf68e570 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooFewBulbsContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooFewBulbsContradictionRule.java
@@ -6,24 +6,26 @@
import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import edu.rpi.legup.puzzle.lightup.LightUpCell;
import edu.rpi.legup.puzzle.lightup.LightUpCellType;
-
import java.awt.*;
public class TooFewBulbsContradictionRule extends ContradictionRule {
public TooFewBulbsContradictionRule() {
- super("LTUP-CONT-0003", "Too Few Bulbs",
+ super(
+ "LTUP-CONT-0003",
+ "Too Few Bulbs",
"There cannot be less bulbs around a block than its number states.",
"edu/rpi/legup/images/lightup/contradictions/TooFewBulbs.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooManyBulbsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooManyBulbsContradictionRule.java
index ffe7ca4d1..64cd4adcb 100644
--- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooManyBulbsContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooManyBulbsContradictionRule.java
@@ -6,24 +6,26 @@
import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import edu.rpi.legup.puzzle.lightup.LightUpCell;
import edu.rpi.legup.puzzle.lightup.LightUpCellType;
-
import java.awt.*;
public class TooManyBulbsContradictionRule extends ContradictionRule {
public TooManyBulbsContradictionRule() {
- super("LTUP-CONT-0004", "Too Many Bulbs",
+ super(
+ "LTUP-CONT-0004",
+ "Too Many Bulbs",
"There cannot be more bulbs around a block than its number states.",
"edu/rpi/legup/images/lightup/contradictions/TooManyBulbs.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/EditLineCommand.java b/src/main/java/edu/rpi/legup/puzzle/masyu/EditLineCommand.java
index 827be37ff..9986a1eda 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/EditLineCommand.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/EditLineCommand.java
@@ -1,5 +1,7 @@
package edu.rpi.legup.puzzle.masyu;
+import static edu.rpi.legup.app.GameBoardFacade.getInstance;
+
import edu.rpi.legup.history.PuzzleCommand;
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.gameboard.Board;
@@ -12,11 +14,8 @@
import edu.rpi.legup.ui.boardview.BoardView;
import edu.rpi.legup.ui.boardview.ElementView;
import edu.rpi.legup.ui.proofeditorui.treeview.*;
-
import java.awt.event.MouseEvent;
-import static edu.rpi.legup.app.GameBoardFacade.getInstance;
-
public class EditLineCommand extends PuzzleCommand {
private TreeTransition transition;
private PuzzleElement oldData;
@@ -29,7 +28,11 @@ public class EditLineCommand extends PuzzleCommand {
private TreeTransitionView transitionView;
- public EditLineCommand(ElementView elementView, TreeElementView selectedView, MouseEvent event, MasyuLine line) {
+ public EditLineCommand(
+ ElementView elementView,
+ TreeElementView selectedView,
+ MouseEvent event,
+ MasyuLine line) {
this.elementView = elementView;
this.selectedView = selectedView;
this.event = event;
@@ -38,9 +41,7 @@ public EditLineCommand(ElementView elementView, TreeElementView selectedView, Mo
this.transition = null;
}
- /**
- * Executes a command
- */
+ /** Executes a command */
@Override
public void executeCommand() {
Tree tree = getInstance().getTree();
@@ -61,18 +62,19 @@ public void executeCommand() {
}
treeNode.getChildren().add(transition);
- puzzle.notifyTreeListeners((ITreeListener listener) -> listener.onTreeElementAdded(transition));
+ puzzle.notifyTreeListeners(
+ (ITreeListener listener) -> listener.onTreeElementAdded(transition));
transitionView = (TreeTransitionView) treeView.getElementView(transition);
selection.newSelection(transitionView);
- puzzle.notifyTreeListeners((ITreeListener listener) -> listener.onTreeSelectionChanged(selection));
+ puzzle.notifyTreeListeners(
+ (ITreeListener listener) -> listener.onTreeSelectionChanged(selection));
getInstance().getLegupUI().repaintTree();
board = (MasyuBoard) transition.getBoard();
getInstance().getPuzzleModule().setCurrentBoard(board);
oldData = newData.copy();
- }
- else {
+ } else {
transitionView = (TreeTransitionView) selectedView;
transition = transitionView.getTreeElement();
}
@@ -100,13 +102,14 @@ public void executeCommand() {
System.out.println("delete");
board.getModifiedData().remove(dup_line);
board.getLines().remove(dup_line);
-// puzzle.notifyBoardListeners((IBoardListener listener) -> listener.onTreeElementChanged(editBoard));
- }
- else {
+ // puzzle.notifyBoardListeners((IBoardListener listener) ->
+ // listener.onTreeElementChanged(editBoard));
+ } else {
System.out.println("adding");
board.getModifiedData().add(newData);
board.getLines().add((MasyuLine) newData);
-// puzzle.notifyBoardListeners((IBoardListener listener) -> listener.onTreeElementChanged(editBoard));
+ // puzzle.notifyBoardListeners((IBoardListener listener) ->
+ // listener.onTreeElementChanged(editBoard));
}
transition.propagateChange(newData);
@@ -116,15 +119,14 @@ public void executeCommand() {
* Gets the reason why the command cannot be executed
*
* @return if command cannot be executed, returns reason for why the command cannot be executed,
- * otherwise null if command can be executed
+ * otherwise null if command can be executed
*/
@Override
public String getErrorString() {
Board board = selectedView.getTreeElement().getBoard();
if (!board.isModifiable()) {
return "Board is not modifiable";
- }
- else {
+ } else {
if (!board.getPuzzleElement(elementView.getPuzzleElement()).isModifiable()) {
return "Data is not modifiable";
}
@@ -132,9 +134,7 @@ public String getErrorString() {
return null;
}
- /**
- * Undoes an command
- */
+ /** Undoes an command */
@Override
public void undoCommand() {
Tree tree = getInstance().getTree();
@@ -156,17 +156,16 @@ public void undoCommand() {
getInstance().getPuzzleModule().setCurrentBoard(treeNode.getBoard());
}
- Board prevBoard = null;// transition.getParentNode().getBoard();
+ Board prevBoard = null; // transition.getParentNode().getBoard();
newData.setData(oldData.getData());
board.notifyChange(newData);
- //System.err.println(newData.getData() + " : " + oldData.getData());
+ // System.err.println(newData.getData() + " : " + oldData.getData());
if (prevBoard.getPuzzleElement(elementView.getPuzzleElement()).equalsData(newData)) {
board.removeModifiedData(newData);
- }
- else {
+ } else {
board.addModifiedData(newData);
}
transition.propagateChange(newData);
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/Masyu.java b/src/main/java/edu/rpi/legup/puzzle/masyu/Masyu.java
index b339630e9..1ab74d56b 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/Masyu.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/Masyu.java
@@ -14,12 +14,9 @@ public Masyu() {
this.exporter = new MasyuExporter(this);
this.factory = new MasyuCellFactory();
-
}
- /**
- * Initializes the game board. Called by the invoker of the class
- */
+ /** Initializes the game board. Called by the invoker of the class */
@Override
public void initializeView() {
boardView = new MasyuView((MasyuBoard) currentBoard);
@@ -40,8 +37,8 @@ public Board generatePuzzle(int difficulty) {
/**
* Determines if the given dimensions are valid for Masyu
*
- * @param rows the number of rows
- * @param columns the number of columns
+ * @param rows the number of rows
+ * @param columns the number of columns
* @return true if the given dimensions are valid for Masyu, false otherwise
*/
public boolean isValidDimensions(int rows, int columns) {
@@ -66,7 +63,5 @@ public boolean isBoardComplete(Board board) {
* @param board the board that has changed
*/
@Override
- public void onBoardChange(Board board) {
-
- }
+ public void onBoardChange(Board board) {}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuBoard.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuBoard.java
index 96183bcfe..f347ff4c4 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuBoard.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuBoard.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.gameboard.GridBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-
import java.util.ArrayList;
import java.util.List;
@@ -36,8 +35,7 @@ public void setLines(List lines) {
public void notifyChange(PuzzleElement puzzleElement) {
if (puzzleElement instanceof MasyuLine) {
lines.add((MasyuLine) puzzleElement);
- }
- else {
+ } else {
super.notifyChange(puzzleElement);
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCell.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCell.java
index af32dbfb6..af0811c55 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCell.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCell.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.puzzle.masyu;
import edu.rpi.legup.model.gameboard.GridCell;
-
import java.awt.*;
public class MasyuCell extends GridCell {
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java
index 5278e0036..50e3c4cc0 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java
@@ -4,17 +4,16 @@
import edu.rpi.legup.model.gameboard.ElementFactory;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.awt.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import java.awt.*;
-
public class MasyuCellFactory extends ElementFactory {
/**
* Creates a puzzleElement based on the xml document Node and adds it to the board
*
- * @param node node that represents the puzzleElement
+ * @param node node that represents the puzzleElement
* @param board board to add the newly created cell
* @return newly created cell from the xml document Node
* @throws InvalidFileFormatException if file is invalid
@@ -23,7 +22,8 @@ public class MasyuCellFactory extends ElementFactory {
public MasyuCell importCell(Node node, Board board) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("cell")) {
- throw new InvalidFileFormatException("Masyu Factory: unknown puzzleElement puzzleElement");
+ throw new InvalidFileFormatException(
+ "Masyu Factory: unknown puzzleElement puzzleElement");
}
MasyuBoard masyuBoard = (MasyuBoard) board;
@@ -44,11 +44,10 @@ public MasyuCell importCell(Node node, Board board) throws InvalidFileFormatExce
MasyuCell cell = new MasyuCell(MasyuType.convertToMasyuType(value), new Point(x, y));
cell.setIndex(y * height + x);
return cell;
- }
- catch (NumberFormatException e) {
- throw new InvalidFileFormatException("Masyu Factory: unknown value where integer expected");
- }
- catch (NullPointerException e) {
+ } catch (NumberFormatException e) {
+ throw new InvalidFileFormatException(
+ "Masyu Factory: unknown value where integer expected");
+ } catch (NullPointerException e) {
throw new InvalidFileFormatException("Masyu Factory: could not find attribute(s)");
}
}
@@ -56,7 +55,7 @@ public MasyuCell importCell(Node node, Board board) throws InvalidFileFormatExce
/**
* Creates a xml document puzzleElement from a cell for exporting
*
- * @param document xml document
+ * @param document xml document
* @param puzzleElement PuzzleElement cell
* @return xml PuzzleElement
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuController.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuController.java
index 02328c691..202c43a1e 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuController.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuController.java
@@ -1,18 +1,17 @@
package edu.rpi.legup.puzzle.masyu;
+import static edu.rpi.legup.app.GameBoardFacade.getInstance;
+
import edu.rpi.legup.app.GameBoardFacade;
import edu.rpi.legup.controller.ElementController;
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.ui.boardview.BoardView;
-
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
-import static edu.rpi.legup.app.GameBoardFacade.getInstance;
-
public class MasyuController extends ElementController {
private MasyuElementView mousePressedCell;
@@ -52,19 +51,25 @@ public void mouseDragged(MouseEvent e) {
if (Math.abs(p1.x - p2.x) == 1 ^ Math.abs(p1.y - p2.y) == 1) {
masyuLine.add(elementView);
- MasyuLine newLine = new MasyuLine(mousePressedCell.getPuzzleElement(), mouseDraggedCell.getPuzzleElement());
+ MasyuLine newLine =
+ new MasyuLine(
+ mousePressedCell.getPuzzleElement(),
+ mouseDraggedCell.getPuzzleElement());
puzzle.notifyBoardListeners(listener -> listener.onBoardDataChanged(newLine));
}
- }
- else {
+ } else {
if (mouseDraggedCell != elementView) {
Point p1 = mouseDraggedCell.getPuzzleElement().getLocation();
Point p2 = elementView.getPuzzleElement().getLocation();
if (Math.abs(p1.x - p2.x) == 1 ^ Math.abs(p1.y - p2.y) == 1) {
masyuLine.add(elementView);
- MasyuLine newLine = new MasyuLine(mouseDraggedCell.getPuzzleElement(), elementView.getPuzzleElement());
- puzzle.notifyBoardListeners(listener -> listener.onBoardDataChanged(newLine));
+ MasyuLine newLine =
+ new MasyuLine(
+ mouseDraggedCell.getPuzzleElement(),
+ elementView.getPuzzleElement());
+ puzzle.notifyBoardListeners(
+ listener -> listener.onBoardDataChanged(newLine));
}
mouseDraggedCell = elementView;
}
@@ -83,7 +88,7 @@ public void mouseReleased(MouseEvent e) {
/**
* Alters the cells as they are being dragged over or clicked
*
- * @param e Mouse event being used
+ * @param e Mouse event being used
* @param data Data of selected cell
*/
@Override
@@ -94,8 +99,7 @@ public void changeCell(MouseEvent e, PuzzleElement data) {
}
if (cell.getData() == MasyuType.UNKNOWN) {
data.setData(3);
- }
- else {
+ } else {
data.setData(0);
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuElementView.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuElementView.java
index b2f1f8902..942e1ffd2 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuElementView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuElementView.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.puzzle.masyu;
import edu.rpi.legup.ui.boardview.GridElementView;
-
import java.awt.*;
public class MasyuElementView extends GridElementView {
@@ -24,8 +23,7 @@ public void drawElement(Graphics2D graphics2D) {
graphics2D.fillRect(location.x, location.y, size.width, size.height);
graphics2D.setColor(Color.BLACK);
graphics2D.drawRect(location.x, location.y, size.width, size.height);
- }
- else {
+ } else {
if (type == MasyuType.BLACK) {
graphics2D.setStroke(new BasicStroke(1));
graphics2D.setColor(Color.LIGHT_GRAY);
@@ -34,8 +32,7 @@ public void drawElement(Graphics2D graphics2D) {
graphics2D.fillOval(location.x + 5, location.y + 5, 20, 20);
graphics2D.setColor(Color.BLACK);
graphics2D.drawRect(location.x, location.y, size.width, size.height);
- }
- else {
+ } else {
if (type == MasyuType.WHITE) {
graphics2D.setStroke(new BasicStroke(2));
graphics2D.setColor(Color.LIGHT_GRAY);
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java
index e5fb071b4..0c692193a 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.PuzzleExporter;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard;
import org.w3c.dom.Document;
public class MasyuExporter extends PuzzleExporter {
@@ -16,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
MasyuBoard board;
if (puzzle.getTree() != null) {
board = (MasyuBoard) puzzle.getTree().getRootNode().getBoard();
- }
- else {
+ } else {
board = (MasyuBoard) puzzle.getBoardView().getBoard();
}
@@ -28,7 +26,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
org.w3c.dom.Element cellsElement = newDocument.createElement("cells");
for (PuzzleElement puzzleElement : board.getPuzzleElements()) {
MasyuCell cell = (MasyuCell) puzzleElement;
- org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement);
+ org.w3c.dom.Element cellElement =
+ puzzle.getFactory().exportCell(newDocument, puzzleElement);
cellsElement.appendChild(cellElement);
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java
index 3e0d328c4..2170da3ee 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java
@@ -2,12 +2,11 @@
import edu.rpi.legup.model.PuzzleImporter;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.awt.*;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import java.awt.*;
-
public class MasyuImporter extends PuzzleImporter {
public MasyuImporter(Masyu masyu) {
super(masyu);
@@ -26,14 +25,12 @@ public boolean acceptsTextInput() {
/**
* Creates an empty board for building
*
- * @param rows the number of rows on the board
+ * @param rows the number of rows on the board
* @param columns the number of columns on the board
* @throws RuntimeException if board can not be created
*/
@Override
- public void initializeBoard(int rows, int columns) {
-
- }
+ public void initializeBoard(int rows, int columns) {}
/**
* Creates the board for building
@@ -45,11 +42,13 @@ public void initializeBoard(int rows, int columns) {
public void initializeBoard(Node node) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("board")) {
- throw new InvalidFileFormatException("Masyu Importer: cannot find board puzzleElement");
+ throw new InvalidFileFormatException(
+ "Masyu Importer: cannot find board puzzleElement");
}
Element boardElement = (Element) node;
if (boardElement.getElementsByTagName("cells").getLength() == 0) {
- throw new InvalidFileFormatException("Masyu Importer: no puzzleElement found for board");
+ throw new InvalidFileFormatException(
+ "Masyu Importer: no puzzleElement found for board");
}
Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0);
NodeList elementDataList = dataElement.getElementsByTagName("cell");
@@ -58,9 +57,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
if (!boardElement.getAttribute("size").isEmpty()) {
int size = Integer.valueOf(boardElement.getAttribute("size"));
masyuBoard = new MasyuBoard(size);
- }
- else {
- if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) {
+ } else {
+ if (!boardElement.getAttribute("width").isEmpty()
+ && !boardElement.getAttribute("height").isEmpty()) {
int width = Integer.valueOf(boardElement.getAttribute("width"));
int height = Integer.valueOf(boardElement.getAttribute("height"));
masyuBoard = new MasyuBoard(width, height);
@@ -75,7 +74,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
int height = masyuBoard.getHeight();
for (int i = 0; i < elementDataList.getLength(); i++) {
- MasyuCell cell = (MasyuCell) puzzle.getFactory().importCell(elementDataList.item(i), masyuBoard);
+ MasyuCell cell =
+ (MasyuCell)
+ puzzle.getFactory().importCell(elementDataList.item(i), masyuBoard);
Point loc = cell.getLocation();
if (cell.getData() != MasyuType.UNKNOWN) {
cell.setModifiable(false);
@@ -95,9 +96,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
}
}
puzzle.setCurrentBoard(masyuBoard);
- }
- catch (NumberFormatException e) {
- throw new InvalidFileFormatException("Masyu Importer: unknown value where integer expected");
+ } catch (NumberFormatException e) {
+ throw new InvalidFileFormatException(
+ "Masyu Importer: unknown value where integer expected");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLine.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLine.java
index d8c3240c7..eda51c839 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLine.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLine.java
@@ -25,8 +25,10 @@ public void setC2(MasyuCell c2) {
}
public boolean compare(MasyuLine line) {
- return ((line.getC1().getLocation().equals(data.getKey().getLocation()) && line.getC2().getLocation().equals(data.getValue().getLocation())) ||
- (line.getC1().getLocation().equals(data.getValue().getLocation()) && line.getC2().getLocation().equals(data.getKey().getLocation())));
+ return ((line.getC1().getLocation().equals(data.getKey().getLocation())
+ && line.getC2().getLocation().equals(data.getValue().getLocation()))
+ || (line.getC1().getLocation().equals(data.getValue().getLocation())
+ && line.getC2().getLocation().equals(data.getKey().getLocation())));
}
/**
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLineView.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLineView.java
index d527ca414..c967f4865 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLineView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLineView.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.puzzle.masyu;
import edu.rpi.legup.ui.boardview.ElementView;
-
import java.awt.*;
public class MasyuLineView extends ElementView {
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuType.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuType.java
index 264350a95..4029d259d 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuType.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuType.java
@@ -1,9 +1,10 @@
package edu.rpi.legup.puzzle.masyu;
-import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType;
-
public enum MasyuType {
- UNKNOWN, BLACK, WHITE, LINE;
+ UNKNOWN,
+ BLACK,
+ WHITE,
+ LINE;
public static MasyuType convertToMasyuType(int num) {
switch (num) {
@@ -18,4 +19,3 @@ public static MasyuType convertToMasyuType(int num) {
}
}
}
-
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuView.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuView.java
index ac60dbe66..e962a6ebf 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuView.java
@@ -3,7 +3,6 @@
import edu.rpi.legup.controller.BoardController;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.ui.boardview.GridBoardView;
-
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
@@ -20,7 +19,8 @@ public MasyuView(MasyuBoard board) {
MasyuElementView elementView = new MasyuElementView(cell);
elementView.setIndex(cell.getIndex());
elementView.setSize(elementSize);
- elementView.setLocation(new Point(loc.x * elementSize.width, loc.y * elementSize.height));
+ elementView.setLocation(
+ new Point(loc.x * elementSize.width, loc.y * elementSize.height));
elementViews.add(elementView);
}
lineViews = new ArrayList<>();
@@ -33,7 +33,8 @@ public MasyuView(MasyuBoard board) {
@Override
public void drawBoard(Graphics2D graphics2D) {
- graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ graphics2D.setRenderingHint(
+ RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
super.drawBoard(graphics2D);
lineViews.forEach(masyuLineView -> masyuLineView.draw(graphics2D));
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BadLoopingContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BadLoopingContradictionRule.java
index 0da4dffe2..1681446cd 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BadLoopingContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BadLoopingContradictionRule.java
@@ -7,18 +7,21 @@
public class BadLoopingContradictionRule extends ContradictionRule {
public BadLoopingContradictionRule() {
- super("MASY-CONT-0001", "Bad Looping",
+ super(
+ "MASY-CONT-0001",
+ "Bad Looping",
"",
"edu/rpi/legup/images/masyu/ContradictionBadLooping.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackContradictionRule.java
index b4d32a46a..c219eeaa3 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackContradictionRule.java
@@ -7,18 +7,17 @@
public class BlackContradictionRule extends ContradictionRule {
public BlackContradictionRule() {
- super("MASY-CONT-0002", "Black",
- "",
- "edu/rpi/legup/images/masyu/ContradictionBlack.png");
+ super("MASY-CONT-0002", "Black", "", "edu/rpi/legup/images/masyu/ContradictionBlack.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackEdgeDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackEdgeDirectRule.java
index b35dceaa7..665a74204 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackEdgeDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackEdgeDirectRule.java
@@ -1,42 +1,41 @@
-package edu.rpi.legup.puzzle.masyu.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class BlackEdgeDirectRule extends DirectRule {
-
- public BlackEdgeDirectRule() {
- super("MASY-BASC-0001", "Black Edge",
- "",
- "edu/rpi/legup/images/masyu/RuleBlackEdge.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.masyu.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class BlackEdgeDirectRule extends DirectRule {
+
+ public BlackEdgeDirectRule() {
+ super("MASY-BASC-0001", "Black Edge", "", "edu/rpi/legup/images/masyu/RuleBlackEdge.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackSplitCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackSplitCaseRule.java
index 3db89ef58..c7e3ff500 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackSplitCaseRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackSplitCaseRule.java
@@ -5,20 +5,17 @@
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.tree.TreeTransition;
-
import java.util.List;
public class BlackSplitCaseRule extends CaseRule {
public BlackSplitCaseRule() {
- super("MASY-CASE-0001", "Black Split",
- "",
- "edu/rpi/legup/images/masyu/CaseBlackSplit.png");
+ super("MASY-CASE-0001", "Black Split", "", "edu/rpi/legup/images/masyu/CaseBlackSplit.png");
}
/**
- * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is
- * the one that should overridden in child classes.
+ * Checks whether the {@link TreeTransition} logically follows from the parent node using this
+ * rule. This method is the one that should overridden in child classes.
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
@@ -29,13 +26,14 @@ public String checkRuleRaw(TreeTransition transition) {
}
/**
- * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using
- * this rule. This method is the one that should overridden in child classes.
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule. This method is the one that should overridden in child
+ * classes.
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
@@ -43,7 +41,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
}
/**
- * Gets the case board that indicates where this case rule can be applied on the given {@link Board}.
+ * Gets the case board that indicates where this case rule can be applied on the given {@link
+ * Board}.
*
* @param board board to find locations where this case rule can be applied
* @return a case board
@@ -54,9 +53,10 @@ public CaseBoard getCaseBoard(Board board) {
}
/**
- * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule.
+ * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on
+ * this case rule.
*
- * @param board the current board state
+ * @param board the current board state
* @param puzzleElement equivalent puzzleElement
* @return a list of elements the specified could be
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlockedBlackDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlockedBlackDirectRule.java
index 4364d016c..5c284eb45 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlockedBlackDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlockedBlackDirectRule.java
@@ -1,42 +1,45 @@
-package edu.rpi.legup.puzzle.masyu.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class BlockedBlackDirectRule extends DirectRule {
-
- public BlockedBlackDirectRule() {
- super("MASY-BASC-0002", "Blocked Black",
- "",
- "edu/rpi/legup/images/masyu/RuleBlockedBlack.gif");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.masyu.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class BlockedBlackDirectRule extends DirectRule {
+
+ public BlockedBlackDirectRule() {
+ super(
+ "MASY-BASC-0002",
+ "Blocked Black",
+ "",
+ "edu/rpi/legup/images/masyu/RuleBlockedBlack.gif");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/ConnectedCellsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/ConnectedCellsDirectRule.java
index 49949ecec..6aee8ba5f 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/ConnectedCellsDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/ConnectedCellsDirectRule.java
@@ -1,42 +1,45 @@
-package edu.rpi.legup.puzzle.masyu.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class ConnectedCellsDirectRule extends DirectRule {
-
- public ConnectedCellsDirectRule() {
- super("MASY-BASC-0003", "Connected Cells",
- "",
- "edu/rpi/legup/images/masyu/RuleConnectedCells.gif");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.masyu.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class ConnectedCellsDirectRule extends DirectRule {
+
+ public ConnectedCellsDirectRule() {
+ super(
+ "MASY-BASC-0003",
+ "Connected Cells",
+ "",
+ "edu/rpi/legup/images/masyu/RuleConnectedCells.gif");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/FinishPathDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/FinishPathDirectRule.java
index e04301ce2..27b39bc04 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/FinishPathDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/FinishPathDirectRule.java
@@ -1,42 +1,45 @@
-package edu.rpi.legup.puzzle.masyu.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class FinishPathDirectRule extends DirectRule {
-
- public FinishPathDirectRule() {
- super("MASY-BASC-0004", "Finished Path",
- "",
- "edu/rpi/legup/images/masyu/RuleFinishPath.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.masyu.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class FinishPathDirectRule extends DirectRule {
+
+ public FinishPathDirectRule() {
+ super(
+ "MASY-BASC-0004",
+ "Finished Path",
+ "",
+ "edu/rpi/legup/images/masyu/RuleFinishPath.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NearWhiteDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NearWhiteDirectRule.java
index 7cf707d0d..6a565bc82 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NearWhiteDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NearWhiteDirectRule.java
@@ -1,42 +1,41 @@
-package edu.rpi.legup.puzzle.masyu.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class NearWhiteDirectRule extends DirectRule {
-
- public NearWhiteDirectRule() {
- super("MASY-BASC-0005", "Near White",
- "",
- "edu/rpi/legup/images/masyu/RuleNearWhite.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.masyu.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class NearWhiteDirectRule extends DirectRule {
+
+ public NearWhiteDirectRule() {
+ super("MASY-BASC-0005", "Near White", "", "edu/rpi/legup/images/masyu/RuleNearWhite.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NoOptionsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NoOptionsContradictionRule.java
index 19da790aa..c41999b9c 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NoOptionsContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NoOptionsContradictionRule.java
@@ -7,18 +7,21 @@
public class NoOptionsContradictionRule extends ContradictionRule {
public NoOptionsContradictionRule() {
- super("MASY-CONT-0003", "No Options",
+ super(
+ "MASY-CONT-0003",
+ "No Options",
"",
"edu/rpi/legup/images/masyu/ContradictionNoOptions.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NormalSplitCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NormalSplitCaseRule.java
index ab47adc1b..382ac6466 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NormalSplitCaseRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NormalSplitCaseRule.java
@@ -5,20 +5,21 @@
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.tree.TreeTransition;
-
import java.util.List;
public class NormalSplitCaseRule extends CaseRule {
public NormalSplitCaseRule() {
- super("MASY-CASE-0002", "Normal Split",
+ super(
+ "MASY-CASE-0002",
+ "Normal Split",
"",
"edu/rpi/legup/images/masyu/CaseNormalSplit.png");
}
/**
- * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is
- * the one that should overridden in child classes.
+ * Checks whether the {@link TreeTransition} logically follows from the parent node using this
+ * rule. This method is the one that should overridden in child classes.
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
@@ -29,13 +30,14 @@ public String checkRuleRaw(TreeTransition transition) {
}
/**
- * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using
- * this rule. This method is the one that should overridden in child classes.
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule. This method is the one that should overridden in child
+ * classes.
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
@@ -43,7 +45,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
}
/**
- * Gets the case board that indicates where this case rule can be applied on the given {@link Board}.
+ * Gets the case board that indicates where this case rule can be applied on the given {@link
+ * Board}.
*
* @param board board to find locations where this case rule can be applied
* @return a case board
@@ -54,9 +57,10 @@ public CaseBoard getCaseBoard(Board board) {
}
/**
- * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule.
+ * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on
+ * this case rule.
*
- * @param board the current board state
+ * @param board the current board state
* @param puzzleElement equivalent puzzleElement
* @return a list of elements the specified could be
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyOneChoiceDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyOneChoiceDirectRule.java
index b0311e741..bc7353e5d 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyOneChoiceDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyOneChoiceDirectRule.java
@@ -1,42 +1,45 @@
-package edu.rpi.legup.puzzle.masyu.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class OnlyOneChoiceDirectRule extends DirectRule {
-
- public OnlyOneChoiceDirectRule() {
- super("MASY-BASC-0006", "Only One Choice",
- "",
- "edu/rpi/legup/images/masyu/RuleOnlyOneChoice.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.masyu.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class OnlyOneChoiceDirectRule extends DirectRule {
+
+ public OnlyOneChoiceDirectRule() {
+ super(
+ "MASY-BASC-0006",
+ "Only One Choice",
+ "",
+ "edu/rpi/legup/images/masyu/RuleOnlyOneChoice.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyTwoContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyTwoContradictionRule.java
index ab587a0ec..ee71ee2bc 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyTwoContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyTwoContradictionRule.java
@@ -7,18 +7,21 @@
public class OnlyTwoContradictionRule extends ContradictionRule {
public OnlyTwoContradictionRule() {
- super("MASY-CONT-0004", "Only Two",
+ super(
+ "MASY-CONT-0004",
+ "Only Two",
"",
"edu/rpi/legup/images/masyu/ContradictionOnly2.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteContradictionRule.java
index 091c2b039..efc523b8d 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteContradictionRule.java
@@ -7,18 +7,17 @@
public class WhiteContradictionRule extends ContradictionRule {
public WhiteContradictionRule() {
- super("MASY-CONT-0005", "White",
- "",
- "edu/rpi/legup/images/masyu/ContradictionWhite.png");
+ super("MASY-CONT-0005", "White", "", "edu/rpi/legup/images/masyu/ContradictionWhite.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteEdgeDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteEdgeDirectRule.java
index bd894e1d4..4d2982d00 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteEdgeDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteEdgeDirectRule.java
@@ -1,41 +1,40 @@
-package edu.rpi.legup.puzzle.masyu.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-
-public class WhiteEdgeDirectRule extends DirectRule {
- public WhiteEdgeDirectRule() {
- super("MASY-BASC-0007", "White Edge",
- "",
- "edu/rpi/legup/images/masyu/RuleWhiteEdge.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- * This method is the one that should overridden in child classes
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.masyu.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+
+public class WhiteEdgeDirectRule extends DirectRule {
+ public WhiteEdgeDirectRule() {
+ super("MASY-BASC-0007", "White Edge", "", "edu/rpi/legup/images/masyu/RuleWhiteEdge.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule This method is the one that should overridden in child
+ * classes
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteSplitCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteSplitCaseRule.java
index e45fde0a1..d50ddacfa 100644
--- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteSplitCaseRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteSplitCaseRule.java
@@ -5,20 +5,17 @@
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.tree.TreeTransition;
-
import java.util.List;
public class WhiteSplitCaseRule extends CaseRule {
public WhiteSplitCaseRule() {
- super("MASY-CASE-0003", "White Split",
- "",
- "edu/rpi/legup/images/masyu/CaseWhiteSplit.png");
+ super("MASY-CASE-0003", "White Split", "", "edu/rpi/legup/images/masyu/CaseWhiteSplit.png");
}
/**
- * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is
- * the one that should overridden in child classes.
+ * Checks whether the {@link TreeTransition} logically follows from the parent node using this
+ * rule. This method is the one that should overridden in child classes.
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
@@ -29,13 +26,14 @@ public String checkRuleRaw(TreeTransition transition) {
}
/**
- * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using
- * this rule. This method is the one that should overridden in child classes.
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule. This method is the one that should overridden in child
+ * classes.
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
@@ -43,7 +41,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
}
/**
- * Gets the case board that indicates where this case rule can be applied on the given {@link Board}.
+ * Gets the case board that indicates where this case rule can be applied on the given {@link
+ * Board}.
*
* @param board board to find locations where this case rule can be applied
* @return a case board
@@ -54,9 +53,10 @@ public CaseBoard getCaseBoard(Board board) {
}
/**
- * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule.
+ * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on
+ * this case rule.
*
- * @param board the current board state
+ * @param board the current board state
* @param puzzleElement equivalent puzzleElement
* @return a list of elements the specified could be
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java
index 2edbcb039..8366d905f 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java
@@ -17,9 +17,7 @@ public Nurikabe() {
this.factory = new NurikabeCellFactory();
}
- /**
- * Initializes the game board. Called by the invoker of the class
- */
+ /** Initializes the game board. Called by the invoker of the class */
@Override
public void initializeView() {
boardView = new NurikabeView((NurikabeBoard) currentBoard);
@@ -42,8 +40,8 @@ public Board generatePuzzle(int difficulty) {
/**
* Determines if the given dimensions are valid for Nurikabe
*
- * @param rows the number of rows
- * @param columns the number of columns
+ * @param rows the number of rows
+ * @param columns the number of columns
* @return true if the given dimensions are valid for Nurikabe, false otherwise
*/
public boolean isValidDimensions(int rows, int columns) {
@@ -80,7 +78,5 @@ public boolean isBoardComplete(Board board) {
* @param board the board that has changed
*/
@Override
- public void onBoardChange(Board board) {
-
- }
+ public void onBoardChange(Board board) {}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeBoard.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeBoard.java
index d5b83d1e8..1f80611e8 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeBoard.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeBoard.java
@@ -1,6 +1,5 @@
package edu.rpi.legup.puzzle.nurikabe;
-import edu.rpi.legup.model.elements.Element;
import edu.rpi.legup.model.gameboard.GridBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;
@@ -15,8 +14,11 @@ public NurikabeBoard(int size) {
@Override
public NurikabeCell getCell(int x, int y) {
- if (y * dimension.width + x >= puzzleElements.size() || x >= dimension.width ||
- y >= dimension.height || x < 0 || y < 0) {
+ if (y * dimension.width + x >= puzzleElements.size()
+ || x >= dimension.width
+ || y >= dimension.height
+ || x < 0
+ || y < 0) {
return null;
}
return (NurikabeCell) super.getCell(x, y);
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java
index f84a3c9f1..c6cd2c64e 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java
@@ -1,8 +1,7 @@
package edu.rpi.legup.puzzle.nurikabe;
-import edu.rpi.legup.model.gameboard.GridCell;
import edu.rpi.legup.model.elements.Element;
-
+import edu.rpi.legup.model.gameboard.GridCell;
import java.awt.*;
import java.awt.event.MouseEvent;
@@ -11,7 +10,7 @@ public class NurikabeCell extends GridCell {
/**
* NurikabeCell Constructor - creates a NurikabeCell from the specified value and location
*
- * @param value value of the NurikabeCell
+ * @param value value of the NurikabeCell
* @param location position of the NurikabeCell
*/
public NurikabeCell(int value, Point location) {
@@ -46,7 +45,7 @@ public NurikabeType getType() {
*/
@Override
public void setType(Element e, MouseEvent m) {
- switch (e.getElementID()){
+ switch (e.getElementID()) {
case "NURI-PLAC-0001":
this.data = -1;
break;
@@ -54,20 +53,18 @@ public void setType(Element e, MouseEvent m) {
this.data = 0;
break;
case "NURI-UNPL-0001":
- switch (m.getButton()){
+ switch (m.getButton()) {
case MouseEvent.BUTTON1:
if (this.data <= 0 || this.data > 8) {
this.data = 1;
- }
- else {
+ } else {
this.data = this.data + 1;
}
break;
case MouseEvent.BUTTON3:
if (this.data > 1) {
this.data = this.data - 1;
- }
- else {
+ } else {
this.data = 9;
}
break;
@@ -92,4 +89,4 @@ public NurikabeCell copy() {
copy.setGiven(isGiven);
return copy;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java
index b754f3e46..7241608ac 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java
@@ -4,17 +4,16 @@
import edu.rpi.legup.model.gameboard.ElementFactory;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.awt.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import java.awt.*;
-
public class NurikabeCellFactory extends ElementFactory {
/**
* Creates a puzzleElement based on the xml document Node and adds it to the board
*
- * @param node node that represents the puzzleElement
+ * @param node node that represents the puzzleElement
* @param board board to add the newly created cell
* @return newly created cell from the xml document Node
* @throws InvalidFileFormatException if file is invalid
@@ -23,7 +22,8 @@ public class NurikabeCellFactory extends ElementFactory {
public NurikabeCell importCell(Node node, Board board) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("cell")) {
- throw new InvalidFileFormatException("nurikabe Factory: unknown puzzleElement puzzleElement");
+ throw new InvalidFileFormatException(
+ "nurikabe Factory: unknown puzzleElement puzzleElement");
}
NurikabeBoard nurikabeBoard = (NurikabeBoard) board;
@@ -35,7 +35,8 @@ public NurikabeCell importCell(Node node, Board board) throws InvalidFileFormatE
int x = Integer.valueOf(attributeList.getNamedItem("x").getNodeValue());
int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue());
if (x >= width || y >= height) {
- throw new InvalidFileFormatException("nurikabe Factory: cell location out of bounds");
+ throw new InvalidFileFormatException(
+ "nurikabe Factory: cell location out of bounds");
}
if (value < -2) {
throw new InvalidFileFormatException("nurikabe Factory: cell unknown value");
@@ -44,11 +45,10 @@ public NurikabeCell importCell(Node node, Board board) throws InvalidFileFormatE
NurikabeCell cell = new NurikabeCell(value, new Point(x, y));
cell.setIndex(y * height + x);
return cell;
- }
- catch (NumberFormatException e) {
- throw new InvalidFileFormatException("nurikabe Factory: unknown value where integer expected");
- }
- catch (NullPointerException e) {
+ } catch (NumberFormatException e) {
+ throw new InvalidFileFormatException(
+ "nurikabe Factory: unknown value where integer expected");
+ } catch (NullPointerException e) {
throw new InvalidFileFormatException("nurikabe Factory: could not find attribute(s)");
}
}
@@ -56,7 +56,7 @@ public NurikabeCell importCell(Node node, Board board) throws InvalidFileFormatE
/**
* Creates a xml document puzzleElement from a cell for exporting
*
- * @param document xml document
+ * @param document xml document
* @param puzzleElement PuzzleElement cell
* @return xml PuzzleElement
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeController.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeController.java
index c115498a8..158abe7b4 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeController.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeController.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.controller.ElementController;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-
import java.awt.event.MouseEvent;
public class NurikabeController extends ElementController {
@@ -12,32 +11,31 @@ public void changeCell(MouseEvent e, PuzzleElement data) {
NurikabeCell cell = (NurikabeCell) data;
if (e.getButton() == MouseEvent.BUTTON1) {
if (e.isControlDown()) {
- this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY());
- }
- else {
+ this.boardView
+ .getSelectionPopupMenu()
+ .show(
+ boardView,
+ this.boardView.getCanvas().getX() + e.getX(),
+ this.boardView.getCanvas().getY() + e.getY());
+ } else {
if (cell.getData() == -2) {
data.setData(0);
- }
- else {
+ } else {
if (cell.getData() == 0) {
data.setData(-1);
- }
- else {
+ } else {
data.setData(-2);
}
}
}
- }
- else {
+ } else {
if (e.getButton() == MouseEvent.BUTTON3) {
if (cell.getData() == -2) {
data.setData(-1);
- }
- else {
+ } else {
if (cell.getData() == 0) {
data.setData(-2);
- }
- else {
+ } else {
data.setData(0);
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeElementView.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeElementView.java
index f122a7a5b..116b727d2 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeElementView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeElementView.java
@@ -1,7 +1,6 @@
package edu.rpi.legup.puzzle.nurikabe;
import edu.rpi.legup.ui.boardview.GridElementView;
-
import java.awt.*;
public class NurikabeElementView extends GridElementView {
@@ -40,24 +39,22 @@ public void drawElement(Graphics2D graphics2D) {
FontMetrics metrics = graphics2D.getFontMetrics(FONT);
String value = String.valueOf(puzzleElement.getData());
int xText = location.x + (size.width - metrics.stringWidth(value)) / 2;
- int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent();
+ int yText =
+ location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent();
graphics2D.drawString(String.valueOf(puzzleElement.getData()), xText, yText);
- }
- else {
+ } else {
if (type == NurikabeType.BLACK) {
graphics2D.setStroke(new BasicStroke(1));
graphics2D.setColor(Color.BLACK);
graphics2D.fillRect(location.x, location.y, size.width, size.height);
- }
- else {
+ } else {
if (type == NurikabeType.WHITE) {
graphics2D.setStroke(new BasicStroke(1));
graphics2D.setColor(Color.WHITE);
graphics2D.fillRect(location.x, location.y, size.width, size.height);
graphics2D.setColor(Color.BLACK);
graphics2D.drawRect(location.x, location.y, size.width, size.height);
- }
- else {
+ } else {
if (type == NurikabeType.UNKNOWN) {
graphics2D.setStroke(new BasicStroke(1));
graphics2D.setColor(Color.LIGHT_GRAY);
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeExporter.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeExporter.java
index 095642a6e..23efd4724 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeExporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeExporter.java
@@ -15,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
NurikabeBoard board;
if (puzzle.getTree() != null) {
board = (NurikabeBoard) puzzle.getTree().getRootNode().getBoard();
- }
- else {
+ } else {
board = (NurikabeBoard) puzzle.getBoardView().getBoard();
}
@@ -28,7 +27,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
for (PuzzleElement puzzleElement : board.getPuzzleElements()) {
NurikabeCell cell = (NurikabeCell) puzzleElement;
if (cell.getData() != -2) {
- org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement);
+ org.w3c.dom.Element cellElement =
+ puzzle.getFactory().exportCell(newDocument, puzzleElement);
cellsElement.appendChild(cellElement);
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java
index 2cbcc9ad0..ec4ed3ac1 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java
@@ -2,12 +2,11 @@
import edu.rpi.legup.model.PuzzleImporter;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.awt.*;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import java.awt.*;
-
public class NurikabeImporter extends PuzzleImporter {
public NurikabeImporter(Nurikabe nurikabe) {
super(nurikabe);
@@ -26,7 +25,7 @@ public boolean acceptsTextInput() {
/**
* Creates an empty board for building
*
- * @param rows the number of rows on the board
+ * @param rows the number of rows on the board
* @param columns the number of columns on the board
* @throws RuntimeException if board can not be created
*/
@@ -36,7 +35,8 @@ public void initializeBoard(int rows, int columns) {
for (int y = 0; y < rows; y++) {
for (int x = 0; x < columns; x++) {
- NurikabeCell cell = new NurikabeCell(NurikabeType.UNKNOWN.toValue(), new Point(x, y));
+ NurikabeCell cell =
+ new NurikabeCell(NurikabeType.UNKNOWN.toValue(), new Point(x, y));
cell.setIndex(y * columns + x);
cell.setModifiable(true);
nurikabeBoard.setCell(x, y, cell);
@@ -55,11 +55,13 @@ public void initializeBoard(int rows, int columns) {
public void initializeBoard(Node node) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("board")) {
- throw new InvalidFileFormatException("nurikabe Importer: cannot find board puzzleElement");
+ throw new InvalidFileFormatException(
+ "nurikabe Importer: cannot find board puzzleElement");
}
Element boardElement = (Element) node;
if (boardElement.getElementsByTagName("cells").getLength() == 0) {
- throw new InvalidFileFormatException("nurikabe Importer: no puzzleElement found for board");
+ throw new InvalidFileFormatException(
+ "nurikabe Importer: no puzzleElement found for board");
}
Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0);
NodeList elementDataList = dataElement.getElementsByTagName("cell");
@@ -68,9 +70,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
if (!boardElement.getAttribute("size").isEmpty()) {
int size = Integer.valueOf(boardElement.getAttribute("size"));
nurikabeBoard = new NurikabeBoard(size);
- }
- else {
- if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) {
+ } else {
+ if (!boardElement.getAttribute("width").isEmpty()
+ && !boardElement.getAttribute("height").isEmpty()) {
int width = Integer.valueOf(boardElement.getAttribute("width"));
int height = Integer.valueOf(boardElement.getAttribute("height"));
nurikabeBoard = new NurikabeBoard(width, height);
@@ -85,7 +87,10 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
int height = nurikabeBoard.getHeight();
for (int i = 0; i < elementDataList.getLength(); i++) {
- NurikabeCell cell = (NurikabeCell) puzzle.getFactory().importCell(elementDataList.item(i), nurikabeBoard);
+ NurikabeCell cell =
+ (NurikabeCell)
+ puzzle.getFactory()
+ .importCell(elementDataList.item(i), nurikabeBoard);
Point loc = cell.getLocation();
if (cell.getData() != NurikabeType.UNKNOWN.toValue()) {
cell.setModifiable(false);
@@ -97,7 +102,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (nurikabeBoard.getCell(x, y) == null) {
- NurikabeCell cell = new NurikabeCell(NurikabeType.UNKNOWN.toValue(), new Point(x, y));
+ NurikabeCell cell =
+ new NurikabeCell(NurikabeType.UNKNOWN.toValue(), new Point(x, y));
cell.setIndex(y * height + x);
cell.setModifiable(true);
nurikabeBoard.setCell(x, y, cell);
@@ -105,9 +111,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
}
}
puzzle.setCurrentBoard(nurikabeBoard);
- }
- catch (NumberFormatException e) {
- throw new InvalidFileFormatException("nurikabe Importer: unknown value where integer expected");
+ } catch (NumberFormatException e) {
+ throw new InvalidFileFormatException(
+ "nurikabe Importer: unknown value where integer expected");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeType.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeType.java
index 1dbab645d..8acf9fc02 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeType.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeType.java
@@ -1,7 +1,10 @@
package edu.rpi.legup.puzzle.nurikabe;
public enum NurikabeType {
- UNKNOWN, BLACK, WHITE, NUMBER;
+ UNKNOWN,
+ BLACK,
+ WHITE,
+ NUMBER;
public int toValue() {
return this.ordinal() - 2;
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java
index 024cf6bb2..71ffa08e5 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.utility.DisjointSets;
-
import java.awt.*;
import java.util.HashMap;
import java.util.HashSet;
@@ -50,18 +49,18 @@ public static DisjointSets getNurikabeRegions(NurikabeBoard board)
NurikabeCell rightCell = board.getCell(x + 1, y);
NurikabeCell downCell = board.getCell(x, y + 1);
- if (cell.getType() == NurikabeType.NUMBER ||
- cell.getType() == NurikabeType.WHITE) {
- if (rightCell != null && (rightCell.getType() == NurikabeType.NUMBER ||
- rightCell.getType() == NurikabeType.WHITE)) {
+ if (cell.getType() == NurikabeType.NUMBER || cell.getType() == NurikabeType.WHITE) {
+ if (rightCell != null
+ && (rightCell.getType() == NurikabeType.NUMBER
+ || rightCell.getType() == NurikabeType.WHITE)) {
regions.union(cell, rightCell);
}
- if (downCell != null && (downCell.getType() == NurikabeType.NUMBER ||
- downCell.getType() == NurikabeType.WHITE)) {
+ if (downCell != null
+ && (downCell.getType() == NurikabeType.NUMBER
+ || downCell.getType() == NurikabeType.WHITE)) {
regions.union(cell, downCell);
}
- }
- else {
+ } else {
if (cell.getType() == NurikabeType.BLACK) {
if (rightCell != null && rightCell.getType() == NurikabeType.BLACK) {
regions.union(cell, rightCell);
@@ -69,8 +68,7 @@ public static DisjointSets getNurikabeRegions(NurikabeBoard board)
if (downCell != null && downCell.getType() == NurikabeType.BLACK) {
regions.union(cell, downCell);
}
- }
- else {
+ } else {
if (cell.getType() == NurikabeType.UNKNOWN) {
if (rightCell != null && rightCell.getType() == NurikabeType.UNKNOWN) {
regions.union(cell, rightCell);
@@ -110,13 +108,16 @@ public static DisjointSets getPossibleBlackRegions(NurikabeBoard b
NurikabeCell cell = board.getCell(x, y);
NurikabeCell rightCell = board.getCell(x + 1, y);
NurikabeCell downCell = board.getCell(x, y + 1);
- if (cell.getType() == NurikabeType.BLACK || cell.getType() == NurikabeType.UNKNOWN) {
- if (rightCell != null && (rightCell.getType() == NurikabeType.BLACK ||
- rightCell.getType() == NurikabeType.UNKNOWN)) {
+ if (cell.getType() == NurikabeType.BLACK
+ || cell.getType() == NurikabeType.UNKNOWN) {
+ if (rightCell != null
+ && (rightCell.getType() == NurikabeType.BLACK
+ || rightCell.getType() == NurikabeType.UNKNOWN)) {
blackRegions.union(cell, rightCell);
}
- if (downCell != null && (downCell.getType() == NurikabeType.BLACK ||
- downCell.getType() == NurikabeType.UNKNOWN)) {
+ if (downCell != null
+ && (downCell.getType() == NurikabeType.BLACK
+ || downCell.getType() == NurikabeType.UNKNOWN)) {
blackRegions.union(cell, downCell);
}
}
@@ -139,7 +140,9 @@ public static DisjointSets getPossibleWhiteRegions(NurikabeBoard b
DisjointSets whiteRegions = new DisjointSets<>();
for (PuzzleElement data : board.getPuzzleElements()) {
NurikabeCell cell = (NurikabeCell) data;
- if (cell.getType() == NurikabeType.WHITE || cell.getType() == NurikabeType.NUMBER || cell.getType() == NurikabeType.UNKNOWN) {
+ if (cell.getType() == NurikabeType.WHITE
+ || cell.getType() == NurikabeType.NUMBER
+ || cell.getType() == NurikabeType.UNKNOWN) {
whiteRegions.createSet(cell);
}
}
@@ -149,14 +152,19 @@ public static DisjointSets getPossibleWhiteRegions(NurikabeBoard b
NurikabeCell cell = board.getCell(x, y);
NurikabeCell rightCell = board.getCell(x + 1, y);
NurikabeCell downCell = board.getCell(x, y + 1);
- if (cell.getType() == NurikabeType.WHITE || cell.getType() == NurikabeType.NUMBER ||
- cell.getType() == NurikabeType.UNKNOWN) {
- if (rightCell != null && (rightCell.getType() == NurikabeType.WHITE ||
- rightCell.getType() == NurikabeType.NUMBER || rightCell.getType() == NurikabeType.UNKNOWN)) {
+ if (cell.getType() == NurikabeType.WHITE
+ || cell.getType() == NurikabeType.NUMBER
+ || cell.getType() == NurikabeType.UNKNOWN) {
+ if (rightCell != null
+ && (rightCell.getType() == NurikabeType.WHITE
+ || rightCell.getType() == NurikabeType.NUMBER
+ || rightCell.getType() == NurikabeType.UNKNOWN)) {
whiteRegions.union(cell, rightCell);
}
- if (downCell != null && (downCell.getType() == NurikabeType.WHITE ||
- downCell.getType() == NurikabeType.NUMBER || downCell.getType() == NurikabeType.UNKNOWN)) {
+ if (downCell != null
+ && (downCell.getType() == NurikabeType.WHITE
+ || downCell.getType() == NurikabeType.NUMBER
+ || downCell.getType() == NurikabeType.UNKNOWN)) {
whiteRegions.union(cell, downCell);
}
}
@@ -166,9 +174,8 @@ public static DisjointSets getPossibleWhiteRegions(NurikabeBoard b
}
/**
- * Makes a map where the keys are white/numbered cells
- * and the values are the amount of cells that need
- * to be added to the region
+ * Makes a map where the keys are white/numbered cells and the values are the amount of cells
+ * that need to be added to the region
*
* @param board nurikabe board
* @return a map of cell keys to integer values
@@ -181,7 +188,7 @@ public static HashMap getWhiteRegionMap(NurikabeBoard boa
// Final mapping of cell to size
HashMap whiteRegionMap = new HashMap<>();
for (NurikabeCell center : numberedCells) {
- //BFS for each center to find the size of the region
+ // BFS for each center to find the size of the region
int size = 1;
// Mark all the vertices as not visited(By default
// set as false)
@@ -224,8 +231,7 @@ public static HashMap getWhiteRegionMap(NurikabeBoard boa
// If a adjacent has not been visited, then mark it
// visited and enqueue it
for (NurikabeCell n : adj) {
- if (!visited.getOrDefault(n, false)
- && n.getType() == NurikabeType.WHITE) {
+ if (!visited.getOrDefault(n, false) && n.getType() == NurikabeType.WHITE) {
connected.add(n);
visited.put(n, true);
queue.add(n);
@@ -249,7 +255,8 @@ public static HashMap getWhiteRegionMap(NurikabeBoard boa
* @param center nurikabe cell
* @return a set of all white/numbered cells in the region
*/
- public static Set getSurroundedRegionOf(NurikabeBoard board, NurikabeCell center) {
+ public static Set getSurroundedRegionOf(
+ NurikabeBoard board, NurikabeCell center) {
int width = board.getWidth();
int height = board.getHeight();
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeView.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeView.java
index cef287b92..0bac7e3e5 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeView.java
@@ -3,7 +3,6 @@
import edu.rpi.legup.controller.BoardController;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.ui.boardview.GridBoardView;
-
import java.awt.*;
public class NurikabeView extends GridBoardView {
@@ -17,7 +16,8 @@ public NurikabeView(NurikabeBoard board) {
NurikabeElementView elementView = new NurikabeElementView(cell);
elementView.setIndex(cell.getIndex());
elementView.setSize(elementSize);
- elementView.setLocation(new Point(loc.x * elementSize.width, loc.y * elementSize.height));
+ elementView.setLocation(
+ new Point(loc.x * elementSize.width, loc.y * elementSize.height));
elementViews.add(elementView);
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/BlackTile.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/BlackTile.java
index 1609fbf99..459a809e0 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/BlackTile.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/BlackTile.java
@@ -4,6 +4,10 @@
public class BlackTile extends PlaceableElement {
public BlackTile() {
- super("NURI-PLAC-0001", "Black Tile", "The black tile", "edu/rpi/legup/images/nurikabe/tiles/BlackTile.png");
+ super(
+ "NURI-PLAC-0001",
+ "Black Tile",
+ "The black tile",
+ "edu/rpi/legup/images/nurikabe/tiles/BlackTile.png");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/NumberTile.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/NumberTile.java
index 0b1ee9656..475b278da 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/NumberTile.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/NumberTile.java
@@ -6,7 +6,11 @@ public class NumberTile extends NonPlaceableElement {
private int object_num;
public NumberTile() {
- super("NURI-UNPL-0001", "Number Tile", "A numbered tile", "edu/rpi/legup/images/nurikabe/tiles/NumberTile.png");
+ super(
+ "NURI-UNPL-0001",
+ "Number Tile",
+ "A numbered tile",
+ "edu/rpi/legup/images/nurikabe/tiles/NumberTile.png");
object_num = 0;
}
@@ -23,5 +27,4 @@ public int getTileNumber() {
public void setTileNumber(int num) {
object_num = num;
}
-
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/UnknownTile.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/UnknownTile.java
index 259e17e74..85d47e208 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/UnknownTile.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/UnknownTile.java
@@ -4,6 +4,10 @@
public class UnknownTile extends NonPlaceableElement {
public UnknownTile() {
- super("NURI-UNPL-0002", "Unknown Tile", "A blank tile", "edu/rpi/legup/images/nurikabe/tiles/UnknownTile.png");
+ super(
+ "NURI-UNPL-0002",
+ "Unknown Tile",
+ "A blank tile",
+ "edu/rpi/legup/images/nurikabe/tiles/UnknownTile.png");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/WhiteTile.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/WhiteTile.java
index 434e0663e..35eb63b81 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/WhiteTile.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/WhiteTile.java
@@ -4,6 +4,10 @@
public class WhiteTile extends PlaceableElement {
public WhiteTile() {
- super("NURI-PLAC-0002", "White Tile", "The white tile", "edu/rpi/legup/images/nurikabe/tiles/WhiteTile.png");
+ super(
+ "NURI-PLAC-0002",
+ "White Tile",
+ "The white tile",
+ "edu/rpi/legup/images/nurikabe/tiles/WhiteTile.png");
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBetweenRegionsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBetweenRegionsDirectRule.java
index bb527e4e2..7428ac204 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBetweenRegionsDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBetweenRegionsDirectRule.java
@@ -1,112 +1,122 @@
-package edu.rpi.legup.puzzle.nurikabe.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.rules.ContradictionRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities;
-import edu.rpi.legup.utility.DisjointSets;
-
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-public class BlackBetweenRegionsDirectRule extends DirectRule {
-
- public BlackBetweenRegionsDirectRule() {
- super("NURI-BASC-0001",
- "Black Between Regions",
- "Any unknowns between two regions must be black.",
- "edu/rpi/legup/images/nurikabe/rules/BetweenRegions.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- Set contras = new LinkedHashSet<>();
- contras.add(new MultipleNumbersContradictionRule());
- contras.add(new TooManySpacesContradictionRule());
-
- NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard();
- NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard();
-
- NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement);
-
- if (cell.getType() != NurikabeType.BLACK) {
- return super.getInvalidUseOfRuleMessage() + ": Only black cells are allowed for this rule!";
- }
-
- int x = cell.getLocation().x;
- int y = cell.getLocation().y;
-
- DisjointSets regions = NurikabeUtilities.getNurikabeRegions(destBoardState);
- Set adjacentWhiteRegions = new HashSet<>();
- NurikabeCell upCell = destBoardState.getCell(x, y - 1);
- NurikabeCell rightCell = destBoardState.getCell(x + 1, y);
- NurikabeCell downCell = destBoardState.getCell(x, y + 1);
- NurikabeCell leftCell = destBoardState.getCell(x - 1, y);
-
- if (upCell != null && (upCell.getType() == NurikabeType.WHITE || upCell.getType() == NurikabeType.NUMBER)) {
- NurikabeCell repCell = regions.find(upCell);
- if (!adjacentWhiteRegions.contains(repCell)) {
- adjacentWhiteRegions.add(repCell);
- }
- }
- if (rightCell != null && (rightCell.getType() == NurikabeType.WHITE || rightCell.getType() == NurikabeType.NUMBER)) {
- NurikabeCell repCell = regions.find(rightCell);
- if (!adjacentWhiteRegions.contains(repCell)) {
- adjacentWhiteRegions.add(repCell);
- }
- }
- if (downCell != null && (downCell.getType() == NurikabeType.WHITE || downCell.getType() == NurikabeType.NUMBER)) {
- NurikabeCell repCell = regions.find(downCell);
- if (!adjacentWhiteRegions.contains(repCell)) {
- adjacentWhiteRegions.add(repCell);
- }
- }
- if (leftCell != null && (leftCell.getType() == NurikabeType.WHITE || leftCell.getType() == NurikabeType.NUMBER)) {
- NurikabeCell repCell = regions.find(leftCell);
- if (!adjacentWhiteRegions.contains(repCell)) {
- adjacentWhiteRegions.add(repCell);
- }
- }
-
- if (adjacentWhiteRegions.size() < 2) {
- return "The new black cell must separate two white regions for this rule!";
- }
-
- NurikabeBoard modified = origBoardState.copy();
- modified.getCell(x, y).setData(NurikabeType.WHITE.toValue());
-
- for (ContradictionRule c : contras) {
- if (c.checkContradiction(modified) == null) {
- return null;
- }
- }
- return "Does not follow from the rule";
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.nurikabe.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.ContradictionRule;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities;
+import edu.rpi.legup.utility.DisjointSets;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+public class BlackBetweenRegionsDirectRule extends DirectRule {
+
+ public BlackBetweenRegionsDirectRule() {
+ super(
+ "NURI-BASC-0001",
+ "Black Between Regions",
+ "Any unknowns between two regions must be black.",
+ "edu/rpi/legup/images/nurikabe/rules/BetweenRegions.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ Set contras = new LinkedHashSet<>();
+ contras.add(new MultipleNumbersContradictionRule());
+ contras.add(new TooManySpacesContradictionRule());
+
+ NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard();
+ NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard();
+
+ NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement);
+
+ if (cell.getType() != NurikabeType.BLACK) {
+ return super.getInvalidUseOfRuleMessage()
+ + ": Only black cells are allowed for this rule!";
+ }
+
+ int x = cell.getLocation().x;
+ int y = cell.getLocation().y;
+
+ DisjointSets regions = NurikabeUtilities.getNurikabeRegions(destBoardState);
+ Set adjacentWhiteRegions = new HashSet<>();
+ NurikabeCell upCell = destBoardState.getCell(x, y - 1);
+ NurikabeCell rightCell = destBoardState.getCell(x + 1, y);
+ NurikabeCell downCell = destBoardState.getCell(x, y + 1);
+ NurikabeCell leftCell = destBoardState.getCell(x - 1, y);
+
+ if (upCell != null
+ && (upCell.getType() == NurikabeType.WHITE
+ || upCell.getType() == NurikabeType.NUMBER)) {
+ NurikabeCell repCell = regions.find(upCell);
+ if (!adjacentWhiteRegions.contains(repCell)) {
+ adjacentWhiteRegions.add(repCell);
+ }
+ }
+ if (rightCell != null
+ && (rightCell.getType() == NurikabeType.WHITE
+ || rightCell.getType() == NurikabeType.NUMBER)) {
+ NurikabeCell repCell = regions.find(rightCell);
+ if (!adjacentWhiteRegions.contains(repCell)) {
+ adjacentWhiteRegions.add(repCell);
+ }
+ }
+ if (downCell != null
+ && (downCell.getType() == NurikabeType.WHITE
+ || downCell.getType() == NurikabeType.NUMBER)) {
+ NurikabeCell repCell = regions.find(downCell);
+ if (!adjacentWhiteRegions.contains(repCell)) {
+ adjacentWhiteRegions.add(repCell);
+ }
+ }
+ if (leftCell != null
+ && (leftCell.getType() == NurikabeType.WHITE
+ || leftCell.getType() == NurikabeType.NUMBER)) {
+ NurikabeCell repCell = regions.find(leftCell);
+ if (!adjacentWhiteRegions.contains(repCell)) {
+ adjacentWhiteRegions.add(repCell);
+ }
+ }
+
+ if (adjacentWhiteRegions.size() < 2) {
+ return "The new black cell must separate two white regions for this rule!";
+ }
+
+ NurikabeBoard modified = origBoardState.copy();
+ modified.getCell(x, y).setData(NurikabeType.WHITE.toValue());
+
+ for (ContradictionRule c : contras) {
+ if (c.checkContradiction(modified) == null) {
+ return null;
+ }
+ }
+ return "Does not follow from the rule";
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckDirectRule.java
index c4cf0d3fd..a8a94178b 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckDirectRule.java
@@ -1,65 +1,69 @@
-package edu.rpi.legup.puzzle.nurikabe.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.rules.ContradictionRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
-
-public class BlackBottleNeckDirectRule extends DirectRule {
-
- public BlackBottleNeckDirectRule() {
- super("NURI-BASC-0002",
- "Black Bottle Neck",
- "If there is only one path for a black to escape, then those unknowns must be black.",
- "edu/rpi/legup/images/nurikabe/rules/OneUnknownBlack.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- ContradictionRule contraRule = new IsolateBlackContradictionRule();
-
- NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard();
- NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard();
-
- NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement);
-
- if (cell.getType() != NurikabeType.BLACK) {
- return super.getInvalidUseOfRuleMessage() + ": Only black cells are allowed for this rule!";
- }
- NurikabeBoard modified = origBoardState.copy();
- NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement);
- modCell.setData(NurikabeType.WHITE.toValue());
-
- if (contraRule.checkContradiction(modified) == null) {
- return null;
- }
- else {
- return super.getInvalidUseOfRuleMessage() + ": This is not the only way for black to escape!";
- }
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.nurikabe.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.ContradictionRule;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
+
+public class BlackBottleNeckDirectRule extends DirectRule {
+
+ public BlackBottleNeckDirectRule() {
+ super(
+ "NURI-BASC-0002",
+ "Black Bottle Neck",
+ "If there is only one path for a black to escape, then those unknowns must be"
+ + " black.",
+ "edu/rpi/legup/images/nurikabe/rules/OneUnknownBlack.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ ContradictionRule contraRule = new IsolateBlackContradictionRule();
+
+ NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard();
+ NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard();
+
+ NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement);
+
+ if (cell.getType() != NurikabeType.BLACK) {
+ return super.getInvalidUseOfRuleMessage()
+ + ": Only black cells are allowed for this rule!";
+ }
+ NurikabeBoard modified = origBoardState.copy();
+ NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement);
+ modCell.setData(NurikabeType.WHITE.toValue());
+
+ if (contraRule.checkContradiction(modified) == null) {
+ return null;
+ } else {
+ return super.getInvalidUseOfRuleMessage()
+ + ": This is not the only way for black to escape!";
+ }
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackOrWhiteCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackOrWhiteCaseRule.java
index 641b76322..fe1ffcf91 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackOrWhiteCaseRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackOrWhiteCaseRule.java
@@ -8,22 +8,22 @@
import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
-
import java.util.ArrayList;
import java.util.List;
public class BlackOrWhiteCaseRule extends CaseRule {
public BlackOrWhiteCaseRule() {
- super("NURI-CASE-0001",
+ super(
+ "NURI-CASE-0001",
"Black or White",
"Each blank cell is either black or white.",
"edu/rpi/legup/images/nurikabe/cases/BlackOrWhite.png");
}
/**
- * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is
- * the one that should overridden in child classes.
+ * Checks whether the {@link TreeTransition} logically follows from the parent node using this
+ * rule. This method is the one that should overridden in child classes.
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
@@ -37,20 +37,24 @@ public String checkRuleRaw(TreeTransition transition) {
TreeTransition case1 = childTransitions.get(0);
TreeTransition case2 = childTransitions.get(1);
- if (case1.getBoard().getModifiedData().size() != 1 ||
- case2.getBoard().getModifiedData().size() != 1) {
- return super.getInvalidUseOfRuleMessage() + ": This case rule must have 1 modified cell for each case.";
+ if (case1.getBoard().getModifiedData().size() != 1
+ || case2.getBoard().getModifiedData().size() != 1) {
+ return super.getInvalidUseOfRuleMessage()
+ + ": This case rule must have 1 modified cell for each case.";
}
NurikabeCell mod1 = (NurikabeCell) case1.getBoard().getModifiedData().iterator().next();
NurikabeCell mod2 = (NurikabeCell) case2.getBoard().getModifiedData().iterator().next();
if (!mod1.getLocation().equals(mod2.getLocation())) {
- return super.getInvalidUseOfRuleMessage() + ": This case rule must modify the same cell for each case.";
+ return super.getInvalidUseOfRuleMessage()
+ + ": This case rule must modify the same cell for each case.";
}
- if (!((mod1.getType() == NurikabeType.WHITE && mod2.getType() == NurikabeType.BLACK) ||
- (mod2.getType() == NurikabeType.WHITE && mod1.getType() == NurikabeType.BLACK))) {
- return super.getInvalidUseOfRuleMessage() + ": This case rule must an empty white and black cell.";
+ if (!((mod1.getType() == NurikabeType.WHITE && mod2.getType() == NurikabeType.BLACK)
+ || (mod2.getType() == NurikabeType.WHITE
+ && mod1.getType() == NurikabeType.BLACK))) {
+ return super.getInvalidUseOfRuleMessage()
+ + ": This case rule must an empty white and black cell.";
}
return null;
@@ -72,7 +76,7 @@ public CaseBoard getCaseBoard(Board board) {
/**
* Gets the possible cases at a specific location based on this case rule
*
- * @param board the current board state
+ * @param board the current board state
* @param puzzleElement equivalent puzzleElement
* @return a list of elements the specified could be
*/
@@ -95,13 +99,13 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) {
}
/**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
*
- * @param transition transition to check
+ * @param transition transition to check
* @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackSquareContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackSquareContradictionRule.java
index 2dfb817e2..751c88881 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackSquareContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackSquareContradictionRule.java
@@ -13,20 +13,21 @@ public class BlackSquareContradictionRule extends ContradictionRule {
private final String INVALID_USE_MESSAGE = "Does not contain a contradiction at this index";
public BlackSquareContradictionRule() {
- super("NURI-CONT-0001",
+ super(
+ "NURI-CONT-0001",
"Black Square",
"There cannot be a 2x2 square of black.",
"edu/rpi/legup/images/nurikabe/contradictions/BlackSquare.png");
}
-
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
@@ -39,12 +40,16 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE;
}
- for (int x = cell.getLocation().x - 1; x >= 0 && x < cell.getLocation().x + 1 && x < width - 1; x++) {
- for (int y = cell.getLocation().y - 1; y >= 0 && y < cell.getLocation().y + 1 && y < height - 1; y++) {
- if (nurikabeBoard.getCell(x, y).getType() == NurikabeType.BLACK &&
- nurikabeBoard.getCell(x + 1, y).getType() == NurikabeType.BLACK &&
- nurikabeBoard.getCell(x, y + 1).getType() == NurikabeType.BLACK &&
- nurikabeBoard.getCell(x + 1, y + 1).getType() == NurikabeType.BLACK) {
+ for (int x = cell.getLocation().x - 1;
+ x >= 0 && x < cell.getLocation().x + 1 && x < width - 1;
+ x++) {
+ for (int y = cell.getLocation().y - 1;
+ y >= 0 && y < cell.getLocation().y + 1 && y < height - 1;
+ y++) {
+ if (nurikabeBoard.getCell(x, y).getType() == NurikabeType.BLACK
+ && nurikabeBoard.getCell(x + 1, y).getType() == NurikabeType.BLACK
+ && nurikabeBoard.getCell(x, y + 1).getType() == NurikabeType.BLACK
+ && nurikabeBoard.getCell(x + 1, y + 1).getType() == NurikabeType.BLACK) {
return null;
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CannotReachCellDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CannotReachCellDirectRule.java
index e86724ed9..f3d3ee8f2 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CannotReachCellDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CannotReachCellDirectRule.java
@@ -1,61 +1,64 @@
-package edu.rpi.legup.puzzle.nurikabe.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.rules.ContradictionRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
-
-public class CannotReachCellDirectRule extends DirectRule {
- public CannotReachCellDirectRule() {
- super("NURI-BASC-0008",
- "Can't Reach Cell",
- "A cell must be black if it cannot be reached by any white region",
- "edu/rpi/legup/images/nurikabe/rules/Unreachable.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- ContradictionRule contraRule = new UnreachableWhiteCellContradictionRule();
-
- NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard();
- NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement);
- if (cell.getType() != NurikabeType.BLACK) {
- return super.getInvalidUseOfRuleMessage() + ": Only black cells are allowed for this rule!";
- }
-
- NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard();
- NurikabeBoard modified = origBoardState.copy();
-
- NurikabeCell modifiedCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement);
- modifiedCell.setData(NurikabeType.WHITE.toValue());
- if (contraRule.checkContradictionAt(modified, modifiedCell) == null) {
- return null;
- }
- return super.getInvalidUseOfRuleMessage() + ": Cell at this index can be reached";
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.nurikabe.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.ContradictionRule;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
+
+public class CannotReachCellDirectRule extends DirectRule {
+ public CannotReachCellDirectRule() {
+ super(
+ "NURI-BASC-0008",
+ "Can't Reach Cell",
+ "A cell must be black if it cannot be reached by any white region",
+ "edu/rpi/legup/images/nurikabe/rules/Unreachable.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ ContradictionRule contraRule = new UnreachableWhiteCellContradictionRule();
+
+ NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard();
+ NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement);
+ if (cell.getType() != NurikabeType.BLACK) {
+ return super.getInvalidUseOfRuleMessage()
+ + ": Only black cells are allowed for this rule!";
+ }
+
+ NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard();
+ NurikabeBoard modified = origBoardState.copy();
+
+ NurikabeCell modifiedCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement);
+ modifiedCell.setData(NurikabeType.WHITE.toValue());
+ if (contraRule.checkContradictionAt(modified, modifiedCell) == null) {
+ return null;
+ }
+ return super.getInvalidUseOfRuleMessage() + ": Cell at this index can be reached";
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CornerBlackDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CornerBlackDirectRule.java
index 55316fcbb..84ec45e99 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CornerBlackDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CornerBlackDirectRule.java
@@ -1,108 +1,133 @@
-package edu.rpi.legup.puzzle.nurikabe.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.rules.ContradictionRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
-import edu.rpi.legup.utility.ConnectedRegions;
-
-import java.awt.*;
-import java.util.Set;
-
-public class CornerBlackDirectRule extends DirectRule {
-
- public CornerBlackDirectRule() {
- super("NURI-BASC-0003",
- "Corners Black",
- "If there is only one white square connected to unknowns and one more white is needed then the angles of that white square are black",
- "edu/rpi/legup/images/nurikabe/rules/CornerBlack.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- NurikabeBoard board = (NurikabeBoard) transition.getBoard();
- NurikabeCell cell = (NurikabeCell) board.getPuzzleElement(puzzleElement);
- if (cell.getType() != NurikabeType.BLACK) {
- return "Only black cells are allowed for this rule!";
- }
-
- ContradictionRule tooFewContra = new TooFewSpacesContradictionRule();
- Point cellLocation = cell.getLocation();
- // 1. Find the coordinates of the white space (should be a corner of cell)
- for (int i = -1; i < 2; i += 2) {
- for (int j = -1; j < 2; j += 2) {
- // If the corner does not exist, skip the corner
- if (!(cellLocation.x + i >= 0 && cellLocation.x + i < board.getWidth() && cellLocation.y + j >= 0 && cellLocation.y + j < board.getHeight())) {
- continue;
- }
-
- NurikabeCell corner = board.getCell(cellLocation.x + i, cellLocation.y + j);
- NurikabeType cornerType = corner.getType();
- if (cornerType == NurikabeType.WHITE || cornerType == NurikabeType.NUMBER) {
- Point cornerLocation = corner.getLocation();
- // 2. Check if the intersecting adjacent spaces of the white space and the black corner are empty
- if (board.getCell(cornerLocation.x, cellLocation.y).getType() == NurikabeType.UNKNOWN && board.getCell(cellLocation.x, cornerLocation.y).getType() == NurikabeType.UNKNOWN) {
- // System.out.println("Went inside if statement");
- NurikabeBoard modified = board.copy();
- modified.getCell(cornerLocation.x, cellLocation.y).setData(NurikabeType.BLACK.toValue());
- modified.getCell(cellLocation.x, cornerLocation.y).setData(NurikabeType.BLACK.toValue());
- boolean containsContradiction = tooFewContra.checkContradiction(modified) == null;
- if (containsContradiction) {
- // 3. Check if the connected region is 1 under what is needed
- Set region = ConnectedRegions.getRegionAroundPoint(cornerLocation, NurikabeType.BLACK.toValue(), modified.getIntArray(), modified.getWidth(), modified.getHeight());
- int regionNumber = 0;
- // System.out.println("Region set size: " + region.size());
- for (Point p : region) {
- NurikabeCell pCell = modified.getCell(p.x, p.y);
- if (pCell.getType() == NurikabeType.NUMBER) {
- if (regionNumber == 0) {
- regionNumber = pCell.getData();
- }
- else {
- return "There is a MultipleNumbers Contradiction on the board.";
- }
- }
- }
- // If the region size is 0, there is a possibility that there was only 1 cell in the white
- // region, and that white cell was a NurikabeType.NUMBER cell
- if (regionNumber == 0 && corner.getType() == NurikabeType.NUMBER && corner.getData() == 2) {
- return null;
- }
- // If the region size is not 0, make sure the regionNumber and the region size match (need
- // to add 1 to account for the cell that was surrounded
- if (regionNumber != 0 && region.size() + 1 == regionNumber) {
- return null;
- }
- }
- }
- }
- }
- }
- return "This is not a valid use of the corner black rule!";
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.nurikabe.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.ContradictionRule;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
+import edu.rpi.legup.utility.ConnectedRegions;
+import java.awt.*;
+import java.util.Set;
+
+public class CornerBlackDirectRule extends DirectRule {
+
+ public CornerBlackDirectRule() {
+ super(
+ "NURI-BASC-0003",
+ "Corners Black",
+ "If there is only one white square connected to unknowns and one more white is"
+ + " needed then the angles of that white square are black",
+ "edu/rpi/legup/images/nurikabe/rules/CornerBlack.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ NurikabeBoard board = (NurikabeBoard) transition.getBoard();
+ NurikabeCell cell = (NurikabeCell) board.getPuzzleElement(puzzleElement);
+ if (cell.getType() != NurikabeType.BLACK) {
+ return "Only black cells are allowed for this rule!";
+ }
+
+ ContradictionRule tooFewContra = new TooFewSpacesContradictionRule();
+ Point cellLocation = cell.getLocation();
+ // 1. Find the coordinates of the white space (should be a corner of cell)
+ for (int i = -1; i < 2; i += 2) {
+ for (int j = -1; j < 2; j += 2) {
+ // If the corner does not exist, skip the corner
+ if (!(cellLocation.x + i >= 0
+ && cellLocation.x + i < board.getWidth()
+ && cellLocation.y + j >= 0
+ && cellLocation.y + j < board.getHeight())) {
+ continue;
+ }
+
+ NurikabeCell corner = board.getCell(cellLocation.x + i, cellLocation.y + j);
+ NurikabeType cornerType = corner.getType();
+ if (cornerType == NurikabeType.WHITE || cornerType == NurikabeType.NUMBER) {
+ Point cornerLocation = corner.getLocation();
+ // 2. Check if the intersecting adjacent spaces of the white space and the black
+ // corner
+ // are empty
+ if (board.getCell(cornerLocation.x, cellLocation.y).getType()
+ == NurikabeType.UNKNOWN
+ && board.getCell(cellLocation.x, cornerLocation.y).getType()
+ == NurikabeType.UNKNOWN) {
+ // System.out.println("Went inside if statement");
+ NurikabeBoard modified = board.copy();
+ modified.getCell(cornerLocation.x, cellLocation.y)
+ .setData(NurikabeType.BLACK.toValue());
+ modified.getCell(cellLocation.x, cornerLocation.y)
+ .setData(NurikabeType.BLACK.toValue());
+ boolean containsContradiction =
+ tooFewContra.checkContradiction(modified) == null;
+ if (containsContradiction) {
+ // 3. Check if the connected region is 1 under what is needed
+ Set region =
+ ConnectedRegions.getRegionAroundPoint(
+ cornerLocation,
+ NurikabeType.BLACK.toValue(),
+ modified.getIntArray(),
+ modified.getWidth(),
+ modified.getHeight());
+ int regionNumber = 0;
+ // System.out.println("Region set size: " + region.size());
+ for (Point p : region) {
+ NurikabeCell pCell = modified.getCell(p.x, p.y);
+ if (pCell.getType() == NurikabeType.NUMBER) {
+ if (regionNumber == 0) {
+ regionNumber = pCell.getData();
+ } else {
+ return "There is a MultipleNumbers Contradiction on the"
+ + " board.";
+ }
+ }
+ }
+ // If the region size is 0, there is a possibility that there was only 1
+ // cell in the
+ // white
+ // region, and that white cell was a NurikabeType.NUMBER cell
+ if (regionNumber == 0
+ && corner.getType() == NurikabeType.NUMBER
+ && corner.getData() == 2) {
+ return null;
+ }
+ // If the region size is not 0, make sure the regionNumber and the
+ // region size match
+ // (need
+ // to add 1 to account for the cell that was surrounded
+ if (regionNumber != 0 && region.size() + 1 == regionNumber) {
+ return null;
+ }
+ }
+ }
+ }
+ }
+ }
+ return "This is not a valid use of the corner black rule!";
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinBlackDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinBlackDirectRule.java
index aab389e4a..7c4629f65 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinBlackDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinBlackDirectRule.java
@@ -1,60 +1,62 @@
-package edu.rpi.legup.puzzle.nurikabe.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.rules.ContradictionRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
-
-public class FillinBlackDirectRule extends DirectRule {
-
- public FillinBlackDirectRule() {
- super("NURI-BASC-0004",
- "Fill In Black",
- "If there an unknown region surrounded by black, it must be black.",
- "edu/rpi/legup/images/nurikabe/rules/FillInBlack.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- NurikabeBoard board = (NurikabeBoard) transition.getBoard();
- NurikabeBoard origBoard = (NurikabeBoard) transition.getParents().get(0).getBoard();
- ContradictionRule contraRule = new NoNumberContradictionRule();
-
- NurikabeCell cell = (NurikabeCell) board.getPuzzleElement(puzzleElement);
-
- if (cell.getType() != NurikabeType.BLACK) {
- return "Only black cells are allowed for this rule!";
- }
- NurikabeBoard modified = origBoard.copy();
- modified.getPuzzleElement(puzzleElement).setData(NurikabeType.WHITE.toValue());
- if (contraRule.checkContradictionAt(modified, puzzleElement) != null) {
- return "Black cells must be placed in a region of black cells!";
- }
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.nurikabe.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.ContradictionRule;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
+
+public class FillinBlackDirectRule extends DirectRule {
+
+ public FillinBlackDirectRule() {
+ super(
+ "NURI-BASC-0004",
+ "Fill In Black",
+ "If there an unknown region surrounded by black, it must be black.",
+ "edu/rpi/legup/images/nurikabe/rules/FillInBlack.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ NurikabeBoard board = (NurikabeBoard) transition.getBoard();
+ NurikabeBoard origBoard = (NurikabeBoard) transition.getParents().get(0).getBoard();
+ ContradictionRule contraRule = new NoNumberContradictionRule();
+
+ NurikabeCell cell = (NurikabeCell) board.getPuzzleElement(puzzleElement);
+
+ if (cell.getType() != NurikabeType.BLACK) {
+ return "Only black cells are allowed for this rule!";
+ }
+ NurikabeBoard modified = origBoard.copy();
+ modified.getPuzzleElement(puzzleElement).setData(NurikabeType.WHITE.toValue());
+ if (contraRule.checkContradictionAt(modified, puzzleElement) != null) {
+ return "Black cells must be placed in a region of black cells!";
+ }
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinWhiteDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinWhiteDirectRule.java
index 4f57602d5..05bb2f046 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinWhiteDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinWhiteDirectRule.java
@@ -1,60 +1,62 @@
-package edu.rpi.legup.puzzle.nurikabe.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.rules.ContradictionRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
-
-public class FillinWhiteDirectRule extends DirectRule {
-
- public FillinWhiteDirectRule() {
- super("NURI-BASC-0005",
- "Fill In White",
- "If there an unknown region surrounded by white, it must be white.",
- "edu/rpi/legup/images/nurikabe/rules/FillInWhite.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- NurikabeBoard board = (NurikabeBoard) transition.getBoard();
- NurikabeBoard origBoard = (NurikabeBoard) transition.getParents().get(0).getBoard();
- ContradictionRule contraRule = new IsolateBlackContradictionRule();
-
- NurikabeCell cell = (NurikabeCell) board.getPuzzleElement(puzzleElement);
-
- if (cell.getType() != NurikabeType.WHITE) {
- return "Only white cells are allowed for this rule!";
- }
- NurikabeBoard modified = origBoard.copy();
- modified.getPuzzleElement(puzzleElement).setData(NurikabeType.BLACK.toValue());
- if (contraRule.checkContradictionAt(modified, puzzleElement) != null) {
- return "white cells must be placed in a region of white cells!";
- }
- return null;
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.nurikabe.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.ContradictionRule;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
+
+public class FillinWhiteDirectRule extends DirectRule {
+
+ public FillinWhiteDirectRule() {
+ super(
+ "NURI-BASC-0005",
+ "Fill In White",
+ "If there an unknown region surrounded by white, it must be white.",
+ "edu/rpi/legup/images/nurikabe/rules/FillInWhite.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ NurikabeBoard board = (NurikabeBoard) transition.getBoard();
+ NurikabeBoard origBoard = (NurikabeBoard) transition.getParents().get(0).getBoard();
+ ContradictionRule contraRule = new IsolateBlackContradictionRule();
+
+ NurikabeCell cell = (NurikabeCell) board.getPuzzleElement(puzzleElement);
+
+ if (cell.getType() != NurikabeType.WHITE) {
+ return "Only white cells are allowed for this rule!";
+ }
+ NurikabeBoard modified = origBoard.copy();
+ modified.getPuzzleElement(puzzleElement).setData(NurikabeType.BLACK.toValue());
+ if (contraRule.checkContradictionAt(modified, puzzleElement) != null) {
+ return "white cells must be placed in a region of white cells!";
+ }
+ return null;
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java
index c7331330b..f26f0c3fe 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java
@@ -8,30 +8,30 @@
import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities;
import edu.rpi.legup.utility.DisjointSets;
-
import java.util.Set;
public class IsolateBlackContradictionRule extends ContradictionRule {
- private final String NO_CONTRADICTION_MESSAGE = "Contradiction applied incorrectly. No isolated Blacks.";
+ private final String NO_CONTRADICTION_MESSAGE =
+ "Contradiction applied incorrectly. No isolated Blacks.";
private final String INVALID_USE_MESSAGE = "Contradiction must be a black cell";
public IsolateBlackContradictionRule() {
- super("NURI-CONT-0003",
+ super(
+ "NURI-CONT-0003",
"Isolated Black",
"There must still be a possibility to connect every Black cell",
"edu/rpi/legup/images/nurikabe/contradictions/BlackArea.png");
}
/**
- * Checks whether the transition has a contradiction at the specific
- * {@link PuzzleElement} index using this rule.
+ * Checks whether the transition has a contradiction at the specific {@link PuzzleElement} index
+ * using this rule.
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
- * @return null
if the transition contains a
- * contradiction at the specified {@link PuzzleElement},
- * otherwise return a no contradiction message.
+ * @return null
if the transition contains a contradiction at the specified {@link
+ * PuzzleElement}, otherwise return a no contradiction message.
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
@@ -41,15 +41,15 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE;
}
- DisjointSets blackRegions = NurikabeUtilities.getPossibleBlackRegions(nurikabeBoard);
+ DisjointSets blackRegions =
+ NurikabeUtilities.getPossibleBlackRegions(nurikabeBoard);
boolean oneRegion = false;
for (Set region : blackRegions.getAllSets()) {
for (NurikabeCell c : region) {
if (c.getType() == NurikabeType.BLACK) {
if (oneRegion) {
return null;
- }
- else {
+ } else {
oneRegion = true;
break;
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/MultipleNumbersContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/MultipleNumbersContradictionRule.java
index e83204b99..1925a68ec 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/MultipleNumbersContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/MultipleNumbersContradictionRule.java
@@ -8,28 +8,30 @@
import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities;
import edu.rpi.legup.utility.DisjointSets;
-
import java.util.Set;
public class MultipleNumbersContradictionRule extends ContradictionRule {
- private final String NO_CONTRADICTION_MESSAGE = "Does not contain a contradiction at this index";
+ private final String NO_CONTRADICTION_MESSAGE =
+ "Does not contain a contradiction at this index";
private final String INVALID_USE_MESSAGE = "Contradiction must be a numbered cell";
public MultipleNumbersContradictionRule() {
- super("NURI-CONT-0004",
+ super(
+ "NURI-CONT-0004",
"Multiple Numbers",
"All white regions cannot have more than one number.",
"edu/rpi/legup/images/nurikabe/contradictions/MultipleNumbers.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java
index c2752da7a..6c69136b2 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java
@@ -7,31 +7,31 @@
import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities;
-import edu.rpi.legup.utility.DisjointSets;
-
import java.util.Set;
-import java.util.List;
public class NoNumberContradictionRule extends ContradictionRule {
- private final String NO_CONTRADICTION_MESSAGE = "Does not contain a contradiction at this index";
+ private final String NO_CONTRADICTION_MESSAGE =
+ "Does not contain a contradiction at this index";
private final String INVALID_USE_MESSAGE = "Contradiction must be a white cell";
private final String NOT_SURROUNDED_BY_BLACK_MESSAGE = "Must be surrounded by black cells";
public NoNumberContradictionRule() {
- super("NURI-CONT-0005",
+ super(
+ "NURI-CONT-0005",
"No Number",
"All enclosed white regions must have a number.",
"edu/rpi/legup/images/nurikabe/contradictions/NoNumber.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/PreventBlackSquareDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/PreventBlackSquareDirectRule.java
index 2502ee62f..106c22f7a 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/PreventBlackSquareDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/PreventBlackSquareDirectRule.java
@@ -1,66 +1,67 @@
-package edu.rpi.legup.puzzle.nurikabe.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.rules.ContradictionRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
-
-public class PreventBlackSquareDirectRule extends DirectRule {
-
- public PreventBlackSquareDirectRule() {
- super("NURI-BASC-0006",
- "Prevent Black Square",
- "There cannot be a 2x2 square of black. (3 blacks = fill in last corner white)",
- "edu/rpi/legup/images/nurikabe/rules/NoBlackSquare.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- ContradictionRule contraRule = new BlackSquareContradictionRule();
-
- NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard();
- NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard();
-
- NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement);
-
- if (cell.getType() != NurikabeType.WHITE) {
- return "Only white cells are allowed for this rule!";
- }
-
- NurikabeBoard modified = origBoardState.copy();
- NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement);
- modCell.setData(NurikabeType.BLACK.toValue());
-
- if (contraRule.checkContradiction(modified) == null) {
- return null;
- }
- else {
- return "Does not contain a contradiction at this index";
- }
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.nurikabe.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.ContradictionRule;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
+
+public class PreventBlackSquareDirectRule extends DirectRule {
+
+ public PreventBlackSquareDirectRule() {
+ super(
+ "NURI-BASC-0006",
+ "Prevent Black Square",
+ "There cannot be a 2x2 square of black. (3 blacks = fill in last corner white)",
+ "edu/rpi/legup/images/nurikabe/rules/NoBlackSquare.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ ContradictionRule contraRule = new BlackSquareContradictionRule();
+
+ NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard();
+ NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard();
+
+ NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement);
+
+ if (cell.getType() != NurikabeType.WHITE) {
+ return "Only white cells are allowed for this rule!";
+ }
+
+ NurikabeBoard modified = origBoardState.copy();
+ NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement);
+ modCell.setData(NurikabeType.BLACK.toValue());
+
+ if (contraRule.checkContradiction(modified) == null) {
+ return null;
+ } else {
+ return "Does not contain a contradiction at this index";
+ }
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/SurroundRegionDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/SurroundRegionDirectRule.java
index d992fd22c..8e260cf42 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/SurroundRegionDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/SurroundRegionDirectRule.java
@@ -1,95 +1,103 @@
-package edu.rpi.legup.puzzle.nurikabe.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities;
-import edu.rpi.legup.utility.DisjointSets;
-
-import java.util.Arrays;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.HashSet;
-import java.util.Set;
-import java.awt.*;
-
-public class SurroundRegionDirectRule extends DirectRule {
-
- public SurroundRegionDirectRule() {
- super("NURI-BASC-0007", "Surround Region",
- "Surround Region",
- "edu/rpi/legup/images/nurikabe/rules/SurroundBlack.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
-
- NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard();
- NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard();
-
- NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement);
-
- if (cell.getType() != NurikabeType.BLACK) {
- return "Only black cells are allowed for this rule!";
- }
-
- NurikabeBoard modified = origBoardState.copy();
- NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement);
- modCell.setData(NurikabeType.WHITE.toValue());
-
- if(cell.getType() == NurikabeType.BLACK) {
- DisjointSets regions = NurikabeUtilities.getNurikabeRegions(destBoardState);
- Set adj = new HashSet<>(); //set to hold adjacent cells
- Point loc = cell.getLocation(); //position of placed cell
- List directions = Arrays.asList(new Point(-1, 0), new Point(1, 0), new Point(0, -1), new Point(0, 1));
- for(Point direction : directions) {
- NurikabeCell curr = destBoardState.getCell(loc.x + direction.x, loc.y + direction.y);
- if(curr != null) {
- if(curr.getType() == NurikabeType.WHITE || curr.getType() == NurikabeType.NUMBER) {
- adj.add(curr); //adds cells to adj only if they are white or number blocks
- }
- }
- }
- List numberedCells = new ArrayList<>(); //number value of number cells
- for (NurikabeCell c : adj) { //loops through adjacent cells
- Set disRow = regions.getSet(c); //set of white spaces
- for (NurikabeCell d : disRow) { //loops through white spaces
- if (d.getType() == NurikabeType.NUMBER) { //if the white space is a number
- numberedCells.add(d); //add that number to numberedCells
- }
- }
- }
- for (NurikabeCell number : numberedCells) { //loops through numberedCells
- if (regions.getSet(number).size() == number.getData()) { //if that cells white area is the exact
- return null; //size of the number of one of the number cells within that set
- }
- }
- }
- return "Does not follow from this rule at this index";
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.nurikabe.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities;
+import edu.rpi.legup.utility.DisjointSets;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class SurroundRegionDirectRule extends DirectRule {
+
+ public SurroundRegionDirectRule() {
+ super(
+ "NURI-BASC-0007",
+ "Surround Region",
+ "Surround Region",
+ "edu/rpi/legup/images/nurikabe/rules/SurroundBlack.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+
+ NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard();
+ NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard();
+
+ NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement);
+
+ if (cell.getType() != NurikabeType.BLACK) {
+ return "Only black cells are allowed for this rule!";
+ }
+
+ NurikabeBoard modified = origBoardState.copy();
+ NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement);
+ modCell.setData(NurikabeType.WHITE.toValue());
+
+ if (cell.getType() == NurikabeType.BLACK) {
+ DisjointSets regions =
+ NurikabeUtilities.getNurikabeRegions(destBoardState);
+ Set adj = new HashSet<>(); // set to hold adjacent cells
+ Point loc = cell.getLocation(); // position of placed cell
+ List directions =
+ Arrays.asList(
+ new Point(-1, 0), new Point(1, 0), new Point(0, -1), new Point(0, 1));
+ for (Point direction : directions) {
+ NurikabeCell curr =
+ destBoardState.getCell(loc.x + direction.x, loc.y + direction.y);
+ if (curr != null) {
+ if (curr.getType() == NurikabeType.WHITE
+ || curr.getType() == NurikabeType.NUMBER) {
+ adj.add(curr); // adds cells to adj only if they are white or number blocks
+ }
+ }
+ }
+ List numberedCells = new ArrayList<>(); // number value of number cells
+ for (NurikabeCell c : adj) { // loops through adjacent cells
+ Set disRow = regions.getSet(c); // set of white spaces
+ for (NurikabeCell d : disRow) { // loops through white spaces
+ if (d.getType() == NurikabeType.NUMBER) { // if the white space is a number
+ numberedCells.add(d); // add that number to numberedCells
+ }
+ }
+ }
+ for (NurikabeCell number : numberedCells) { // loops through numberedCells
+ if (regions.getSet(number).size()
+ == number.getData()) { // if that cells white area is the exact
+ return null; // size of the number of one of the number cells within that set
+ }
+ }
+ }
+ return "Does not follow from this rule at this index";
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooFewSpacesContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooFewSpacesContradictionRule.java
index d01dd806c..e7995165b 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooFewSpacesContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooFewSpacesContradictionRule.java
@@ -8,28 +8,30 @@
import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities;
import edu.rpi.legup.utility.DisjointSets;
-
import java.util.Set;
public class TooFewSpacesContradictionRule extends ContradictionRule {
- private final String NO_CONTRADICTION_MESSAGE = "Does not contain a contradiction at this index";
+ private final String NO_CONTRADICTION_MESSAGE =
+ "Does not contain a contradiction at this index";
private final String INVALID_USE_MESSAGE = "Contradiction must be a white or a numbered cell";
public TooFewSpacesContradictionRule() {
- super("NURI-CONT-0006",
+ super(
+ "NURI-CONT-0006",
"Too Few Spaces",
"A region cannot contain less spaces than its number.",
"edu/rpi/legup/images/nurikabe/contradictions/TooFewSpaces.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
@@ -40,7 +42,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE;
}
- DisjointSets regions = NurikabeUtilities.getPossibleWhiteRegions(nurikabeBoard);
+ DisjointSets regions =
+ NurikabeUtilities.getPossibleWhiteRegions(nurikabeBoard);
Set whiteRegion = regions.getSet(cell);
NurikabeCell numberedCell = null;
for (NurikabeCell c : whiteRegion) {
@@ -51,7 +54,9 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
}
if (numberedCell != null && whiteRegion.size() < numberedCell.getData()) {
- // System.err.println("Cell Value: " + numberedCell.getData() + ", Loc: " + cell.getLocation() + ", region: " + whiteRegion.size());
+ // System.err.println("Cell Value: " + numberedCell.getData() + ", Loc: " +
+ // cell.getLocation()
+ // + ", region: " + whiteRegion.size());
return null;
}
return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE;
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooManySpacesContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooManySpacesContradictionRule.java
index e5aa9f18b..7bd0883ef 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooManySpacesContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooManySpacesContradictionRule.java
@@ -8,29 +8,31 @@
import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities;
import edu.rpi.legup.utility.DisjointSets;
-
import java.util.ArrayList;
import java.util.Set;
public class TooManySpacesContradictionRule extends ContradictionRule {
- private final String NO_CONTRADICTION_MESSAGE = "Does not contain a contradiction at this index";
+ private final String NO_CONTRADICTION_MESSAGE =
+ "Does not contain a contradiction at this index";
private final String INVALID_USE_MESSAGE = "Contradiction must be a white or a numbered cell";
public TooManySpacesContradictionRule() {
- super("NURI-CONT-0007",
+ super(
+ "NURI-CONT-0007",
"Too Many Spaces",
"A region cannot contain more spaces than its number.",
"edu/rpi/legup/images/nurikabe/contradictions/TooManySpaces.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/UnreachableWhiteCellContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/UnreachableWhiteCellContradictionRule.java
index ec16475f1..c578d317f 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/UnreachableWhiteCellContradictionRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/UnreachableWhiteCellContradictionRule.java
@@ -7,7 +7,6 @@
import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities;
-
import java.awt.*;
import java.util.*;
@@ -17,19 +16,21 @@ public class UnreachableWhiteCellContradictionRule extends ContradictionRule {
private final String INVALID_USE_MESSAGE = "Does not contain a contradiction at this index";
public UnreachableWhiteCellContradictionRule() {
- super("NURI-CONT-0002",
+ super(
+ "NURI-CONT-0002",
"Unreachable White Cell",
"A white cell must be able to reach a white region",
"edu/rpi/legup/images/nurikabe/contradictions/CantReach.png");
}
/**
- * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule
+ * Checks whether the transition has a contradiction at the specific puzzleElement index using
+ * this rule
*
- * @param board board to check contradiction
+ * @param board board to check contradiction
* @param puzzleElement equivalent puzzleElement
* @return null if the transition contains a contradiction at the specified puzzleElement,
- * otherwise error message
+ * otherwise error message
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
@@ -44,7 +45,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
int width = nurikabeBoard.getWidth();
// Get regions
- HashMap whiteRegionMap = NurikabeUtilities.getWhiteRegionMap(nurikabeBoard);
+ HashMap whiteRegionMap =
+ NurikabeUtilities.getWhiteRegionMap(nurikabeBoard);
if (whiteRegionMap.containsKey(cell)) {
return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE;
}
@@ -83,15 +85,17 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
for (NurikabeCell n : adj) {
int regionNeed = whiteRegionMap.getOrDefault(n, -1);
if (pathLength <= regionNeed) {
- return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE;
+ return super.getNoContradictionMessage()
+ + ": "
+ + this.NO_CONTRADICTION_MESSAGE;
}
}
}
for (NurikabeCell n : adj) {
if (!visited.getOrDefault(n, false)
- && (n.getType() == NurikabeType.UNKNOWN ||
- n.getType() == NurikabeType.WHITE)) {
+ && (n.getType() == NurikabeType.UNKNOWN
+ || n.getType() == NurikabeType.WHITE)) {
visited.put(n, true);
queue.add(n);
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/WhiteBottleNeckDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/WhiteBottleNeckDirectRule.java
index dd337858c..434e7ccde 100644
--- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/WhiteBottleNeckDirectRule.java
+++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/WhiteBottleNeckDirectRule.java
@@ -1,69 +1,72 @@
-package edu.rpi.legup.puzzle.nurikabe.rules;
-
-import edu.rpi.legup.model.gameboard.Board;
-import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.model.rules.DirectRule;
-import edu.rpi.legup.model.rules.ContradictionRule;
-import edu.rpi.legup.model.tree.TreeNode;
-import edu.rpi.legup.model.tree.TreeTransition;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
-
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-public class WhiteBottleNeckDirectRule extends DirectRule {
-
- public WhiteBottleNeckDirectRule() {
- super("NURI-BASC-0009",
- "White Bottle Neck",
- "If a region needs more whites and there is only one path for the region to expand, then those unknowns must be white.", "edu/rpi/legup/images/nurikabe/rules/OneUnknownWhite.png");
- }
-
- /**
- * Checks whether the child node logically follows from the parent node
- * at the specific puzzleElement index using this rule
- *
- * @param transition transition to check
- * @param puzzleElement equivalent puzzleElement
- * @return null if the child node logically follow from the parent node at the specified puzzleElement,
- * otherwise error message
- */
- @Override
- public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
- Set contras = new LinkedHashSet<>();
- contras.add(new NoNumberContradictionRule());
- contras.add(new TooFewSpacesContradictionRule());
-
- NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard();
- NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard();
-
- NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement);
-
- if (cell.getType() != NurikabeType.WHITE) {
- return "Only white cells are allowed for this rule!";
- }
- NurikabeBoard modified = origBoardState.copy();
- NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement);
- modCell.setData(NurikabeType.BLACK.toValue());
-
- for (ContradictionRule contraRule : contras) {
- if (contraRule.checkContradiction(modified) == null) {
- return null;
- }
- }
- return "This is not the only way for white to escape!";
- }
-
- /**
- * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}.
- *
- * @param node tree node used to create default transition board
- * @return default board or null if this rule cannot be applied to this tree node
- */
- @Override
- public Board getDefaultBoard(TreeNode node) {
- return null;
- }
-}
+package edu.rpi.legup.puzzle.nurikabe.rules;
+
+import edu.rpi.legup.model.gameboard.Board;
+import edu.rpi.legup.model.gameboard.PuzzleElement;
+import edu.rpi.legup.model.rules.ContradictionRule;
+import edu.rpi.legup.model.rules.DirectRule;
+import edu.rpi.legup.model.tree.TreeNode;
+import edu.rpi.legup.model.tree.TreeTransition;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
+import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+public class WhiteBottleNeckDirectRule extends DirectRule {
+
+ public WhiteBottleNeckDirectRule() {
+ super(
+ "NURI-BASC-0009",
+ "White Bottle Neck",
+ "If a region needs more whites and there is only one path for the region to expand,"
+ + " then those unknowns must be white.",
+ "edu/rpi/legup/images/nurikabe/rules/OneUnknownWhite.png");
+ }
+
+ /**
+ * Checks whether the child node logically follows from the parent node at the specific
+ * puzzleElement index using this rule
+ *
+ * @param transition transition to check
+ * @param puzzleElement equivalent puzzleElement
+ * @return null if the child node logically follow from the parent node at the specified
+ * puzzleElement, otherwise error message
+ */
+ @Override
+ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
+ Set contras = new LinkedHashSet<>();
+ contras.add(new NoNumberContradictionRule());
+ contras.add(new TooFewSpacesContradictionRule());
+
+ NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard();
+ NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard();
+
+ NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement);
+
+ if (cell.getType() != NurikabeType.WHITE) {
+ return "Only white cells are allowed for this rule!";
+ }
+ NurikabeBoard modified = origBoardState.copy();
+ NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement);
+ modCell.setData(NurikabeType.BLACK.toValue());
+
+ for (ContradictionRule contraRule : contras) {
+ if (contraRule.checkContradiction(modified) == null) {
+ return null;
+ }
+ }
+ return "This is not the only way for white to escape!";
+ }
+
+ /**
+ * Creates a transition {@link Board} that has this rule applied to it using the {@link
+ * TreeNode}.
+ *
+ * @param node tree node used to create default transition board
+ * @return default board or null if this rule cannot be applied to this tree node
+ */
+ @Override
+ public Board getDefaultBoard(TreeNode node) {
+ return null;
+ }
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java
index e8f9ffc0d..8b0b8e6d5 100644
--- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java
+++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java
@@ -18,9 +18,7 @@ public ShortTruthTable() {
this.factory = new ShortTruthTableCellFactory();
}
- /**
- * Initializes the game board. Called by the invoker of the class
- */
+ /** Initializes the game board. Called by the invoker of the class */
@Override
public void initializeView() {
ShortTruthTableBoard sttBoard = (ShortTruthTableBoard) currentBoard;
@@ -44,8 +42,8 @@ public Board generatePuzzle(int difficulty) {
/**
* Determines if the given dimensions are valid for Short Truth Table
*
- * @param rows the number of rows
- * @param columns the number of columns
+ * @param rows the number of rows
+ * @param columns the number of columns
* @return true if the given dimensions are valid for Short Truth Table, false otherwise
*/
public boolean isValidDimensions(int rows, int columns) {
@@ -100,7 +98,6 @@ public boolean isBoardComplete(Board board) {
}
}
return true;
-
}
/**
@@ -109,7 +106,5 @@ public boolean isBoardComplete(Board board) {
* @param board the board that has changed
*/
@Override
- public void onBoardChange(Board board) {
-
- }
-}
\ No newline at end of file
+ public void onBoardChange(Board board) {}
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java
index e5011182a..519a61974 100644
--- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java
+++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java
@@ -1,17 +1,12 @@
package edu.rpi.legup.puzzle.shorttruthtable;
-import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.GridBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-
-import edu.rpi.legup.puzzle.lightup.LightUpCell;
-import edu.rpi.legup.puzzle.shorttruthtable.*;
-
import java.awt.*;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.HashSet;
public class ShortTruthTableBoard extends GridBoard {
@@ -22,10 +17,8 @@ public ShortTruthTableBoard(int width, int height, ShortTruthTableStatement[] st
super(width, height);
this.statements = statements;
-
}
-
public Set getCellsWithSymbol(char symbol) {
Set cells = new HashSet();
for (int x = 0; x < this.dimension.width; x++) {
@@ -48,23 +41,23 @@ public ShortTruthTableCell getCell(int x, int y) {
return (ShortTruthTableCell) super.getCell(x, y);
}
-
@Override
public ShortTruthTableBoard copy() {
- //Copy the statements
- ShortTruthTableStatement[] statementsCopy = new ShortTruthTableStatement[this.statements.length];
+ // Copy the statements
+ ShortTruthTableStatement[] statementsCopy =
+ new ShortTruthTableStatement[this.statements.length];
for (int i = 0; i < statements.length; i++) {
statementsCopy[i] = this.statements[i].copy();
}
- //copy the board and set the cells
- ShortTruthTableBoard boardCopy = new ShortTruthTableBoard(getWidth(), getHeight(), statementsCopy);
+ // copy the board and set the cells
+ ShortTruthTableBoard boardCopy =
+ new ShortTruthTableBoard(getWidth(), getHeight(), statementsCopy);
for (int r = 0; r < this.dimension.height; r++) {
for (int c = 0; c < this.dimension.width; c++) {
if (r % 2 == 0 && c < statementsCopy[r / 2].getLength()) {
boardCopy.setCell(c, r, statementsCopy[r / 2].getCell(c));
- }
- else {
+ } else {
boardCopy.setCell(c, r, getCell(c, r).copy());
}
}
@@ -76,14 +69,14 @@ public ShortTruthTableBoard copy() {
System.out.println("original:\n" + this);
System.out.println("copy:\n" + boardCopy);
return boardCopy;
-
}
public ShortTruthTableStatement[] getStatements() {
return statements;
}
- public static List copyStatementList(List statements) {
+ public static List copyStatementList(
+ List statements) {
List copy = new ArrayList();
for (int i = 0; i < statements.size(); i++) {
copy.add(statements.get(i).copy());
@@ -91,13 +84,12 @@ public static List copyStatementList(List {
- //The symbol on the cell
+ // The symbol on the cell
private char symbol;
- //This is a reference to the statement that contains this cell
+ // This is a reference to the statement that contains this cell
private ShortTruthTableStatement statement;
- //Constructors
+ // Constructors
public ShortTruthTableCell(char symbol, ShortTruthTableCellType cellType, Point location) {
super(cellType, location);
this.symbol = symbol;
}
-
/**
* Constructs a new NOT_IN_PLAY Cell
*
@@ -33,8 +29,7 @@ public ShortTruthTableCell(Point location) {
this(' ', ShortTruthTableCellType.NOT_IN_PLAY, location);
}
-
- //Getters
+ // Getters
public ShortTruthTableStatement getStatementReference() {
return statement;
@@ -65,12 +60,12 @@ public int getY() {
return (int) location.getY();
}
-
public boolean isAssigned() {
- return getType() == ShortTruthTableCellType.TRUE || getType() == ShortTruthTableCellType.FALSE;
+ return getType() == ShortTruthTableCellType.TRUE
+ || getType() == ShortTruthTableCellType.FALSE;
}
- //Setters
+ // Setters
void setStatementReference(ShortTruthTableStatement statement) {
this.statement = statement;
@@ -86,7 +81,7 @@ public void setGiven(ShortTruthTableCellType type) {
setGiven(true);
}
- //Modifiers
+ // Modifiers
public void cycleTypeForward() {
switch (data) {
@@ -109,16 +104,14 @@ public void cycleTypeBackward() {
cycleTypeForward();
}
-
- //TO STRING
+ // TO STRING
@Override
public String toString() {
return String.format("STTCell: %c %2d %-11s %s", symbol, index, data, location.toString());
}
-
- //Copy function
+ // Copy function
@Override
public ShortTruthTableCell copy() {
@@ -168,8 +161,7 @@ public void setType(Element e, MouseEvent m) {
if (this.symbol > 'Z') {
this.symbol = 'A';
}
- }
- else {
+ } else {
if (m.getButton() == MouseEvent.BUTTON3) {
this.symbol -= 1;
if (this.symbol < 'A') {
@@ -184,37 +176,30 @@ public void setType(Element e, MouseEvent m) {
if (m.getButton() == MouseEvent.BUTTON1) {
if (this.symbol == '^') {
this.symbol = '|';
- }
- else {
+ } else {
if (this.symbol == '|') {
this.symbol = '>';
- }
- else {
+ } else {
if (this.symbol == '>') {
this.symbol = '-';
- }
- else {
+ } else {
if (this.symbol == '-') {
this.symbol = '^';
}
}
}
}
- }
- else {
+ } else {
if (m.getButton() == MouseEvent.BUTTON3) {
if (this.symbol == '^') {
this.symbol = '-';
- }
- else {
+ } else {
if (this.symbol == '|') {
this.symbol = '^';
- }
- else {
+ } else {
if (this.symbol == '>') {
this.symbol = '|';
- }
- else {
+ } else {
if (this.symbol == '-') {
this.symbol = '>';
}
@@ -229,4 +214,4 @@ public void setType(Element e, MouseEvent m) {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellFactory.java
index 99d626447..df74afdc9 100644
--- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellFactory.java
+++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellFactory.java
@@ -4,57 +4,58 @@
import edu.rpi.legup.model.gameboard.ElementFactory;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.save.InvalidFileFormatException;
+import java.awt.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import java.awt.*;
-
public class ShortTruthTableCellFactory extends ElementFactory {
/**
* Creates a puzzleElement based on the xml document Node and adds it to the board
*
- * @param node node that represents the puzzleElement
+ * @param node node that represents the puzzleElement
* @param board board to add the newly created cell
* @return newly created cell from the xml document Node
* @throws InvalidFileFormatException if file is invalid
*/
@Override
- public ShortTruthTableCell importCell(Node node, Board board) throws InvalidFileFormatException {
+ public ShortTruthTableCell importCell(Node node, Board board)
+ throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("cell")) {
- throw new InvalidFileFormatException("ShortTruthTable Factory: unknown puzzleElement puzzleElement");
+ throw new InvalidFileFormatException(
+ "ShortTruthTable Factory: unknown puzzleElement puzzleElement");
}
ShortTruthTableBoard sttBoard = (ShortTruthTableBoard) board;
- //get the attributes for the cell
+ // get the attributes for the cell
NamedNodeMap attributeList = node.getAttributes();
int rowIndex = Integer.valueOf(attributeList.getNamedItem("row_index").getNodeValue());
- int charIndex = Integer.valueOf(attributeList.getNamedItem("char_index").getNodeValue());
+ int charIndex =
+ Integer.valueOf(attributeList.getNamedItem("char_index").getNodeValue());
String cellType = attributeList.getNamedItem("type").getNodeValue();
- //modify the appropriate cell
- ShortTruthTableCell cell = (ShortTruthTableCell) sttBoard.getCell(charIndex, rowIndex * 2);
+ // modify the appropriate cell
+ ShortTruthTableCell cell =
+ (ShortTruthTableCell) sttBoard.getCell(charIndex, rowIndex * 2);
cell.setData(ShortTruthTableCellType.valueOf(cellType));
return cell;
- }
- catch (NumberFormatException e) {
- throw new InvalidFileFormatException("nurikabe Factory: unknown value where integer expected");
- }
- catch (NullPointerException e) {
+ } catch (NumberFormatException e) {
+ throw new InvalidFileFormatException(
+ "nurikabe Factory: unknown value where integer expected");
+ } catch (NullPointerException e) {
throw new InvalidFileFormatException("nurikabe Factory: could not find attribute(s)");
}
-
}
/**
* Creates a xml document puzzleElement from a cell for exporting
*
- * @param document xml document
+ * @param document xml document
* @param puzzleElement PuzzleElement cell
* @return xml PuzzleElement
*/
diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java
index c997faf5f..d5a8292a2 100644
--- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java
+++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java
@@ -1,11 +1,14 @@
package edu.rpi.legup.puzzle.shorttruthtable;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
public enum ShortTruthTableCellType {
-
- FALSE(0), TRUE(1), UNKNOWN(-1), NOT_IN_PLAY(-2), PARENTHESIS(-3);
+ FALSE(0),
+ TRUE(1),
+ UNKNOWN(-1),
+ NOT_IN_PLAY(-2),
+ PARENTHESIS(-3);
public int value;
private static Map map = new HashMap<>();
@@ -37,7 +40,6 @@ public static char toChar(ShortTruthTableCellType type) {
return ' ';
}
-
/**
* Returns true if this cell holds the value either TRUE or FALSE
*
@@ -47,7 +49,6 @@ public boolean isTrueOrFalse() {
return value == 0 || value == 1;
}
-
public ShortTruthTableCellType getNegation() {
switch (value) {
case 1:
@@ -63,5 +64,4 @@ public static ShortTruthTableCellType getDefaultType(char c) {
if (c == '(' || c == ')') return PARENTHESIS;
return UNKNOWN;
}
-
-}
\ No newline at end of file
+}
diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java
index bddde44a5..172867f5a 100644
--- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java
+++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.controller.ElementController;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-
import java.awt.event.MouseEvent;
public class ShortTruthTableController extends ElementController {
@@ -17,13 +16,16 @@ public void changeCell(MouseEvent e, PuzzleElement data) {
if (e.getButton() == MouseEvent.BUTTON1) {
if (e.isControlDown()) {
- this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY());
- }
- else {
+ this.boardView
+ .getSelectionPopupMenu()
+ .show(
+ boardView,
+ this.boardView.getCanvas().getX() + e.getX(),
+ this.boardView.getCanvas().getY() + e.getY());
+ } else {
cell.cycleTypeForward();
}
- }
- else {
+ } else {
if (e.getButton() == MouseEvent.BUTTON3) {
cell.cycleTypeBackward();
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java
index b787921ad..43e1d2299 100644
--- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java
+++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java
@@ -1,20 +1,19 @@
package edu.rpi.legup.puzzle.shorttruthtable;
-import edu.rpi.legup.ui.boardview.GridElementView;
import edu.rpi.legup.app.LegupPreferences;
-
+import edu.rpi.legup.ui.boardview.GridElementView;
import java.awt.*;
public class ShortTruthTableElementView extends GridElementView {
- //Font
+ // Font
private static final Font FONT = new Font("TimesRoman", Font.BOLD, 16);
private static final Color FONT_COLOR = Color.BLACK;
- //Square Colors
- private static final Color TRUE_COLOR = new Color(0, 130, 0);//green
+ // Square Colors
+ private static final Color TRUE_COLOR = new Color(0, 130, 0); // green
private static final Color TRUE_COLOR_COLORBLIND = new Color(0, 0, 255);
- private static final Color FALSE_COLOR = new Color(200, 0, 0);//red
+ private static final Color FALSE_COLOR = new Color(200, 0, 0); // red
private static final Color FALSE_COLOR_COLORBLIND = new Color(255, 0, 0);
private static final Color UNKNOWN_COLOR = Color.WHITE;
@@ -23,7 +22,6 @@ public ShortTruthTableElementView(ShortTruthTableCell cell) {
super(cell);
}
-
/**
* Gets the PuzzleElement associated with this view
*
@@ -37,14 +35,14 @@ public ShortTruthTableCell getPuzzleElement() {
@Override
public void drawElement(Graphics2D graphics2D) {
- //get information about the cell
+ // get information about the cell
ShortTruthTableCell cell = (ShortTruthTableCell) puzzleElement;
ShortTruthTableCellType type = cell.getData();
- //do not draw the cell if it is not in play
+ // do not draw the cell if it is not in play
if (type == ShortTruthTableCellType.NOT_IN_PLAY) return;
- //fill in background color of the cell
+ // fill in background color of the cell
graphics2D.setStroke(new BasicStroke(1));
LegupPreferences prefs = LegupPreferences.getInstance();
switch (type) {
@@ -68,15 +66,14 @@ public void drawElement(Graphics2D graphics2D) {
}
graphics2D.fillRect(location.x, location.y, size.width, size.height);
- //Draw the symbol on the cell
+ // Draw the symbol on the cell
graphics2D.setColor(FONT_COLOR);
graphics2D.setFont(FONT);
FontMetrics metrics = graphics2D.getFontMetrics(FONT);
String value = String.valueOf(cell.getSymbol());
int xText = location.x + (size.width - metrics.stringWidth(value)) / 2;
int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent();
- graphics2D.drawString(ShortTruthTableOperation.getLogicSymbol(cell.getSymbol()), xText, yText);
-
-
+ graphics2D.drawString(
+ ShortTruthTableOperation.getLogicSymbol(cell.getSymbol()), xText, yText);
}
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java
index 9d6553c7c..0914c159a 100644
--- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java
@@ -2,7 +2,6 @@
import edu.rpi.legup.model.PuzzleExporter;
import edu.rpi.legup.model.gameboard.PuzzleElement;
-import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
import org.w3c.dom.Document;
public class ShortTruthTableExporter extends PuzzleExporter {
@@ -16,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
ShortTruthTableBoard board;
if (puzzle.getTree() != null) {
board = (ShortTruthTableBoard) puzzle.getTree().getRootNode().getBoard();
- }
- else {
+ } else {
board = (ShortTruthTableBoard) puzzle.getBoardView().getBoard();
}
@@ -33,12 +31,12 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
dataElement.appendChild(statementElement);
}
-
for (PuzzleElement puzzleElement : board.getPuzzleElements()) {
ShortTruthTableCell cell = board.getCellFromElement(puzzleElement);
if (!cell.getType().isTrueOrFalse()) continue;
- org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement);
+ org.w3c.dom.Element cellElement =
+ puzzle.getFactory().exportCell(newDocument, puzzleElement);
dataElement.appendChild(cellElement);
}
diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableImporter.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableImporter.java
index 84d04fb45..396668380 100644
--- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableImporter.java
+++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableImporter.java
@@ -2,16 +2,15 @@
import edu.rpi.legup.model.PuzzleImporter;
import edu.rpi.legup.save.InvalidFileFormatException;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
+import javax.swing.*;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
class ShortTruthTableImporter extends PuzzleImporter {
@@ -19,9 +18,9 @@ public ShortTruthTableImporter(ShortTruthTable stt) {
super(stt);
}
-
/**
- * Parse a string into all the cells, the y position of the statement is passed so the y position can be set
+ * Parse a string into all the cells, the y position of the statement is passed so the y
+ * position can be set
*
* @param statement
* @param y
@@ -29,83 +28,90 @@ public ShortTruthTableImporter(ShortTruthTable stt) {
*/
private List getCells(String statement, int y) {
List cells = new ArrayList();
- //go through each char in the statement and make a cell for it
+ // go through each char in the statement and make a cell for it
for (int i = 0; i < statement.length(); i++) {
char c = statement.charAt(i);
- ShortTruthTableCell cell = new ShortTruthTableCell(c, ShortTruthTableCellType.getDefaultType(c), new Point(i, y));
- //it is modifiable if the type is unknown
+ ShortTruthTableCell cell =
+ new ShortTruthTableCell(
+ c, ShortTruthTableCellType.getDefaultType(c), new Point(i, y));
+ // it is modifiable if the type is unknown
cell.setModifiable(cell.getType() == ShortTruthTableCellType.UNKNOWN);
cells.add(cell);
}
return cells;
}
-
/**
- * Parses the statementData into all the cells (with symbols) and statements for the
- * puzzle. All cells are set to UNKNWON, it their value is given, it will be set later
- * in the import process.
- *
- * Both allCells and statements act as returns, They should be passed as empty arrays
+ * Parses the statementData into all the cells (with symbols) and statements for the puzzle. All
+ * cells are set to UNKNWON, it their value is given, it will be set later in the import
+ * process.
+ *
+ *
Both allCells and statements act as returns, They should be passed as empty arrays
*
* @param statementData The data to be imported
- * @param allCells returns all the cells as a jagged 2d array
- * @param statements returns all the statements
+ * @param allCells returns all the cells as a jagged 2d array
+ * @param statements returns all the statements
* @return the length, in chars, of the longest statement
*/
- private int parseAllStatementsAndCells(final NodeList statementData,
- List> allCells,
- List statements) throws InvalidFileFormatException {
+ private int parseAllStatementsAndCells(
+ final NodeList statementData,
+ List> allCells,
+ List statements)
+ throws InvalidFileFormatException {
int maxStatementLength = 0;
- //get a 2D arraylist of all the cells
+ // get a 2D arraylist of all the cells
for (int i = 0; i < statementData.getLength(); i++) {
- //Get the atributes from the statement i in the file
+ // Get the atributes from the statement i in the file
NamedNodeMap attributeList = statementData.item(i).getAttributes();
String statementRep = attributeList.getNamedItem("representation").getNodeValue();
System.out.println("STATEMENT REP: " + statementRep);
- System.out.println("ROW INDEX: " + attributeList.getNamedItem("row_index").getNodeValue());
- //parser time (on statementRep)
- //if (!validGrammar(statementRep)) throw some error
+ System.out.println(
+ "ROW INDEX: " + attributeList.getNamedItem("row_index").getNodeValue());
+ // parser time (on statementRep)
+ // if (!validGrammar(statementRep)) throw some error
if (!validGrammar(statementRep)) {
JOptionPane.showMessageDialog(null, "ERROR: Invalid file syntax");
- throw new InvalidFileFormatException("shorttruthtable importer: invalid sentence syntax");
+ throw new InvalidFileFormatException(
+ "shorttruthtable importer: invalid sentence syntax");
}
int rowIndex = Integer.valueOf(attributeList.getNamedItem("row_index").getNodeValue());
- //get the cells for the statement
+ // get the cells for the statement
List rowOfCells = getCells(statementRep, rowIndex * 2);
allCells.add(rowOfCells);
statements.add(new ShortTruthTableStatement(statementRep, rowOfCells));
- //keep track of the length of the longest statement
+ // keep track of the length of the longest statement
maxStatementLength = Math.max(maxStatementLength, statementRep.length());
-
}
return maxStatementLength;
}
- private int parseAllStatementsAndCells(String[] statementData,
- List> allCells,
- List statements) throws IllegalArgumentException {
+ private int parseAllStatementsAndCells(
+ String[] statementData,
+ List> allCells,
+ List statements)
+ throws IllegalArgumentException {
int maxStatementLength = 0;
for (int i = 0; i < statementData.length; i++) {
if (!validGrammar(statementData[i])) {
JOptionPane.showMessageDialog(null, "ERROR: Invalid file syntax");
- throw new IllegalArgumentException("shorttruthtable importer: invalid sentence syntax");
+ throw new IllegalArgumentException(
+ "shorttruthtable importer: invalid sentence syntax");
}
- //get the cells for the statement
+ // get the cells for the statement
List rowOfCells = getCells(statementData[i], i * 2);
allCells.add(rowOfCells);
statements.add(new ShortTruthTableStatement(statementData[i], rowOfCells));
- //keep track of the length of the longest statement
+ // keep track of the length of the longest statement
maxStatementLength = Math.max(maxStatementLength, statementData[i].length());
}
@@ -115,7 +121,7 @@ private int parseAllStatementsAndCells(String[] statementData,
protected boolean validGrammar(String sentence) {
int open = 0;
int close = 0;
- char[] valid_characters = new char[]{'^', 'v', '!', '>', '-', '&', '|', '~', '$', '%'};
+ char[] valid_characters = new char[] {'^', 'v', '!', '>', '-', '&', '|', '~', '$', '%'};
for (int i = 0; i < sentence.length(); i++) {
char s = sentence.charAt(i);
if (s == '(' || s == ')') {
@@ -155,8 +161,7 @@ protected boolean validGrammar(String sentence) {
}
}
}
- }
- else {
+ } else {
if (i != sentence.length() - 1) {
if (Character.isLetter(sentence.charAt(i + 1))) {
System.out.println("Invalid next character");
@@ -170,75 +175,81 @@ protected boolean validGrammar(String sentence) {
return open == close;
}
- private ShortTruthTableBoard generateBoard(List> allCells,
- List statements,
- int width) {
+ private ShortTruthTableBoard generateBoard(
+ List> allCells,
+ List statements,
+ int width) {
- //calculate the height for the board
+ // calculate the height for the board
int height = statements.size() * 2 - 1;
- //instantiate the board with the correct width and height
- ShortTruthTableBoard sttBoard = new ShortTruthTableBoard(width, height,
- statements.toArray(new ShortTruthTableStatement[statements.size()]));
+ // instantiate the board with the correct width and height
+ ShortTruthTableBoard sttBoard =
+ new ShortTruthTableBoard(
+ width,
+ height,
+ statements.toArray(new ShortTruthTableStatement[statements.size()]));
- //set the cells in the board. create not_in_play cells where needed
+ // set the cells in the board. create not_in_play cells where needed
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
- //get the statement index for this row of the table
+ // get the statement index for this row of the table
int statementIndex = y / 2;
- //get the cell at this location; or create a not_in_play one if necessary
+ // get the cell at this location; or create a not_in_play one if necessary
ShortTruthTableCell cell = null;
- //for a cell to exist at (x, y), it must be a valid row and within the statement length
+ // for a cell to exist at (x, y), it must be a valid row and within the statement
+ // length
if (y % 2 == 0 && x < statements.get(statementIndex).getLength()) {
cell = allCells.get(statementIndex).get(x);
- System.out.println("Importer: check cell statement ref: " + cell.getStatementReference());
- }
- else {
- //if it is not a valid cell space, add a NOT_IN_PLAY cell
- cell = new ShortTruthTableCell(' ', ShortTruthTableCellType.NOT_IN_PLAY, new Point(x, y));
+ System.out.println(
+ "Importer: check cell statement ref: " + cell.getStatementReference());
+ } else {
+ // if it is not a valid cell space, add a NOT_IN_PLAY cell
+ cell =
+ new ShortTruthTableCell(
+ ' ', ShortTruthTableCellType.NOT_IN_PLAY, new Point(x, y));
cell.setModifiable(false);
}
- //add the cell to the table
+ // add the cell to the table
cell.setIndex(y * width + x);
sttBoard.setCell(x, y, cell);
}
}
return sttBoard;
-
}
+ private void setGivenCells(
+ ShortTruthTableBoard sttBoard,
+ Element dataElement,
+ NodeList cellData,
+ List