-
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.
Added "More Bombs Than Flag" Case Rule
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/MoreBombsThanFlagContradictionRule.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,54 @@ | ||
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.ContradictionRule; | ||
import edu.rpi.legup.puzzle.minesweeper.MinesweeperBoard; | ||
import edu.rpi.legup.puzzle.minesweeper.MinesweeperCell; | ||
import edu.rpi.legup.puzzle.minesweeper.MinesweeperTileType; | ||
import edu.rpi.legup.puzzle.minesweeper.MinesweeperTileData; | ||
import edu.rpi.legup.puzzle.minesweeper.MinesweeperUtilities; | ||
import java.util.ArrayList; | ||
|
||
public class MoreBombsThanFlagContradictionRule extends ContradictionRule { | ||
|
||
public MoreBombsThanFlagContradictionRule() { | ||
super( | ||
"MINE-CONT-0001", | ||
"More Bombs Than Flag", | ||
"There can not be more Bombs around a flag than the specified number\n", | ||
"edu/rpi/legup/images/minesweeper/contradictions/Bomb_Surplus.jpg"); | ||
} | ||
|
||
/** | ||
* Checks whether the transition has a contradiction at the specific 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 | ||
*/ | ||
@Override | ||
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { | ||
MinesweeperBoard minesweeperBoard = (MinesweeperBoard) board; | ||
MinesweeperCell cell = (MinesweeperCell) minesweeperBoard.getPuzzleElement(puzzleElement); | ||
|
||
int cellNum = cell.getTileNumber(); | ||
if (cellNum < 0 || cellNum >= 10) { | ||
return super.getNoContradictionMessage(); | ||
} | ||
int numBlack = 0; | ||
ArrayList<MinesweeperCell> adjCells = MinesweeperUtilities.getAdjacentCells(minesweeperBoard, cell); | ||
for (MinesweeperCell adjCell : adjCells) { | ||
if (adjCell.getTileType() == MinesweeperTileType.BOMB) { | ||
numBlack++; | ||
} | ||
} | ||
if (numBlack > cellNum) { | ||
return null; | ||
} | ||
|
||
return super.getNoContradictionMessage(); | ||
} | ||
} |
Binary file added
BIN
+9.6 KB
...main/resources/edu/rpi/legup/images/minesweeper/contradictions/Bomb_Surplus.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.