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

Star battle new rule added (among other things) #844

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9e41523
Comment out nonfunctional test
summerhenson Apr 16, 2024
3abd581
Untested fix for StarBattleBoard copy function
summerhenson Jun 7, 2024
ebc20df
Start first Clashing Orbit contradiction rule test
summerhenson Jun 7, 2024
b192b79
Create 6x6 Star Battle Normal1 visualized (DO NOT OPEN AS A PUZZLE).png
offline171 Jun 11, 2024
6d8d050
Create 5x5 Star Battle Normal visualized (DO NOT OPEN AS A PUZZLE).png
offline171 Jun 11, 2024
9dff936
Fixed first clashing orbit test
summerhenson Jun 11, 2024
8d1f230
Finished Clashing Orbit contradiction rule test suite
summerhenson Jun 11, 2024
307d8ef
Start Too Few Stars contradiction rule test
summerhenson Jun 11, 2024
cd17e87
Create FalseContradiction
summerhenson Jun 14, 2024
c0fc026
Merge branch 'master' into star-battle
summerhenson Jun 14, 2024
9ef4cd4
Merge remote-tracking branch 'upstream/star-battle' into star-battle
offline171 Jun 14, 2024
7d02f11
Finish Too Few Stars contradiction rule tests
summerhenson Jun 14, 2024
d3a677e
Too Many Stars tests
offline171 Jun 14, 2024
732bc78
Too Many Stars test suite
offline171 Jun 18, 2024
1a1bf5e
Editing Blackout test
offline171 Jun 18, 2024
1203860
Basic Surround Star direct rule tests
summerhenson Jun 18, 2024
02bf6f5
Blackout Test Suite first test
offline171 Jun 18, 2024
109293b
Merge branch 'Bram-Hub:star-battle' into star-battle
summerhenson Jun 21, 2024
b222cdc
Finishing Blackout Test
offline171 Jun 21, 2024
cd42e83
Added new Surround Star direct rule test
summerhenson Jun 21, 2024
6772071
Finish with Stars
offline171 Jun 21, 2024
ac95969
Make a rule name more accurate
summerhenson Jun 21, 2024
4a1ab37
Merge pull request #828 from summerhenson/star-battle
offline171 Jun 21, 2024
d286dda
Merge branch 'Bram-Hub:star-battle' into star-battle
offline171 Jun 21, 2024
d30206d
new 2 star puzzle
offline171 Jun 25, 2024
dbbaca6
Update 10x10 Star Battle 2star Normal1.xml
offline171 Jun 28, 2024
2e6b526
Merge branch 'star-battle' of https://github.com/offline171/LEGUP int…
offline171 Jun 28, 2024
453fe30
Added Image for PushoutAdjacentDirectRule
offline171 Jul 12, 2024
7750b73
Name change
offline171 Jul 12, 2024
d2347f3
EmptyAdjacentDirectRule added
offline171 Jul 19, 2024
eac5fd5
Added tests (function not working)
offline171 Jul 19, 2024
9d95045
Fixed an issue where tests wouldn't run
offline171 Jul 23, 2024
f99a1d1
Debugging process rooted out issue
offline171 Jul 26, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Legup version="2.0.0">
<puzzle name="StarBattle">
<board size="10" puzzle_num="2">
<region>
<cells>
<cell value="0" x="0" y="0"/>
<cell value="0" x="1" y="0"/>
<cell value="0" x="0" y="1"/>
<cell value="0" x="1" y="1"/>
<cell value="0" x="0" y="2"/>
<cell value="0" x="0" y="3"/>
<cell value="0" x="0" y="4"/>
<cell value="0" x="0" y="5"/>
<cell value="0" x="0" y="6"/>
<cell value="0" x="0" y="7"/>
<cell value="0" x="0" y="8"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="2" y="0"/>
<cell value="0" x="2" y="1"/>
<cell value="0" x="1" y="2"/>
<cell value="0" x="2" y="2"/>
<cell value="0" x="1" y="3"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="3" y="0"/>
<cell value="0" x="3" y="1"/>
<cell value="0" x="3" y="2"/>
<cell value="0" x="2" y="3"/>
<cell value="0" x="3" y="3"/>
<cell value="0" x="3" y="4"/>
<cell value="0" x="3" y="5"/>
<cell value="0" x="2" y="6"/>
<cell value="0" x="3" y="6"/>
<cell value="0" x="2" y="7"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="4" y="0"/>
<cell value="0" x="5" y="0"/>
<cell value="0" x="6" y="0"/>
<cell value="0" x="4" y="1"/>
<cell value="0" x="5" y="1"/>
<cell value="0" x="6" y="1"/>
<cell value="0" x="4" y="2"/>
<cell value="0" x="5" y="2"/>
<cell value="0" x="6" y="2"/>
<cell value="0" x="4" y="3"/>
<cell value="0" x="5" y="3"/>
<cell value="0" x="6" y="3"/>
<cell value="0" x="6" y="4"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="7" y="0"/>
<cell value="0" x="7" y="1"/>
<cell value="0" x="7" y="2"/>
<cell value="0" x="7" y="3"/>
<cell value="0" x="7" y="4"/>
<cell value="0" x="7" y="5"/>
<cell value="0" x="7" y="6"/>
<cell value="0" x="8" y="6"/>
<cell value="0" x="7" y="7"/>
<cell value="0" x="7" y="8"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="8" y="0"/>
<cell value="0" x="9" y="0"/>
<cell value="0" x="8" y="1"/>
<cell value="0" x="9" y="1"/>
<cell value="0" x="8" y="2"/>
<cell value="0" x="9" y="2"/>
<cell value="0" x="8" y="3"/>
<cell value="0" x="9" y="3"/>
<cell value="0" x="8" y="4"/>
<cell value="0" x="9" y="4"/>
<cell value="0" x="8" y="5"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="1" y="4"/>
<cell value="0" x="2" y="4"/>
<cell value="0" x="1" y="5"/>
<cell value="0" x="2" y="5"/>
<cell value="0" x="1" y="6"/>
<cell value="0" x="1" y="7"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="4" y="4"/>
<cell value="0" x="5" y="4"/>
<cell value="0" x="4" y="5"/>
<cell value="0" x="5" y="5"/>
<cell value="0" x="6" y="5"/>
<cell value="0" x="4" y="6"/>
<cell value="0" x="5" y="6"/>
<cell value="0" x="6" y="6"/>
<cell value="0" x="3" y="7"/>
<cell value="0" x="4" y="7"/>
<cell value="0" x="5" y="7"/>
<cell value="0" x="6" y="7"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="9" y="5"/>
<cell value="0" x="9" y="6"/>
<cell value="0" x="8" y="7"/>
<cell value="0" x="9" y="7"/>
<cell value="0" x="8" y="8"/>
<cell value="0" x="9" y="8"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="1" y="8"/>
<cell value="0" x="2" y="8"/>
<cell value="0" x="3" y="8"/>
<cell value="0" x="4" y="8"/>
<cell value="0" x="5" y="8"/>
<cell value="0" x="6" y="8"/>
<cell value="0" x="0" y="9"/>
<cell value="0" x="1" y="9"/>
<cell value="0" x="2" y="9"/>
<cell value="0" x="3" y="9"/>
<cell value="0" x="4" y="9"/>
<cell value="0" x="5" y="9"/>
<cell value="0" x="6" y="9"/>
<cell value="0" x="7" y="9"/>
<cell value="0" x="8" y="9"/>
<cell value="0" x="9" y="9"/>
</cells>
</region>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/starbattle/StarBattleBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,25 @@ public int rowStars(int rowIndex) {

public StarBattleBoard copy() {
StarBattleBoard copy = new StarBattleBoard(size, puzzleNum);
for (int r = 0; r < this.regions.size(); ++r) {
StarBattleRegion regionCopy = this.regions.get(r).copy();
for (StarBattleCell cell: regionCopy.getCells()) {
copy.setCell(cell.getLocation().x, cell.getLocation().y, cell);
}
copy.setRegion(r, regionCopy);
}
/*
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());
}

if (x < this.regions.size()) {
copy.regions.add(this.getRegion(x).copy());
}

}
*/
for (PuzzleElement e : modifiedData) {
copy.getPuzzleElement(e).setModifiable(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package edu.rpi.legup.puzzle.starbattle.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.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;

public class EmptyAdjacentDirectRule extends DirectRule {

public EmptyAdjacentDirectRule() {
super(
"STBL-BASC-0010",
"Empty Adjacent",
"Tiles next to other tiles that need to contain a star to reach the puzzle number for their region/row/column need to be blacked out.",
"edu/rpi/legup/images/starbattle/rules/EmptyAdjacentDirectRule.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) {
StarBattleBoard board = (StarBattleBoard) transition.getBoard();
StarBattleBoard origBoard = (StarBattleBoard) transition.getParents().get(0).getBoard();
ContradictionRule contraRule = new TooFewStarsContradictionRule();

StarBattleCell cell = (StarBattleCell) board.getPuzzleElement(puzzleElement);

if (cell.getType() != StarBattleCellType.BLACK) {
return super.getInvalidUseOfRuleMessage()
+ ": Only black cells are allowed for this rule!";
}

int x = cell.getLocation().x;
int y = cell.getLocation().y;

StarBattleCell northWest = board.getCell(x - 1, y - 1);
StarBattleCell north = board.getCell(x, y - 1);
StarBattleCell northEast = board.getCell(x + 1, y - 1);
StarBattleCell west = board.getCell(x - 1, y);
StarBattleCell east = board.getCell(x + 1, y);
StarBattleCell southWest = board.getCell(x - 1, y + 1);
StarBattleCell south = board.getCell(x, y + 1);
StarBattleCell southEast = board.getCell(x + 1, y + 1);

StarBattleCell[] adjacent = {northWest, north, northEast, west, east, southWest, south, southEast};

StarBattleBoard modified = (StarBattleBoard) origBoard.copy();
modified.getPuzzleElement(puzzleElement).setData(StarBattleCellType.STAR.value);
for(int i = 0; i < 8; i++){ //sets each spot to a black square if not filled
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!";
}

/**
* 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
int rowCount = 0;
int columnCount = 0;
for (int i = 0; i < sbBoard.getSize(); ++i) {
if (sbBoard.getCell(row, i).getType() != StarBattleCellType.BLACK) {
if (sbBoard.getCell(i, row).getType() != StarBattleCellType.BLACK) {
++rowCount;
}
if (sbBoard.getCell(i, column).getType() != StarBattleCellType.BLACK) {
if (sbBoard.getCell(column, i).getType() != StarBattleCellType.BLACK) {
++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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Regions Within Rows: STBL-BASC-0006
Rows Within Columns: STBL-BASC-0007
Rows Within Regions: STBL-BASC-0008
Surround Star: STBL-BASC-0009
Empty Adjacent: STBL-BASC-0010

Contradiction Rules:
Too Many Stars: STBL-CONT-0001
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading