From 21088743a02849ac9ea1ac79bfbaac7f83029331 Mon Sep 17 00:00:00 2001 From: offline171 <146153141+offline171@users.noreply.github.com> Date: Tue, 30 Jul 2024 14:33:13 -0400 Subject: [PATCH 01/11] Fixed Empty Adjacent Test Fixed Empty Adjacent Test (one of those one line deletion bug fixes) and got rid of print statements and comments blocking useful lines of code --- .../starbattle/rules/EmptyAdjacentDirectRule.java | 6 ------ .../rules/TooFewStarsContradictionRule.java | 2 -- .../rules/EmptyAdjacentDirectRuleTest.java | 12 ++++-------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/EmptyAdjacentDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/EmptyAdjacentDirectRule.java index 17909e233..882f23302 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/EmptyAdjacentDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/EmptyAdjacentDirectRule.java @@ -6,8 +6,6 @@ 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.NurikabeCell; -import edu.rpi.legup.puzzle.nurikabe.NurikabeType; import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; import edu.rpi.legup.puzzle.starbattle.StarBattleCell; import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; @@ -64,18 +62,14 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem StarBattleCell temp = adjacent[i]; if (temp != null && temp.getType() == StarBattleCellType.UNKNOWN) { - temp.setData(StarBattleCellType.BLACK.value); int X = temp.getLocation().x; int Y = temp.getLocation().y; modified.getCell(X,Y).setData(StarBattleCellType.BLACK.value); - System.out.println("covering square " + X + " " + Y + " type " + modified.getCell(X,Y).getType() + " i = " + i + "\n"); if(contraRule.checkContradictionAt(modified, temp) == null){ - System.out.println("Good job!"); return null; //used correctly if even one space causes a toofewstars issue } } } - System.out.println("Wait why did this exit?\n"); return "Black cells must be placed adjacent to a tile(s) where a star is needed!"; } diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooFewStarsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooFewStarsContradictionRule.java index 358e5b9bd..b0d49c6d2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooFewStarsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooFewStarsContradictionRule.java @@ -45,9 +45,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { ++columnCount; } } - System.out.println("rowCount = " + rowCount + " columnCount = " + columnCount + " at " + column + "," + row + "\n"); if (rowCount < sbBoard.getPuzzleNumber() || columnCount < sbBoard.getPuzzleNumber()) { - System.out.println("Returning Null\n"); return null; } StarBattleRegion region = sbBoard.getRegion(cell); diff --git a/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java index c81c74657..d71499017 100644 --- a/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java @@ -81,33 +81,29 @@ public void EmptyAdjacentDirectRule_TwoLeft() throws InvalidFileFormatException StarBattleBoard board = (StarBattleBoard) transition.getBoard(); StarBattleCell cell1 = board.getCell(1,1); cell1.setData(StarBattleCellType.BLACK.value); - /* StarBattleCell cell2 = board.getCell(2,1); cell2.setData(StarBattleCellType.BLACK.value); StarBattleCell cell3 = board.getCell(1,3); cell3.setData(StarBattleCellType.BLACK.value); StarBattleCell cell4 = board.getCell(2,3); cell4.setData(StarBattleCellType.BLACK.value); - */ board.addModifiedData(cell1); - /* board.addModifiedData(cell2); board.addModifiedData(cell3); board.addModifiedData(cell4); - */ Assert.assertNull(RULE.checkRule(transition)); - System.out.println("General Case is done\n"); for (int i = 0; i < board.getHeight(); ++i) { for (int j = 0; j < board.getWidth(); ++j) { Point point = new Point(j,i); - if (point.equals(cell1.getLocation())) { + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); - } /* + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); - } */ + } } } } From e5d7ded07cb309b28cea9d1add5bcb53dc74982a Mon Sep 17 00:00:00 2001 From: offline171 <146153141+offline171@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:07:45 -0400 Subject: [PATCH 02/11] Adding border functionality Starter code for borders --- .../legup/puzzle/starbattle/StarBattleCell.java | 2 +- .../legup/puzzle/starbattle/StarBattleView.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCell.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCell.java index ddae8f882..9045ccfd9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCell.java @@ -6,7 +6,7 @@ import java.awt.event.MouseEvent; public class StarBattleCell extends GridCell { - private int groupIndex; + private int groupIndex; //This is the region the cell is in private int max; /** diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java index 550b5495d..d1a5d9f20 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java @@ -1,14 +1,19 @@ package edu.rpi.legup.puzzle.starbattle; import edu.rpi.legup.controller.BoardController; +import edu.rpi.legup.model.elements.Element; 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.io.IOException; +import java.util.ArrayList; import javax.imageio.ImageIO; public class StarBattleView extends GridBoardView { static Image STAR; + private ArrayList> horizontalBorders; //board.size * board.size+1 left-right up-down + private ArrayList> verticalBorders; //board.size+1 * board.size left-right up-down static { try { @@ -23,6 +28,8 @@ public class StarBattleView extends GridBoardView { public StarBattleView(StarBattleBoard board) { super(new BoardController(), new StarBattleController(), board.getDimension()); + this.horizontalBorders = new ArrayList<>(); + this.verticalBorders = new ArrayList<>(); for (PuzzleElement puzzleElement : board.getPuzzleElements()) { StarBattleCell cell = (StarBattleCell) puzzleElement; @@ -34,5 +41,15 @@ public StarBattleView(StarBattleBoard board) { new Point(loc.x * elementSize.width, loc.y * elementSize.height)); elementViews.add(elementView); } + + //initialize horizontal borders + for(int i = 0; i < board.getWidth(); i++){ + ArrayList temp = new ArrayList<>(); + for(int j = 0; j < board.getHeight() + 1; j++){ + if(j == 0 || j == board.getHeight()){ //set borders at the ends of the board + temp.add(Boolean.TRUE); + } + } + } } } From 1838eb7f176af527f414ccfd328a3e144c8c32e1 Mon Sep 17 00:00:00 2001 From: offline171 <146153141+offline171@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:15:16 -0400 Subject: [PATCH 03/11] Border locations Added primitive code to outline where borders would be placed --- .../puzzle/starbattle/StarBattleView.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java index d1a5d9f20..12ef30baf 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java @@ -42,14 +42,39 @@ public StarBattleView(StarBattleBoard board) { elementViews.add(elementView); } - //initialize horizontal borders + //initialize horizontal borders, the ones that are between two cells along the y-axis, and look like -- not | for(int i = 0; i < board.getWidth(); i++){ ArrayList temp = new ArrayList<>(); - for(int j = 0; j < board.getHeight() + 1; j++){ + for(int j = 0; j < board.getHeight() + 1; j++){ //+1 to account for sides of board if(j == 0 || j == board.getHeight()){ //set borders at the ends of the board temp.add(Boolean.TRUE); } + else if(board.getCell(i, j-1).getGroupIndex() != board.getCell(i, j).getGroupIndex()){ //general case + temp.add(Boolean.TRUE); //adds border when two adjacent cells aren't from the same region + } + else{ + temp.add(Boolean.FALSE); + } + } + horizontalBorders.add(temp); + } + //initialize vertical borders, the ones that are between two cells along the x-axis, and look like | not -- + //largely the same code as horizontal border adder but i and j are flipped and general case checks cells adjacent + //along i (x) instead of j (y) + for(int j = 0; j < board.getHeight(); j++){ //initialize j (y) first since we're checking the opposite axis + ArrayList temp = new ArrayList<>(); + for(int i = 0; i < board.getHeight() + 1; i++){ //+1 to account for sides of board + if(i == 0 || i == board.getWidth()){ //set borders at the ends of the board + temp.add(Boolean.TRUE); + } + else if(board.getCell(i-1, j).getGroupIndex() != board.getCell(i, j).getGroupIndex()){ //general case + temp.add(Boolean.TRUE); //adds border when two adjacent cells aren't from the same region + } + else{ + temp.add(Boolean.FALSE); + } } + verticalBorders.add(temp); } } } From e0156a5cf9713902a50bfd3cdd3385ab465df39f Mon Sep 17 00:00:00 2001 From: offline171 <146153141+offline171@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:02:32 -0400 Subject: [PATCH 04/11] Start on code to actually draw the borders commented out rough draft on how element view draws borders. Don't need an image for them likely, just use basic drawRect function, and make sure to distinguish if it's vertical or horizontal if necessary --- .../legup/puzzle/starbattle/StarBattleElementView.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java index 66d59d364..f55eb082b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java @@ -42,5 +42,14 @@ public void drawElement(Graphics2D graphics2D) { graphics2D.setColor(Color.BLACK); graphics2D.drawRect(location.x, location.y, size.width, size.height); } + //else if (type == StarBattleCellType.BORDER){ //would likely define border as a cell type so as to + //not have to rewrite this whole function + /* //maybe one type for vertical and another for horizontal + graphics2D.setStrike(new BasicStrike(1)); + graphics2D.setColor(Color.BLACK); + graphics2D.drawRect(location.x, location.y, size.width, size.height); + } + */ + } } } From 1f2e980972e01d3b99ca7a6264271d36eece64cb Mon Sep 17 00:00:00 2001 From: offline171 <146153141+offline171@users.noreply.github.com> Date: Fri, 20 Sep 2024 14:22:58 -0400 Subject: [PATCH 05/11] Made dedicated border classes Made dedicated border classes to help define them for drawing --- .../puzzle/starbattle/StarBattleBorder.java | 23 ++++++++++ .../starbattle/StarBattleBorderView.java | 46 +++++++++++++++++++ .../puzzle/starbattle/StarBattleCellType.java | 5 +- .../puzzle/starbattle/StarBattleView.java | 40 ++++++++++++++++ 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorder.java create mode 100644 src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorder.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorder.java new file mode 100644 index 000000000..9556e5727 --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorder.java @@ -0,0 +1,23 @@ +package edu.rpi.legup.puzzle.starbattle; + +import edu.rpi.legup.model.gameboard.PuzzleElement; + +public class StarBattleBorder extends PuzzleElement { + private StarBattleCellType type; + + public StarBattleBorder(StarBattleCellType border_type){ + super(); //just use the empty constructor since it doesn't hold a value + type = border_type; + } + + public StarBattleCellType getType(){ + return type; + } + + public StarBattleBorder copy(){ + StarBattleBorder copy = new StarBattleBorder(type); + copy.setIndex(index); + copy.setModifiable(isModifiable); + return copy; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java new file mode 100644 index 000000000..1a6e44a4f --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java @@ -0,0 +1,46 @@ +package edu.rpi.legup.puzzle.starbattle; + +import edu.rpi.legup.ui.boardview.ElementView; +import java.awt.*; +import java.awt.geom.Rectangle2D; + +public class StarBattleBorderView extends ElementView { + private static final Color Border_COLOR = Color.BLACK; + + public StarBattleBorderView(StarBattleBorder border) { + super(border); + } + + /** + * Gets the PuzzleElement associated with this view + * + * @return PuzzleElement associated with this view + */ + @Override + public StarBattleBorder getPuzzleElement() { + return (StarBattleBorder) super.getPuzzleElement(); + } + + @Override + public void draw(Graphics2D graphics2D) { + drawElement(graphics2D); + if (this.isShowCasePicker() && this.isCaseRulePickable()) { + drawCase(graphics2D); + if (this.isHover()) { + drawHover(graphics2D); + } + } + } + + @Override + public void drawElement(Graphics2D graphics2D) { + graphics2D.setColor(Border_COLOR); + + StarBattleBorder border= getPuzzleElement(); + + int xBorder = location.x + (size.width / 2); + int yBorder = location.y + (size.height / 2); + graphics2D.draw(new Rectangle2D.Double( + location.x + 1.5f, location.y + 1.5f, size.width - 3, size.height - 3)); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCellType.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCellType.java index e48e46fcb..66943698f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCellType.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleCellType.java @@ -4,7 +4,10 @@ public enum StarBattleCellType { STAR(-2), BLACK(-1), - UNKNOWN(0); + UNKNOWN(0), + HORIZ_BORDER(1), + VERT_BORDER(2); + public int value; diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java index 12ef30baf..3f36acd13 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java @@ -77,4 +77,44 @@ else if(board.getCell(i-1, j).getGroupIndex() != board.getCell(i, j).getGroupInd verticalBorders.add(temp); } } + @Override + public void drawBoard(Graphics2D graphics2D){ + super.drawBoard(graphics2D); + int x = 0; + int y = 0; + + for(ArrayList border: horizontalBorders){ + for(Boolean lines: border){ + if(lines){ + //draw a horizontal line + + StarBattleBorder Horiz = new StarBattleBorder(StarBattleCellType.HORIZ_BORDER); + StarBattleBorderView horizontalBorder = new StarBattleBorderView(Horiz); + + //offset by an amount that makes puts borders between two vertically adjacent borders + horizontalBorder.setLocation(new Point((x/ gridSize.width) * elementSize.width, (y/gridSize.height) * elementSize.height)); + + //still need to figure out how to translate over a location + } + y++;//keep track of y index as the program iterates + } + x++; //keep track of x index as the program iterates + } + + for(ArrayList border: horizontalBorders){ + for(Boolean lines: border){ + if(lines){ + //draw a vertical line according to the index + + StarBattleBorder Vert = new StarBattleBorder(StarBattleCellType.VERT_BORDER); + StarBattleBorderView verticalBorder = new StarBattleBorderView(Vert); + + //offset by an amount that makes puts borders between two horizontally adjacent borders + verticalBorder.setLocation(new Point((x/ gridSize.width) * elementSize.width, (y/gridSize.height) * elementSize.height)); + } + x++;//keep track of x index, and yes I'm pretty sure the x and y axes are swapped + } + y++; //keep track of y index + } + } } From 217f4e870863abc2cc80694ef08bdb4b4c9871fc Mon Sep 17 00:00:00 2001 From: offline171 <146153141+offline171@users.noreply.github.com> Date: Tue, 1 Oct 2024 03:11:07 -0400 Subject: [PATCH 06/11] Revamped border detection and drawing Changed how borders were counted and drawn to be more in line with skyscrapers --- .../starbattle/StarBattleBorderView.java | 14 ++- .../starbattle/StarBattleElementView.java | 2 +- .../puzzle/starbattle/StarBattleView.java | 117 ++++++++++-------- 3 files changed, 79 insertions(+), 54 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java index 1a6e44a4f..d08be639b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java @@ -6,9 +6,11 @@ public class StarBattleBorderView extends ElementView { private static final Color Border_COLOR = Color.BLACK; + private StarBattleCellType type; public StarBattleBorderView(StarBattleBorder border) { super(border); + type = border.getType(); } /** @@ -38,9 +40,15 @@ public void drawElement(Graphics2D graphics2D) { StarBattleBorder border= getPuzzleElement(); - int xBorder = location.x + (size.width / 2); - int yBorder = location.y + (size.height / 2); + int xSize = size.width; + int ySize = size.height; + if(type == StarBattleCellType.HORIZ_BORDER){ //minimize ySize / height + ySize = ySize / 8; + } + else if(type == StarBattleCellType.VERT_BORDER){ //minimize xSize / width + xSize = xSize / 8; + } graphics2D.draw(new Rectangle2D.Double( - location.x + 1.5f, location.y + 1.5f, size.width - 3, size.height - 3)); + location.x, location.y, xSize, ySize)); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java index f55eb082b..a7fe68c23 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java @@ -50,6 +50,6 @@ public void drawElement(Graphics2D graphics2D) { graphics2D.drawRect(location.x, location.y, size.width, size.height); } */ - } + } } diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java index 3f36acd13..8f9f718a1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java @@ -12,8 +12,8 @@ public class StarBattleView extends GridBoardView { static Image STAR; - private ArrayList> horizontalBorders; //board.size * board.size+1 left-right up-down - private ArrayList> verticalBorders; //board.size+1 * board.size left-right up-down + private ArrayList horizontalBorders; //board.size * board.size+1 left-right up-down + private ArrayList verticalBorders; //board.size+1 * board.size left-right up-down static { try { @@ -42,79 +42,96 @@ public StarBattleView(StarBattleBoard board) { elementViews.add(elementView); } + //Make borders by just making a list of border objects and saving their locations as they come + //then just draw all of them one at a time + //initialize horizontal borders, the ones that are between two cells along the y-axis, and look like -- not | for(int i = 0; i < board.getWidth(); i++){ - ArrayList temp = new ArrayList<>(); for(int j = 0; j < board.getHeight() + 1; j++){ //+1 to account for sides of board - if(j == 0 || j == board.getHeight()){ //set borders at the ends of the board - temp.add(Boolean.TRUE); + StarBattleBorderView temp = new StarBattleBorderView(new StarBattleBorder(StarBattleCellType.HORIZ_BORDER)); + temp.setSize(elementSize); + if(j == 0){ //set borders at the ends of the board + temp.setLocation(endCell(board.getCell(i,j), 8, elementSize)); + horizontalBorders.add(temp); } - else if(board.getCell(i, j-1).getGroupIndex() != board.getCell(i, j).getGroupIndex()){ //general case - temp.add(Boolean.TRUE); //adds border when two adjacent cells aren't from the same region + else if(j == board.getHeight()){ + temp.setLocation(endCell(board.getCell(i,j), 2, elementSize)); + horizontalBorders.add(temp); } - else{ - temp.add(Boolean.FALSE); + else if(board.getCell(i, j-1).getGroupIndex() != board.getCell(i, j).getGroupIndex()){ //general case + //adds border when two adjacent cells aren't from the same region + temp.setLocation(betweenCells(board.getCell(i, j-1), board.getCell(i,j))); + horizontalBorders.add(temp); } + //no else statement. If none of these ifs are met, then just don't add it to the list } - horizontalBorders.add(temp); } //initialize vertical borders, the ones that are between two cells along the x-axis, and look like | not -- //largely the same code as horizontal border adder but i and j are flipped and general case checks cells adjacent //along i (x) instead of j (y) for(int j = 0; j < board.getHeight(); j++){ //initialize j (y) first since we're checking the opposite axis - ArrayList temp = new ArrayList<>(); for(int i = 0; i < board.getHeight() + 1; i++){ //+1 to account for sides of board - if(i == 0 || i == board.getWidth()){ //set borders at the ends of the board - temp.add(Boolean.TRUE); + StarBattleBorderView temp = new StarBattleBorderView(new StarBattleBorder(StarBattleCellType.VERT_BORDER)); + temp.setSize(elementSize); + if(i == 0){ //set borders at the ends of the board + temp.setLocation(endCell(board.getCell(i,j), 4, elementSize)); + verticalBorders.add(temp); } - else if(board.getCell(i-1, j).getGroupIndex() != board.getCell(i, j).getGroupIndex()){ //general case - temp.add(Boolean.TRUE); //adds border when two adjacent cells aren't from the same region + else if(i == board.getHeight()){ + temp.setLocation(endCell(board.getCell(i,j), 6, elementSize)); + verticalBorders.add(temp); } - else{ - temp.add(Boolean.FALSE); + else if(board.getCell(i-1, j).getGroupIndex() != board.getCell(i, j).getGroupIndex()){ //general case + //adds border when two adjacent cells aren't from the same region + temp.setLocation(betweenCells(board.getCell(i-1, j), board.getCell(i,j))); + verticalBorders.add(temp); } } - verticalBorders.add(temp); } } - @Override - public void drawBoard(Graphics2D graphics2D){ - super.drawBoard(graphics2D); - int x = 0; - int y = 0; - for(ArrayList border: horizontalBorders){ - for(Boolean lines: border){ - if(lines){ - //draw a horizontal line + //Direction means which side of the cell in question should have a border on it + //Numpad rules. 2 is down, 4 is left, 6 is right, 8 is up (based on visuals not coordinates, since y is from up to down) + public Point endCell(StarBattleCell one, int direction, Dimension elementSize){ + Point temp = new Point( + one.getLocation().x, + one.getLocation().y + ); + if(direction == 2){ + temp.y += elementSize.height / 2; + } + if(direction == 4){ + temp.y -= elementSize.width / 2; + } + if(direction == 6){ + temp.y += elementSize.width / 2; + } + if(direction == 8){ + temp.y -= elementSize.height / 2; + } + return temp; + } - StarBattleBorder Horiz = new StarBattleBorder(StarBattleCellType.HORIZ_BORDER); - StarBattleBorderView horizontalBorder = new StarBattleBorderView(Horiz); + //finds average point location between two cells + public Point betweenCells(StarBattleCell one, StarBattleCell two){ + return new Point( + (one.getLocation().x + two.getLocation().x) / 2, + (one.getLocation().y + two.getLocation().y) / 2 + ); + } - //offset by an amount that makes puts borders between two vertically adjacent borders - horizontalBorder.setLocation(new Point((x/ gridSize.width) * elementSize.width, (y/gridSize.height) * elementSize.height)); + @Override + public void drawBoard(Graphics2D graphics2D){ + super.drawBoard(graphics2D); - //still need to figure out how to translate over a location - } - y++;//keep track of y index as the program iterates - } - x++; //keep track of x index as the program iterates + for(StarBattleBorderView border: horizontalBorders){ + //draw a horizontal line + border.draw(graphics2D); } - for(ArrayList border: horizontalBorders){ - for(Boolean lines: border){ - if(lines){ - //draw a vertical line according to the index - - StarBattleBorder Vert = new StarBattleBorder(StarBattleCellType.VERT_BORDER); - StarBattleBorderView verticalBorder = new StarBattleBorderView(Vert); - - //offset by an amount that makes puts borders between two horizontally adjacent borders - verticalBorder.setLocation(new Point((x/ gridSize.width) * elementSize.width, (y/gridSize.height) * elementSize.height)); - } - x++;//keep track of x index, and yes I'm pretty sure the x and y axes are swapped - } - y++; //keep track of y index + for(StarBattleBorderView border: verticalBorders){ + //draw a vertical line + border.draw(graphics2D); } } } From eb49c27a7b98901527e64524310b75f89fa6d6bc Mon Sep 17 00:00:00 2001 From: offline171 <146153141+offline171@users.noreply.github.com> Date: Wed, 16 Oct 2024 01:07:03 -0400 Subject: [PATCH 07/11] Borders added Borders added, slipped in-between cells equally, colored red so as to not be confused with the black empty squares --- .../starbattle/StarBattleBorderView.java | 10 ++-- .../starbattle/StarBattleElementView.java | 1 + .../puzzle/starbattle/StarBattleView.java | 52 +++++++++++-------- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java index d08be639b..066f06595 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBorderView.java @@ -36,19 +36,23 @@ public void draw(Graphics2D graphics2D) { @Override public void drawElement(Graphics2D graphics2D) { - graphics2D.setColor(Border_COLOR); + graphics2D.setColor(Color.BLACK); StarBattleBorder border= getPuzzleElement(); int xSize = size.width; int ySize = size.height; if(type == StarBattleCellType.HORIZ_BORDER){ //minimize ySize / height + graphics2D.setColor(Color.RED); + //dump this + //System.out.println("Horizontal -- Border, coords " + location.x + "," + location.y + "\n"); ySize = ySize / 8; } else if(type == StarBattleCellType.VERT_BORDER){ //minimize xSize / width + graphics2D.setColor(Color.RED); + //System.out.println("Vertical | Border, c0ords " + location.x + "," + location.y + "\n"); xSize = xSize / 8; } - graphics2D.draw(new Rectangle2D.Double( - location.x, location.y, xSize, ySize)); + graphics2D.fillRect(location.x, location.y, xSize, ySize); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java index a7fe68c23..9680f14ad 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleElementView.java @@ -18,6 +18,7 @@ public StarBattleCell getPuzzleElement() { public void drawElement(Graphics2D graphics2D) { StarBattleCell cell = (StarBattleCell) puzzleElement; StarBattleCellType type = cell.getType(); + //System.out.println("point for cell is " + location.x + "," + location.y + "\n"); if (type == StarBattleCellType.STAR) { graphics2D.setColor(Color.LIGHT_GRAY); graphics2D.fillRect(location.x, location.y, size.width, size.height); diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java index 8f9f718a1..c4575a7e0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleView.java @@ -51,16 +51,17 @@ public StarBattleView(StarBattleBoard board) { StarBattleBorderView temp = new StarBattleBorderView(new StarBattleBorder(StarBattleCellType.HORIZ_BORDER)); temp.setSize(elementSize); if(j == 0){ //set borders at the ends of the board - temp.setLocation(endCell(board.getCell(i,j), 8, elementSize)); + //set on top of cell + temp.setLocation(endCell(board.getCell(i,0), 8, elementSize)); horizontalBorders.add(temp); } else if(j == board.getHeight()){ - temp.setLocation(endCell(board.getCell(i,j), 2, elementSize)); + temp.setLocation(endCell(board.getCell(i,board.getHeight()-1), 2, elementSize)); horizontalBorders.add(temp); } else if(board.getCell(i, j-1).getGroupIndex() != board.getCell(i, j).getGroupIndex()){ //general case //adds border when two adjacent cells aren't from the same region - temp.setLocation(betweenCells(board.getCell(i, j-1), board.getCell(i,j))); + temp.setLocation(endCell(board.getCell(i,j), 8, elementSize)); horizontalBorders.add(temp); } //no else statement. If none of these ifs are met, then just don't add it to the list @@ -74,16 +75,16 @@ else if(board.getCell(i, j-1).getGroupIndex() != board.getCell(i, j).getGroupInd StarBattleBorderView temp = new StarBattleBorderView(new StarBattleBorder(StarBattleCellType.VERT_BORDER)); temp.setSize(elementSize); if(i == 0){ //set borders at the ends of the board - temp.setLocation(endCell(board.getCell(i,j), 4, elementSize)); + temp.setLocation(endCell(board.getCell(0,j), 4, elementSize)); verticalBorders.add(temp); } - else if(i == board.getHeight()){ - temp.setLocation(endCell(board.getCell(i,j), 6, elementSize)); + else if(i == board.getWidth()){ + temp.setLocation(endCell(board.getCell(board.getWidth() - 1,j), 6, elementSize)); verticalBorders.add(temp); } else if(board.getCell(i-1, j).getGroupIndex() != board.getCell(i, j).getGroupIndex()){ //general case //adds border when two adjacent cells aren't from the same region - temp.setLocation(betweenCells(board.getCell(i-1, j), board.getCell(i,j))); + temp.setLocation(endCell(board.getCell(i,j), 4, elementSize)); verticalBorders.add(temp); } } @@ -94,31 +95,36 @@ else if(board.getCell(i-1, j).getGroupIndex() != board.getCell(i, j).getGroupInd //Numpad rules. 2 is down, 4 is left, 6 is right, 8 is up (based on visuals not coordinates, since y is from up to down) public Point endCell(StarBattleCell one, int direction, Dimension elementSize){ Point temp = new Point( - one.getLocation().x, - one.getLocation().y - ); + one.getLocation().x * elementSize.width, + one.getLocation().y * elementSize.height + );//dump this + //System.out.println("point is " + temp.x + "," + temp.y + "\n"); if(direction == 2){ - temp.y += elementSize.height / 2; + temp.y += elementSize.height * 15/16; //multiply so it doesn't go off screen } if(direction == 4){ - temp.y -= elementSize.width / 2; + temp.x -= elementSize.width / 16; //divide so it doesn't go off screen } if(direction == 6){ - temp.y += elementSize.width / 2; - } - if(direction == 8){ - temp.y -= elementSize.height / 2; + temp.x += elementSize.width * 15/16; //multiply so it doesn't go off screen + }if(direction == 8){ + temp.y -= elementSize.height / 16; //multiply so it doesn't go off screen } + //System.out.println("point is now " + temp.x + "," + temp.y + "\n"); return temp; } - + /* shelved for redundancy //finds average point location between two cells - public Point betweenCells(StarBattleCell one, StarBattleCell two){ - return new Point( - (one.getLocation().x + two.getLocation().x) / 2, - (one.getLocation().y + two.getLocation().y) / 2 - ); - } + public Point betweenCells(StarBattleCell one, StarBattleCell two, Dimension elementSize){ + //dump this + System.out.println("point between is " + Math.max(one.getLocation().x,two.getLocation().x) + "," + Math.max(one.getLocation().y,two.getLocation().y) + "\n"); + if(one.getLocation().x < two.getLocation().x){ + return endCell(one, 6, elementSize); + } + else if(one.getLocation().y < two.getLocation().y){ + return endCell(one, 6, elementSize); + } + } */ @Override public void drawBoard(Graphics2D graphics2D){ From 115c1f4c620f6e773c7b0f2cc06998e1c937e31d Mon Sep 17 00:00:00 2001 From: offline171 <146153141+offline171@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:42:02 -0400 Subject: [PATCH 08/11] Update log4j2.properties Attempting to solve merge issue --- bin/main/edu/rpi/legup/log4j2.properties | 28 ++++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/bin/main/edu/rpi/legup/log4j2.properties b/bin/main/edu/rpi/legup/log4j2.properties index de1fa02ed..4f2556c2d 100644 --- a/bin/main/edu/rpi/legup/log4j2.properties +++ b/bin/main/edu/rpi/legup/log4j2.properties @@ -1,15 +1,15 @@ -# Logging level -# Root logger option -log4j.rootLogger=DEBUG, stdout, file -# Redirect log messages to console -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n -# Redirect log messages to a log file, support file rolling. -log4j.appender.file=org.apache.log4j.RollingFileAppender -log4j.appender.file.File=Legup.log -log4j.appender.file.MaxFileSize=5MB -log4j.appender.file.MaxBackupIndex=10 -log4j.appender.file.layout=org.apache.log4j.PatternLayout +# Logging level +# Root logger option +log4j.rootLogger=DEBUG, stdout, file +# Redirect log messages to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n +# Redirect log messages to a log file, support file rolling. +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=Legup.log +log4j.appender.file.MaxFileSize=5MB +log4j.appender.file.MaxBackupIndex=10 +log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file From f5e932bae1c833362a6e98dde789875a728152c8 Mon Sep 17 00:00:00 2001 From: offline171 <146153141+offline171@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:47:42 -0400 Subject: [PATCH 09/11] Update EmptyAdjacentDirectRule.java Undoing changes to fix merge conflict --- .../puzzle/starbattle/rules/EmptyAdjacentDirectRule.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/EmptyAdjacentDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/EmptyAdjacentDirectRule.java index 882f23302..17909e233 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/EmptyAdjacentDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/EmptyAdjacentDirectRule.java @@ -6,6 +6,8 @@ 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.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; import edu.rpi.legup.puzzle.starbattle.StarBattleCell; import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; @@ -62,14 +64,18 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem StarBattleCell temp = adjacent[i]; if (temp != null && temp.getType() == StarBattleCellType.UNKNOWN) { + temp.setData(StarBattleCellType.BLACK.value); int X = temp.getLocation().x; int Y = temp.getLocation().y; modified.getCell(X,Y).setData(StarBattleCellType.BLACK.value); + System.out.println("covering square " + X + " " + Y + " type " + modified.getCell(X,Y).getType() + " i = " + i + "\n"); if(contraRule.checkContradictionAt(modified, temp) == null){ + System.out.println("Good job!"); return null; //used correctly if even one space causes a toofewstars issue } } } + System.out.println("Wait why did this exit?\n"); return "Black cells must be placed adjacent to a tile(s) where a star is needed!"; } From eaccb9aa39fef2675445c2cdf41265668ba562f8 Mon Sep 17 00:00:00 2001 From: offline171 <146153141+offline171@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:50:52 -0400 Subject: [PATCH 10/11] Update EmptyAdjacentDirectRuleTest.java More undoing --- .../starbattle/rules/EmptyAdjacentDirectRuleTest.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java index d71499017..6495c864f 100644 --- a/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java @@ -81,29 +81,32 @@ public void EmptyAdjacentDirectRule_TwoLeft() throws InvalidFileFormatException StarBattleBoard board = (StarBattleBoard) transition.getBoard(); StarBattleCell cell1 = board.getCell(1,1); cell1.setData(StarBattleCellType.BLACK.value); + /* StarBattleCell cell2 = board.getCell(2,1); cell2.setData(StarBattleCellType.BLACK.value); StarBattleCell cell3 = board.getCell(1,3); cell3.setData(StarBattleCellType.BLACK.value); StarBattleCell cell4 = board.getCell(2,3); cell4.setData(StarBattleCellType.BLACK.value); + */ board.addModifiedData(cell1); + /* board.addModifiedData(cell2); board.addModifiedData(cell3); board.addModifiedData(cell4); + */ Assert.assertNull(RULE.checkRule(transition)); for (int i = 0; i < board.getHeight(); ++i) { for (int j = 0; j < board.getWidth(); ++j) { Point point = new Point(j,i); - if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || - point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { + if (point.equals(cell1.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); - } + } /* else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); - } + } */ } } } From 301dc3d7a19757d7d6c7a3e5b11494d8694fd0ad Mon Sep 17 00:00:00 2001 From: offline171 <146153141+offline171@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:51:33 -0400 Subject: [PATCH 11/11] Update EmptyAdjacentDirectRuleTest.java More --- .../puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java index 6495c864f..c81c74657 100644 --- a/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/EmptyAdjacentDirectRuleTest.java @@ -98,6 +98,7 @@ public void EmptyAdjacentDirectRule_TwoLeft() throws InvalidFileFormatException */ Assert.assertNull(RULE.checkRule(transition)); + System.out.println("General Case is done\n"); for (int i = 0; i < board.getHeight(); ++i) { for (int j = 0; j < board.getWidth(); ++j) { Point point = new Point(j,i);