diff --git a/src/main/java/edu/rpi/legup/puzzle/minesweeper/elements/BombTile.java b/src/main/java/edu/rpi/legup/puzzle/minesweeper/elements/BombTile.java deleted file mode 100644 index 78a5d320c..000000000 --- a/src/main/java/edu/rpi/legup/puzzle/minesweeper/elements/BombTile.java +++ /dev/null @@ -1,13 +0,0 @@ -package edu.rpi.legup.puzzle.minesweeper.elements; - -import edu.rpi.legup.model.elements.NonPlaceableElement; - -public class BombTile extends NonPlaceableElement { - public BombTile() { - super( - "MINE-UNPL-0001", - "Bomb", - "A bomb", - "edu/rpi/legup/images/minesweeper/tiles/Bomb.png"); - } -} diff --git a/src/main/java/edu/rpi/legup/puzzle/minesweeper/elements/FlagTile.java b/src/main/java/edu/rpi/legup/puzzle/minesweeper/elements/FlagTile.java deleted file mode 100644 index 0bbca81f9..000000000 --- a/src/main/java/edu/rpi/legup/puzzle/minesweeper/elements/FlagTile.java +++ /dev/null @@ -1,13 +0,0 @@ -package edu.rpi.legup.puzzle.minesweeper.elements; - -import edu.rpi.legup.model.elements.PlaceableElement; - -public class FlagTile extends PlaceableElement { - public FlagTile() { - super( - "MINE-PLAC-0001", - "Flag", - "The flag", - "edu/rpi/legup/images/nurikabe/tiles/BlackTile.png"); - } -} diff --git a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/BombOrFilledCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/BombOrFilledCaseRule.java deleted file mode 100644 index a1ef97928..000000000 --- a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/BombOrFilledCaseRule.java +++ /dev/null @@ -1,93 +0,0 @@ -package edu.rpi.legup.puzzle.minesweeper.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.CaseBoard; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.CaseRule; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.minesweeper.MinesweeperBoard; -import edu.rpi.legup.puzzle.minesweeper.MinesweeperCell; -import edu.rpi.legup.puzzle.minesweeper.MinesweeperTileData; -import java.util.ArrayList; -import java.util.List; - -public class BombOrFilledCaseRule extends CaseRule { - - public BombOrFilledCaseRule() { - super( - "MINE-CASE-0001", - "Bomb Or Filled", - "A cell can either be a bomb or filled.\n", - "edu/rpi/legup/images/minesweeper/cases/BombOrFilled.jpg"); - } - - @Override - public CaseBoard getCaseBoard(Board board) { - MinesweeperBoard minesweeperBoard = (MinesweeperBoard) board.copy(); - CaseBoard caseBoard = new CaseBoard(minesweeperBoard, this); - minesweeperBoard.setModifiable(false); - for (PuzzleElement data : minesweeperBoard.getPuzzleElements()) { - MinesweeperCell cell = (MinesweeperCell) data; - if (cell.getData().isUnset()) { - caseBoard.addPickableElement(data); - } - } - return caseBoard; - } - - @Override - public List getCases(Board board, PuzzleElement puzzleElement) { - ArrayList cases = new ArrayList<>(); - - Board case1 = board.copy(); - MinesweeperCell cell1 = (MinesweeperCell) case1.getPuzzleElement(puzzleElement); - cell1.setData(MinesweeperTileData.bomb()); - case1.addModifiedData(cell1); - cases.add(case1); - - Board case2 = board.copy(); - MinesweeperCell cell2 = (MinesweeperCell) case2.getPuzzleElement(puzzleElement); - cell2.setData(MinesweeperTileData.empty()); - case2.addModifiedData(cell2); - cases.add(case2); - return cases; - } - - @Override - public String checkRuleRaw(TreeTransition transition) { - List childTransitions = transition.getParents().get(0).getChildren(); - if (childTransitions.size() != 2) { - return super.getInvalidUseOfRuleMessage() + ": This case rule must have 2 children."; - } - - TreeTransition case1 = childTransitions.get(0); - TreeTransition case2 = childTransitions.get(1); - if (case1.getBoard().getModifiedData().size() != 1 - || case2.getBoard().getModifiedData().size() != 1) { - return super.getInvalidUseOfRuleMessage() - + ": This case rule must have 1 modified cell for each case."; - } - - MinesweeperCell mod1 = - (MinesweeperCell) case1.getBoard().getModifiedData().iterator().next(); - MinesweeperCell mod2 = - (MinesweeperCell) case2.getBoard().getModifiedData().iterator().next(); - if (!mod1.getLocation().equals(mod2.getLocation())) { - return super.getInvalidUseOfRuleMessage() - + ": This case rule must modify the same cell for each case."; - } - - if (!((mod1.getData().isBomb() && mod2.getData().isEmpty()) - || (mod2.getData().isBomb() && mod1.getData().isEmpty()))) { - return super.getInvalidUseOfRuleMessage() - + ": This case rule must an empty cell and a bomb cell."; - } - - return null; - } - - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } -} diff --git a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithBombsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithBombsDirectRule.java deleted file mode 100644 index e85008d23..000000000 --- a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithBombsDirectRule.java +++ /dev/null @@ -1,64 +0,0 @@ -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; - } - } -} diff --git a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/LessBombsThanFlagContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/LessBombsThanFlagContradictionRule.java deleted file mode 100644 index c9919343f..000000000 --- a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/LessBombsThanFlagContradictionRule.java +++ /dev/null @@ -1,50 +0,0 @@ -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.*; -import java.util.ArrayList; - -public class LessBombsThanFlagContradictionRule extends ContradictionRule { - private final String NO_CONTRADICTION_MESSAGE = - "Does not contain a contradiction at this index"; - private final String INVALID_USE_MESSAGE = "Contradiction must be a region"; - - public LessBombsThanFlagContradictionRule() { - super( - "MINE-CONT-0000", - "Less Bombs Than Flag", - "There can not be less then the number of Bombs around a flag then the specified number\n", - "edu/rpi/legup/images/nurikabe/contradictions/NoNumber.png"); - } - - @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 >= 9) { - return super.getNoContradictionMessage(); - } - int numEmpty = 0; - int numAdj = 0; - ArrayList adjCells = - MinesweeperUtilities.getAdjacentCells(minesweeperBoard, cell); - for (MinesweeperCell adjCell : adjCells) { - numAdj++; - if (adjCell.getTileType() == MinesweeperTileType.EMPTY && adjCell != cell) { - numEmpty++; - } - } - System.out.println(numEmpty); - System.out.println(numAdj); - System.out.println(cellNum); - if (numEmpty > (numAdj - cellNum)) { - return null; - } - - return super.getNoContradictionMessage(); - } -} diff --git a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/MoreBombsThanFlagContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/MoreBombsThanFlagContradictionRule.java deleted file mode 100644 index ecfdbad66..000000000 --- a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/MoreBombsThanFlagContradictionRule.java +++ /dev/null @@ -1,54 +0,0 @@ -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.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 adjCells = - MinesweeperUtilities.getAdjacentCells(minesweeperBoard, cell); - for (MinesweeperCell adjCell : adjCells) { - if (adjCell.getTileType() == MinesweeperTileType.BOMB) { - numBlack++; - } - } - if (numBlack > cellNum) { - return null; - } - - return super.getNoContradictionMessage(); - } -} diff --git a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/SatisfyFlagCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/SatisfyFlagCaseRule.java deleted file mode 100644 index a59369b7a..000000000 --- a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/SatisfyFlagCaseRule.java +++ /dev/null @@ -1,231 +0,0 @@ -package edu.rpi.legup.puzzle.minesweeper.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.CaseBoard; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.CaseRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.minesweeper.*; -import java.awt.*; -import java.util.*; -import java.util.List; - -public class SatisfyFlagCaseRule extends CaseRule { - public SatisfyFlagCaseRule() { - super( - "MINE-CASE-0002", - "Satisfy Flag", - "Create a different path for each valid way to mark bombs and filled cells around a flag", - "edu/rpi/legup/images/minesweeper/cases/Satisfy_Flag.png"); - } - - @Override - public CaseBoard getCaseBoard(Board board) { - MinesweeperBoard minesweeperBoard = (MinesweeperBoard) board.copy(); - CaseBoard caseBoard = new CaseBoard(minesweeperBoard, this); - minesweeperBoard.setModifiable(false); - for (PuzzleElement data : minesweeperBoard.getPuzzleElements()) { - MinesweeperCell cell = (MinesweeperCell) data; - if (cell.getTileNumber() > 0 - && cell.getTileNumber() <= 8 - && MinesweeperUtilities.hasEmptyAdjacent(minesweeperBoard, cell)) { - caseBoard.addPickableElement(data); - } - } - return caseBoard; - } - - @Override - public ArrayList getCases(Board board, PuzzleElement puzzleElement) { - ArrayList cases = new ArrayList(); - - // get value of cell - MinesweeperBoard minesweeperBoard = (MinesweeperBoard) board.copy(); - MinesweeperCell cell = (MinesweeperCell) minesweeperBoard.getPuzzleElement(puzzleElement); - int cellMaxBlack = cell.getTileNumber(); - if (cellMaxBlack <= 0 || cellMaxBlack > 8) { // cell is not valid cell - return null; - } - - // find number of black & unset squares - int cellNumBomb = 0; - int cellNumUnset = 0; - ArrayList unsetCells = new ArrayList(); - ArrayList adjCells = - MinesweeperUtilities.getAdjacentCells(minesweeperBoard, cell); - for (MinesweeperCell adjCell : adjCells) { - if (adjCell.getTileType() == MinesweeperTileType.BOMB) { - cellNumBomb++; - } - if (adjCell.getTileType() == MinesweeperTileType.UNSET) { - cellNumUnset++; - unsetCells.add(adjCell); - } - } - // no cases if no empty or if too many black already - if (cellNumBomb >= cellMaxBlack || cellNumUnset == 0) { - return cases; - } - - // generate all cases as boolean expressions - ArrayList combinations; - combinations = - MinesweeperUtilities.getCombinations(cellMaxBlack - cellNumBomb, cellNumUnset); - - for (int i = 0; i < combinations.size(); i++) { - Board case_ = board.copy(); - for (int j = 0; j < combinations.get(i).length; j++) { - cell = (MinesweeperCell) case_.getPuzzleElement(unsetCells.get(j)); - if (combinations.get(i)[j]) { - cell.setCellType(MinesweeperTileData.bomb()); - } else { - cell.setCellType(MinesweeperTileData.empty()); - } - case_.addModifiedData(cell); - } - cases.add(case_); - } - - return cases; - } - - @Override - public String checkRuleRaw(TreeTransition transition) { - TreeNode parent = transition.getParents().get(0); - List childTransitions = parent.getChildren(); - - /* - * In order for the transition to be valid, it can only be applied to - * one cell, thus: - * * there must be modified cells - * * all modified cells must share at least one common adjacent - * cell - * * all modified cells must fit within a 3X3 square - * * the center of one of the possible squares must be a cell - * with a number - * * that cells possible combinations must match the transitions - * If all the above is verified, then the transition is valid - */ - - /* ensure there are modified cells */ - Set modCells = transition.getBoard().getModifiedData(); - if (modCells.size() <= 0) { - return super.getInvalidUseOfRuleMessage(); - } - - /* ensure modified cells occur within a 3X3 square */ - int minVertLoc = Integer.MAX_VALUE, maxVertLoc = Integer.MIN_VALUE; - int minHorzLoc = Integer.MAX_VALUE, maxHorzLoc = Integer.MIN_VALUE; - for (PuzzleElement modCell : modCells) { - Point loc = ((MinesweeperCell) modCell).getLocation(); - if (loc.x < minHorzLoc) { - minHorzLoc = loc.x; - } - if (loc.x > maxHorzLoc) { - maxHorzLoc = loc.x; - } - if (loc.y < minVertLoc) { - minVertLoc = loc.y; - } - if (loc.y > maxVertLoc) { - maxVertLoc = loc.y; - } - } - if (maxVertLoc - minVertLoc > 3 || maxHorzLoc - minHorzLoc > 3) { - return super.getInvalidUseOfRuleMessage(); - } - - /* get the center of all possible 3X3 squares, - * and collect all that have numbers */ - MinesweeperBoard board = (MinesweeperBoard) transition.getParents().get(0).getBoard(); - ArrayList possibleCenters = new ArrayList(); - for (PuzzleElement modCell : modCells) { - ArrayList adjacentCells = - MinesweeperUtilities.getAdjacentCells(board, (MinesweeperCell) modCell); - for (MinesweeperCell cell : adjacentCells) { - possibleCenters.add(cell); - } - } - - // removing all elements without a valid number - possibleCenters.removeIf(x -> x.getTileNumber() <= 0 || x.getTileNumber() >= 9); - if (possibleCenters.isEmpty()) { - return super.getInvalidUseOfRuleMessage(); - } - - /* Now go through the remaining centers, and check if their combinations - * match the transitions */ - for (MinesweeperCell possibleCenter : possibleCenters) { - int numBlack = 0; - int numEmpty = 0; - int maxBlack = possibleCenter.getTileNumber(); - for (MinesweeperCell adjCell : - MinesweeperUtilities.getAdjacentCells(board, possibleCenter)) { - if (adjCell.getTileType() == MinesweeperTileType.BOMB) { - numBlack++; - } - if (adjCell.getTileType() == MinesweeperTileType.UNSET) { - numEmpty++; - } - } - if (numEmpty <= 0 || numBlack > maxBlack) { - // this cell has no cases (no empty) or is already broken (too many black) - continue; - } - - ArrayList combinations = - MinesweeperUtilities.getCombinations(maxBlack - numBlack, numEmpty); - if (combinations.size() != childTransitions.size()) { - // not this center because combinations do not match transitions - continue; - } - boolean quitEarly = false; - for (TreeTransition trans : childTransitions) { - /* convert the transition board into boolean format, so that it - * can be compared to the combinations */ - MinesweeperBoard transBoard = (MinesweeperBoard) trans.getBoard(); - ArrayList transModCells = new ArrayList(); - for (PuzzleElement modCell : modCells) { - transModCells.add((MinesweeperCell) transBoard.getPuzzleElement(modCell)); - } - - boolean[] translatedModCells = new boolean[transModCells.size()]; - for (int i = 0; i < transModCells.size(); i++) { - if (transModCells.get(i).getTileType() == MinesweeperTileType.BOMB) { - translatedModCells[i] = true; - } else { - translatedModCells[i] = false; - } - } - - // try to find the above state in the combinations, remove if found - boolean removed = false; - for (boolean[] combination : combinations) { - if (Arrays.equals(combination, translatedModCells)) { - combinations.remove(combination); - removed = true; - break; - } - } - // if combination not found, no need to check further, just quit - if (!removed) { - quitEarly = true; - break; - } - } - - /* we found a center that is valid */ - if (combinations.isEmpty() && !quitEarly) { - return null; - } - } - - return super.getInvalidUseOfRuleMessage(); - } - - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } -}