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

Surround completed region newest #673

Merged
merged 6 commits into from
Nov 3, 2023
Merged
Changes from all commits
Commits
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
Expand Up @@ -3,12 +3,20 @@
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.rules.ContradictionRule;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities;
import edu.rpi.legup.utility.DisjointSets;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
Corppet marked this conversation as resolved.
Show resolved Hide resolved
import java.awt.*;

public class SurroundRegionDirectRule extends DirectRule {

Expand All @@ -29,7 +37,6 @@ public SurroundRegionDirectRule() {
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
ContradictionRule contraRule = new TooManySpacesContradictionRule();

NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard();
NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard();
Expand All @@ -44,12 +51,35 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement);
modCell.setData(NurikabeType.WHITE.toValue());

if (contraRule.checkContradiction(modified) == null) {
return null;
}
else {
return "Does not follow from this rule at this index";
if(cell.getType() == NurikabeType.BLACK) {
DisjointSets<NurikabeCell> regions = NurikabeUtilities.getNurikabeRegions(destBoardState);
Set<NurikabeCell> adj = new HashSet<>(); //set to hold adjacent cells
Point loc = cell.getLocation(); //position of placed cell
List<Point> directions = Arrays.asList(new Point(-1, 0), new Point(1, 0), new Point(0, -1), new Point(0, 1));
for(Point direction : directions) {
NurikabeCell curr = destBoardState.getCell(loc.x + direction.x, loc.y + direction.y);
if(curr != null) {
if(curr.getType() == NurikabeType.WHITE || curr.getType() == NurikabeType.NUMBER) {
adj.add(curr); //adds cells to adj only if they are white or number blocks
}
}
}
List<NurikabeCell> numberedCells = new ArrayList<>(); //number value of number cells
for (NurikabeCell c : adj) { //loops through adjacent cells
Set<NurikabeCell> disRow = regions.getSet(c); //set of white spaces
for (NurikabeCell d : disRow) { //loops through white spaces
if (d.getType() == NurikabeType.NUMBER) { //if the white space is a number
numberedCells.add(d); //add that number to numberedCells
}
}
}
for (NurikabeCell number : numberedCells) { //loops through numberedCells
if (regions.getSet(number).size() == number.getData()) { //if that cells white area is the exact
return null; //size of the number of one of the number cells within that set
}
}
}
return "Does not follow from this rule at this index";
}

/**
Expand Down
Loading