Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaDoc changes and Some Getters For BattleShipBoard #160

Merged
merged 1 commit into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/edu/rpi/legup/model/tree/TreeElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
89 changes: 85 additions & 4 deletions src/main/java/edu/rpi/legup/puzzle/battleship/BattleShipBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<BattleShipClue> east;

/**
* The column of clues on the south side of the board.
*/
private List<BattleShipClue> 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
Expand All @@ -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
*/
Expand All @@ -43,7 +52,8 @@ public BattleShipBoard(int size) {
/**
* Gets the east {@link BattleShipClue}
*
* @return east battle ship clues
* @return List of <code>BattleShipClue</code> objects on the east
* side of the board
*/
public List<BattleShipClue> getEast() {
return east;
Expand All @@ -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());
Expand All @@ -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:
* <code>{ up, right, down, left }</code>
*/
public List<BattleShipCell> getAdjacent(@NotNull BattleShipCell cell) {
List<BattleShipCell> 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:
* <code>{ upRight, downRight, downLeft, upLeft }</code>
*/
public List<BattleShipCell> getAdjDiagonals(@NotNull BattleShipCell cell) {
List<BattleShipCell> 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<BattleShipCell> getRow(int y) {
List<BattleShipCell> 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<BattleShipCell> getColumn(int x) {
List<BattleShipCell> column = new ArrayList<>();
for (int y = 0; y < dimension.height; y++) {
column.add(getCell(x, y));
}
return column;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>null</code> 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<BattleShipCell> orthoAdjCells
= bsBoard.getAdjacent(cell);

BattleShipCell up = orthoAdjCells.get(0);

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<TreeTentCell> getAdjacent(TreeTentCell cell, TreeTentType type) {
List<TreeTentCell> adj = new ArrayList<>();
Point loc = cell.getLocation();
Expand Down