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 420cc6204..17168ac98 100644 --- a/src/main/java/edu/rpi/legup/model/tree/TreeElement.java +++ b/src/main/java/edu/rpi/legup/model/tree/TreeElement.java @@ -24,7 +24,7 @@ public TreeElement(TreeElementType type) { public abstract boolean isContradictoryBranch(); /** - * Recursively determines if the sub tree rooted at this tree puzzleElement is valid by checking + * Recursively determines if the sub-tree rooted at this tree puzzleElement is valid by checking * whether this tree puzzleElement and all descendants of this tree puzzleElement is justified * and justified correctly * 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 154f41fd1..4807ef330 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleShipBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleShipBoard.java @@ -2,17 +2,26 @@ import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; +import org.jetbrains.annotations.NotNull; +import java.awt.*; import java.util.ArrayList; import java.util.List; public class BattleShipBoard extends GridBoard { + /** + * The column of clues on the east side of the board. + */ private List east; + + /** + * The column of clues on the south side of the board. + */ private List south; /** - * BattleShipBoard Constructor creates a new battleship board from the specified width and height + * Constructor for creating a rectangular battleship board. * * @param width width of the board * @param height height of the board @@ -32,7 +41,7 @@ public BattleShipBoard(int width, int height) { } /** - * BattleShipBoard Constructor creates a new battleship board which is square from the specified size + * Constructor for creating a square-sized battleship board. * * @param size size of the board */ @@ -43,7 +52,8 @@ public BattleShipBoard(int size) { /** * Gets the east {@link BattleShipClue} * - * @return east battle ship clues + * @return List of BattleShipClue objects on the east + * side of the board */ public List getEast() { return east; @@ -65,7 +75,8 @@ public BattleShipCell getCell(int x, int y) { @Override public BattleShipBoard copy() { - BattleShipBoard copy = new BattleShipBoard(dimension.width, dimension.height); + BattleShipBoard copy = new BattleShipBoard(dimension.width, + dimension.height); for (int x = 0; x < this.dimension.width; x++) { for (int y = 0; y < this.dimension.height; y++) { copy.setCell(x, y, getCell(x, y).copy()); @@ -78,4 +89,74 @@ public BattleShipBoard copy() { copy.south = this.south; return 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 } + */ + public List getAdjacent(@NotNull BattleShipCell cell) { + List adj = new ArrayList<>(); + Point loc = cell.getLocation(); + BattleShipCell up = getCell(loc.x, loc.y - 1); + BattleShipCell right = getCell(loc.x + 1, loc.y); + BattleShipCell down = getCell(loc.x, loc.y + 1); + BattleShipCell left = getCell(loc.x - 1, loc.y); + adj.add(up); + adj.add(right); + adj.add(down); + adj.add(left); + return adj; + } + + /** + * 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 } + */ + public List getAdjDiagonals(@NotNull BattleShipCell cell) { + List dia = new ArrayList<>(); + Point loc = cell.getLocation(); + BattleShipCell upRight = getCell(loc.x + 1, loc.y - 1); + BattleShipCell downRight = getCell(loc.x + 1, loc.y + 1); + BattleShipCell downLeft = getCell(loc.x - 1, loc.y + 1); + BattleShipCell upLeft = getCell(loc.x - 1, loc.y - 1); + dia.add(upRight); + dia.add(downRight); + dia.add(downLeft); + dia.add(upLeft); + return dia; + } + + /** + * Get a list of cells in a row. + * + * @param y The y-coordinate of the row. + * @return List of cells in the row in increasing x-coordinate order. + */ + public List getRow(int y) { + List row = new ArrayList<>(); + for (int x = 0; x < dimension.width; x++) { + row.add(getCell(x, y)); + } + return row; + } + + /** + * Get a list of cells in a column. + * + * @param x The x-coordinate of the column. + * @return List of cells in the column in increasing y-coordinate order. + */ + public List getColumn(int x) { + List column = new ArrayList<>(); + for (int y = 0; y < dimension.height; y++) { + column.add(getCell(x, y)); + } + return column; + } } \ 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 c336a4daf..4f3fd700e 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 @@ -3,26 +3,46 @@ 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.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"; + public AdjacentShipsContradictionRule() { super("BTSP-CONT-0001", "Adjacent Ships", - "", - "edu/rpi/legup/images/battleship/contradictions/AdjacentShips.png"); + "Cells next to the battleship must be water.", + "edu/rpi/legup/images/battleship/contradictions" + + "/AdjacentShips.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 + * {@link PuzzleElement} index using this rule * * @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 + * @param puzzleElement equivalent {@link PuzzleElement} + * @return null if the transition contains a + * contradiction at the specified {@link PuzzleElement}, + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { + BattleShipBoard bsBoard = (BattleShipBoard) board; + BattleShipCell cell = (BattleShipCell) bsBoard.getPuzzleElement(puzzleElement); + + // check orthogonally adjacent cells + List orthoAdjCells + = bsBoard.getAdjacent(cell); + + BattleShipCell up = orthoAdjCells.get(0); + return null; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java index 776f325b9..73bc9293b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java @@ -101,6 +101,14 @@ public void notifyDeletion(PuzzleElement puzzleElement) { } } + /** + * Get a list of all orthogonally adjacent cells. + * + * @param cell The cell to get adjacent cells from. + * @param type The cell types to get. + * @return List of adjacent cells in the form { up, right, down, left }. + * If an adjacent cell is null, it will not be added to the list. + */ public List getAdjacent(TreeTentCell cell, TreeTentType type) { List adj = new ArrayList<>(); Point loc = cell.getLocation();