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

Fixes for TreeTent rules not dependent on links #171

Merged
merged 9 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix 3 Rules
Fixed EmptyField, LastCampingSpot, and TouchingTents rules
  • Loading branch information
Hiimadd committed Jun 10, 2022
commit b1c8b3f2fea8a152de492d0bebe0d29fdc1959eb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 37,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
TreeTentCell initCell = (TreeTentCell) initialBoard.getPuzzleElement(puzzleElement);
TreeTentBoard finalBoard = (TreeTentBoard) transition.getBoard();
TreeTentCell finalCell = (TreeTentCell) finalBoard.getPuzzleElement(puzzleElement);
if (finalCell.getType() == TreeTentType.GRASS && initCell.getType() == TreeTentType.UNKNOWN) {
return null;
if (!(finalCell.getType() == TreeTentType.GRASS && initCell.getType() == TreeTentType.UNKNOWN)) {
return super.getInvalidUseOfRuleMessage() ": This cell must be grass";
}

if (isForced(finalBoard, finalCell)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 43,46 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
return super.getInvalidUseOfRuleMessage() ": This cell must be a tent.";
}

if (isForced(initialBoard, initCell)) {
if (isForced(finalBoard, finalCell)) {
return null;
} else {
return super.getInvalidUseOfRuleMessage() ": This cell is not forced to be tent.";
}
}

// private boolean isForced(TreeTentBoard board, TreeTentCell cell) {
// List<TreeTentCell> adjTents = board.getAdjacent(cell, TreeTentType.TREE);
// for (TreeTentCell c : adjTents) {
// Point loc = c.getLocation();
// for (TreeTentLine line : board.getLines()) {
// if (line.getC1().getLocation().equals(loc) || line.getC2().getLocation().equals(loc)) {
// return false;
// }
// }
// }
// return false;
// }

private boolean isForced(TreeTentBoard board, TreeTentCell cell) {
List<TreeTentCell> adjTents = board.getAdjacent(cell, TreeTentType.TREE);
for (TreeTentCell c : adjTents) {
Point loc = c.getLocation();
for (TreeTentLine line : board.getLines()) {
if (line.getC1().getLocation().equals(loc) || line.getC2().getLocation().equals(loc)) {
return false;
List<TreeTentCell> adjTrees = board.getAdjacent(cell, TreeTentType.TREE);
for (TreeTentCell c : adjTrees) {
List<TreeTentCell> unkAroundTree = board.getAdjacent(c, TreeTentType.UNKNOWN);
List<TreeTentCell> tntAroundTree = board.getAdjacent(c, TreeTentType.TENT);
if(unkAroundTree.size() == 0)
{
if(tntAroundTree.size() == 1)
{
return true;
}
else
{
for(TreeTentCell t : tntAroundTree)
{
if(t == cell) {continue;}
List<TreeTentCell> treesAroundTents = board.getAdjacent(t, TreeTentType.TREE);
if(treesAroundTents.size() == 1) {return false;}
}
return true;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 27,10 @@ public TouchingTentsContradictionRule() {
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
TreeTentBoard treeTentBoard = (TreeTentBoard) board;
TreeTentCell cell = (TreeTentCell) puzzleElement;
if (cell.getType() != TreeTentType.TREE) {
if (cell.getType() != TreeTentType.TENT) {
return super.getNoContradictionMessage();
}
int adjTree = treeTentBoard.getAdjacent(cell, TreeTentType.TREE).size();
int adjTree = treeTentBoard.getAdjacent(cell, TreeTentType.TENT).size();
if (adjTree > 0) {
return null;
} else {
Expand Down