diff --git a/bin/main/edu/rpi/legup/legup/config b/bin/main/edu/rpi/legup/legup/config index 9a40395f1..cfa1ebeac 100644 --- a/bin/main/edu/rpi/legup/legup/config +++ b/bin/main/edu/rpi/legup/legup/config @@ -1,14 +1,43 @@ - + - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 288e1dcb2..d97583d68 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,8 @@ mainClassName = 'edu.rpi.legup.Legup' sourceCompatibility = 1.8 dependencies { + implementation 'org.jetbrains:annotations:20.1.0' + implementation 'org.jetbrains:annotations:20.1.0' compile project(':legup-update') compile 'com.google.firebase:firebase-admin:6.3.0' compile 'org.apache.httpcomponents:httpclient:4.5.1' 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 b05e5b1c9..dcc9d6443 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java @@ -35,35 +35,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 if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { - int width = Integer.valueOf(boardElement.getAttribute("width")); - int height = Integer.valueOf(boardElement.getAttribute("height")); + } else if (!boardElement.getAttribute("width").isEmpty() + && !boardElement.getAttribute("height").isEmpty()) { + 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); @@ -75,7 +83,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); @@ -85,41 +94,59 @@ 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") || !axis1.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}"); + 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}"); } - 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"); + 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"); } 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++) { @@ -128,18 +155,22 @@ 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"); + throw new InvalidFileFormatException("BattleShip Importer: " + + "unknown value where integer expected"); } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTentForTreeContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTentForTreeContradictionRule.java index eb70b2b34..a27966da0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTentForTreeContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTentForTreeContradictionRule.java @@ -6,6 +6,10 @@ import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.TreeTentCell; import edu.rpi.legup.puzzle.treetent.TreeTentType; +import edu.rpi.legup.puzzle.treetent.TreeTentLine; + +import java.util.List; +import java.util.Iterator; public class NoTentForTreeContradictionRule extends ContradictionRule { @@ -35,6 +39,28 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { if (adjTent == 0 && adjUnknown == 0) { return null; } else { + if(adjTent != 0) + { + List lines = treeTentBoard.getLines(); + List adjTents = treeTentBoard.getAdjacent(cell, TreeTentType.TENT); + for(TreeTentLine l : lines) + { + Iterator i = adjTents.iterator(); + while(i.hasNext()) + { + TreeTentCell t = i.next(); + if (t.getLocation().equals(l.getC1().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) + { + i.remove(); + } + if (t.getLocation().equals(l.getC2().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) + { + i.remove(); + } + } + } + if(adjTents.size() == 0) {return null;} + } return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeBasicRule.java index 4851834bd..e50ca4f88 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeBasicRule.java @@ -9,6 +9,7 @@ import edu.rpi.legup.puzzle.treetent.TreeTentCell; import edu.rpi.legup.puzzle.treetent.TreeTentLine; import edu.rpi.legup.puzzle.treetent.TreeTentType; +import java.util.ArrayList; import java.util.List; @@ -34,31 +35,66 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (!(puzzleElement instanceof TreeTentLine)) { return super.getInvalidUseOfRuleMessage() + ": Lines must be created for this rule."; } - TreeTentBoard initialBoard = (TreeTentBoard) transition.getParents().get(0).getBoard(); - TreeTentLine initLine = (TreeTentLine) initialBoard.getPuzzleElement(puzzleElement); - TreeTentBoard finalBoard = (TreeTentBoard) transition.getBoard(); - TreeTentLine finalLine = (TreeTentLine) finalBoard.getPuzzleElement(puzzleElement); - TreeTentCell tree, tent; - if (finalLine.getC1().getType() == TreeTentType.TREE || finalLine.getC2().getType() == TreeTentType.TENT) { - tree = finalLine.getC1(); - tent = finalLine.getC2(); - } else if (finalLine.getC2().getType() == TreeTentType.TREE || finalLine.getC1().getType() == TreeTentType.TENT) { - tree = finalLine.getC2(); - tent = finalLine.getC1(); + TreeTentBoard board = (TreeTentBoard)transition.getBoard(); + TreeTentLine line = (TreeTentLine)board.getPuzzleElement(puzzleElement); + TreeTentCell tree,tent; + if (line.getC1().getType() == TreeTentType.TREE && line.getC2().getType() == TreeTentType.TENT) { + tree = line.getC1(); + tent = line.getC2(); + } else if (line.getC2().getType() == TreeTentType.TREE && line.getC1().getType() == TreeTentType.TENT) { + tree = line.getC2(); + tent = line.getC1(); } else { return super.getInvalidUseOfRuleMessage() + ": This line must connect a tree to a tent."; } - - if (isForced(initialBoard, tree, tent)) { + int forced = isForced(board, tree, tent, line); + if(forced == 1) + { return null; - } else { - return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; + } + else if (forced == -1) + { + return super.getInvalidUseOfRuleMessage() + ": This tree already has a link"; + } + else if (forced == -2) + { + return super.getInvalidUseOfRuleMessage() + ": This tent already has a link"; + } + else + { + return super.getInvalidUseOfRuleMessage() + ": This tree and tent don't need to be linked."; } } - private boolean isForced(TreeTentBoard board, TreeTentCell tree, TreeTentCell tent) { - List tents = board.getAdjacent(tree, TreeTentType.TENT); - return !tents.isEmpty(); + private Integer isForced(TreeTentBoard board, TreeTentCell tree, TreeTentCell tent, TreeTentLine line) + { + List adjTents = board.getAdjacent(tree, TreeTentType.TENT); + adjTents.remove(tent); + List lines = board.getLines(); + lines.remove(line); + for(TreeTentLine l : lines) + { + ArrayList toRemove = new ArrayList<>(); + if(l.getC1().getLocation().equals(tree.getLocation()) || l.getC2().getLocation().equals(tree.getLocation())) {return -2;} + for(TreeTentCell c : adjTents) + { + if(l.getC1().getLocation().equals(c.getLocation())) + { + if(l.getC2().getLocation().equals(tree.getLocation())) {return -1;} + toRemove.add(c); + + } + else if(l.getC2().getLocation().equals(c.getLocation())) + { + if(l.getC1().getLocation().equals(tree.getLocation())) {return -1;} + toRemove.add(c); + } + } + for(TreeTentCell c : toRemove) {adjTents.remove(c);} + toRemove.clear(); + } + if(adjTents.size() == 0) {return 1;} + else {return 0;} } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TreeForTentBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TreeForTentBasicRule.java index f68d85e38..6492d60e6 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TreeForTentBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TreeForTentBasicRule.java @@ -1,6 +1,7 @@ package edu.rpi.legup.puzzle.treetent.rules; import java.util.List; +import java.util.ArrayList; import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.BasicRule; @@ -44,7 +45,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } else { return super.getInvalidUseOfRuleMessage() + ": This line must connect a tree to a tent."; } - int forced = isForced(board, tree, tent); + int forced = isForced(board, tree, tent, line); if(forced == 1) { return null; @@ -63,28 +64,32 @@ else if (forced == -2) } } - private Integer isForced(TreeTentBoard board, TreeTentCell tree, TreeTentCell tent) + private Integer isForced(TreeTentBoard board, TreeTentCell tree, TreeTentCell tent, TreeTentLine line) { List adjTrees = board.getAdjacent(tent, TreeTentType.TREE); adjTrees.remove(tree); List lines = board.getLines(); + lines.remove(line); for(TreeTentLine l : lines) { + ArrayList toRemove = new ArrayList<>(); if(l.getC1().getLocation().equals(tree.getLocation()) || l.getC2().getLocation().equals(tree.getLocation())) {return -2;} for(TreeTentCell c : adjTrees) { if(l.getC1().getLocation().equals(c.getLocation())) { if(l.getC2().getLocation().equals(tent.getLocation())) {return -1;} - adjTrees.remove(c); + toRemove.add(c); } else if(l.getC2().getLocation().equals(c.getLocation())) { if(l.getC1().getLocation().equals(tent.getLocation())) {return -1;} - adjTrees.remove(c); + toRemove.add(c); } } + for(TreeTentCell c : toRemove) {adjTrees.remove(c);} + toRemove.clear(); } if(adjTrees.size() == 0) {return 1;} else {return 0;} diff --git a/src/main/java/edu/rpi/legup/ui/DynamicView.java b/src/main/java/edu/rpi/legup/ui/DynamicView.java index 671e2d428..40641c851 100644 --- a/src/main/java/edu/rpi/legup/ui/DynamicView.java +++ b/src/main/java/edu/rpi/legup/ui/DynamicView.java @@ -1,5 +1,8 @@ package edu.rpi.legup.ui; +import edu.rpi.legup.app.GameBoardFacade; +import edu.rpi.legup.model.Puzzle; +import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialFonts; @@ -40,10 +43,18 @@ private JPanel setUpZoomer() { zoomWrapper = new JPanel(); try { zoomer = new JPanel(); - + JButton resizeButton = new JButton("Resize"); + resizeButton.setEnabled(true); JLabel zoomLabel = new JLabel("100%"); zoomLabel.setFont(MaterialFonts.getRegularFont(16f)); - + zoomer.add(resizeButton); + resizeButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // System.out.println("The resize bottom be click"); + reset(); + } + }); JSlider zoomSlider = new JSlider(25, 400, 100); JButton plus = new JButton(new ImageIcon(ImageIO.read( @@ -143,4 +154,19 @@ public void updateError(String message) { public void resetStatus() { status.setText(""); } + + public void reset() + { + // System.out.println("get into the reset"); + Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); + Board board1 = GameBoardFacade.getInstance().getBoard(); + board1.setModifiable(true); + Dimension bi = new Dimension(1200,900); + this.getScrollView().zoomFit(); +// System.out.println("get into the reset"+UIhight+" "+this.getHeight()+" "+this.getWidth()); +// this.getScrollView().zoomTo(UIhight); + // System.out.println("Finish into the reset"); + + + } } diff --git a/src/main/java/edu/rpi/legup/ui/LegupUI.java b/src/main/java/edu/rpi/legup/ui/LegupUI.java index 8bca7f663..6a32e0001 100644 --- a/src/main/java/edu/rpi/legup/ui/LegupUI.java +++ b/src/main/java/edu/rpi/legup/ui/LegupUI.java @@ -28,13 +28,13 @@ public class LegupUI extends JFrame implements WindowListener { protected LegupPanel[] panels; /** - * Identifies operating system + * Identifies operating system */ public static String getOS() { - String os = System.getProperty("os.name").toLowerCase(); - if(os.contains("mac")) os = "mac"; - else os = "win"; - return os; + String os = System.getProperty("os.name").toLowerCase(); + if(os.contains("mac")) os = "mac"; + else os = "win"; + return os; } /** @@ -185,4 +185,4 @@ public DynamicView getDynamicBoardView() { public TreePanel getTreePanel() { return getProofEditor().getTreePanel(); } -} +} \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java index ffeaa994b..ef7449019 100644 --- a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java @@ -380,6 +380,7 @@ protected void setupContent() { mainPanel.setPreferredSize(new Dimension(600, 600)); boardPanel.add(mainPanel); + boardPanel.setVisible(true); boardBorder = BorderFactory.createTitledBorder("Board"); boardBorder.setTitleJustification(TitledBorder.CENTER); diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleFrame.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleFrame.java index cfe3ba3b4..dc5848d8f 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleFrame.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleFrame.java @@ -4,6 +4,7 @@ import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.rules.Rule; +import edu.rpi.legup.ui.lookandfeel.components.MaterialTabbedPaneUI; import java.awt.BorderLayout; import java.awt.Dimension; @@ -34,9 +35,18 @@ public class RuleFrame extends JPanel { private RuleController controller; public RuleFrame(RuleController controller) { + + MaterialTabbedPaneUI tabOverride = new MaterialTabbedPaneUI(){ + //this prevents the tabs from moving around when you select them + @Override protected boolean shouldRotateTabRuns(int i){ + return false; + } + }; + this.controller = controller; this.tabbedPane = new JTabbedPane(); + this.tabbedPane.setUI(tabOverride); this.status = new JLabel(); this.buttonGroup = new ButtonGroup(); diff --git a/src/main/resources/edu/rpi/legup/legup/config b/src/main/resources/edu/rpi/legup/legup/config index 5e685d554..cfa1ebeac 100644 --- a/src/main/resources/edu/rpi/legup/legup/config +++ b/src/main/resources/edu/rpi/legup/legup/config @@ -1,18 +1,18 @@ - - @@ -24,14 +24,14 @@ qualifiedClassName="edu.rpi.legup.puzzle.nurikabe.Nurikabe" fileType=".xml" fileCreationDisabled="false"/> - - diff --git a/src/main/resources/edu/rpi/legup/puzzlefiles/battleship/BattleShipTest b/src/main/resources/edu/rpi/legup/puzzlefiles/battleship/BattleShipTest index 749506a1b..77d3e43c6 100644 --- a/src/main/resources/edu/rpi/legup/puzzlefiles/battleship/BattleShipTest +++ b/src/main/resources/edu/rpi/legup/puzzlefiles/battleship/BattleShipTest @@ -1,5 +1,5 @@ - - + + @@ -33,5 +33,5 @@ - - \ No newline at end of file + + \ No newline at end of file diff --git a/src/test/java/puzzles/battleship/rules/AdjacentShipsContradictionRuleTest.java b/src/test/java/puzzles/battleship/rules/AdjacentShipsContradictionRuleTest.java index 20e4e8966..7239cf7ba 100644 --- a/src/test/java/puzzles/battleship/rules/AdjacentShipsContradictionRuleTest.java +++ b/src/test/java/puzzles/battleship/rules/AdjacentShipsContradictionRuleTest.java @@ -33,22 +33,48 @@ public static void setUp() @Test public void OrthogonalAdjacentTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/battleship/rules/" + - "AdjacentShipsContradictionRule/OrthogonalAdjacentBoards", + TestUtilities.importTestBoard("puzzles/battleship/rules" + + "/AdjacentShipsContradictionRule/OrthogonalAdjacentBoards", battleship); TreeNode rootNode = battleship.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); BattleshipBoard board = (BattleshipBoard)transition.getBoard(); - BattleshipCell cell1 = board.getCell(1, 1); - BattleshipCell cell2 = board.getCell(1, 2); - BattleshipCell cell3 = board.getCell(2, 1); - BattleshipCell cell4 = board.getCell(2, 2); + + Assert.assertNotNull(RULE.checkContradiction( + board)); + } + + @Test + public void InvalidOrthogonalAdjacentTest() throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/battleship/rules" + + "/AdjacentShipsContradictionRule" + + "/InvalidOrthogonalAdjacentBoards", battleship); + TreeNode rootNode = battleship.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + BattleshipBoard board = (BattleshipBoard)transition.getBoard(); Assert.assertNull(RULE.checkContradiction( - (BattleshipBoard)transition.getBoard())); + board)); + } + @Test + public void DiagonalAdjacentTest() throws InvalidFileFormatException + { + TestUtilities.importTestBoard("puzzles/battleship/rules" + + "/AdjacentShipsContradictionRule" + + "/DiagonalAdjacentBoards", battleship); + TreeNode rootNode = battleship.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + BattleshipBoard board = (BattleshipBoard)transition.getBoard(); + Assert.assertNull(RULE.checkContradiction( + board)); } } diff --git a/src/test/resources/puzzles/battleship/rules/AdjacentShipsContradictionRule/DiagonalAdjacentBoards b/src/test/resources/puzzles/battleship/rules/AdjacentShipsContradictionRule/DiagonalAdjacentBoards new file mode 100644 index 000000000..ce6e9d011 --- /dev/null +++ b/src/test/resources/puzzles/battleship/rules/AdjacentShipsContradictionRule/DiagonalAdjacentBoards @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/battleship/rules/AdjacentShipsContradictionRule/InvalidOrthogonalAdjacentBoards b/src/test/resources/puzzles/battleship/rules/AdjacentShipsContradictionRule/InvalidOrthogonalAdjacentBoards new file mode 100644 index 000000000..bb8ce02ac --- /dev/null +++ b/src/test/resources/puzzles/battleship/rules/AdjacentShipsContradictionRule/InvalidOrthogonalAdjacentBoards @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/battleship/rules/AdjacentShipsContradictionRule/OrthogonalAdjacentBoards b/src/test/resources/puzzles/battleship/rules/AdjacentShipsContradictionRule/OrthogonalAdjacentBoards new file mode 100644 index 000000000..81f42cffc --- /dev/null +++ b/src/test/resources/puzzles/battleship/rules/AdjacentShipsContradictionRule/OrthogonalAdjacentBoards @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file