-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #813 from vockek/minesweeper
Added "Finish with Bombs" direct rule
- Loading branch information
Showing
5 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithBombsDirectRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package edu.rpi.legup.puzzle.minesweeper.rules; | ||
|
||
import edu.rpi.legup.model.gameboard.Board; | ||
import edu.rpi.legup.model.gameboard.PuzzleElement; | ||
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.minesweeper.*; | ||
|
||
public class FinishWithBombsDirectRule extends DirectRule { | ||
public FinishWithBombsDirectRule() { | ||
super( | ||
"MINE-BASC-0001", | ||
"Finish with Bombs", | ||
"The remaining unknowns around a flag must be bombs to satisfy the number", | ||
"edu/rpi/legup/images/minesweeper/direct/Fill_Bombs.jpg"); | ||
} | ||
|
||
@Override | ||
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { | ||
MinesweeperBoard board = (MinesweeperBoard) transition.getBoard(); | ||
MinesweeperBoard parentBoard = (MinesweeperBoard) transition.getParents().get(0).getBoard(); | ||
MinesweeperCell cell = (MinesweeperCell) board.getPuzzleElement(puzzleElement); | ||
MinesweeperCell parentCell = (MinesweeperCell) parentBoard.getPuzzleElement(puzzleElement); | ||
|
||
if (!(parentCell.getTileType() == MinesweeperTileType.UNSET | ||
&& cell.getTileType() == MinesweeperTileType.BOMB)) { | ||
return super.getInvalidUseOfRuleMessage() | ||
+ ": This cell must be black to be applicable with this rule."; | ||
} | ||
|
||
if (MinesweeperUtilities.isForcedBomb(parentBoard, cell)) { | ||
return null; | ||
} else { | ||
return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be black"; | ||
} | ||
} | ||
|
||
/** | ||
* 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) { | ||
MinesweeperBoard minesweeperBoard = (MinesweeperBoard) node.getBoard().copy(); | ||
for (PuzzleElement element : minesweeperBoard.getPuzzleElements()) { | ||
MinesweeperCell cell = (MinesweeperCell) element; | ||
if (cell.getTileType() == MinesweeperTileType.UNSET | ||
&& MinesweeperUtilities.isForcedBomb((MinesweeperBoard) node.getBoard(), cell)) { | ||
cell.setCellType(MinesweeperTileData.bomb()); | ||
minesweeperBoard.addModifiedData(cell); | ||
} | ||
} | ||
if (minesweeperBoard.getModifiedData().isEmpty()) { | ||
return null; | ||
} else { | ||
return minesweeperBoard; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+22.1 KB
src/main/resources/edu/rpi/legup/images/minesweeper/direct/Fill_Bombs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.