Skip to content

Commit

Permalink
Added "More Bombs Than Flag" Case Rule
Browse files Browse the repository at this point in the history
  • Loading branch information
vockek committed Mar 29, 2024
1 parent 62b3c71 commit 14516ab
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
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();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 14516ab

Please sign in to comment.