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

Fixed Max and OneEdge generalized to use case rules #335

Merged
Merged
Show file tree
Hide file tree
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 @@ -61,9 +61,8 @@ public ArrayList<Board> getCasesFor(Board board, PuzzleElement puzzleElement, In
passed = passed && DupeRule.checkContradictionAt(newCase,newCell)!=null;
}
if(skyscrapersboard.getViewFlag()){
InsufficientVisibilityContradictionRule fewRule = new InsufficientVisibilityContradictionRule();
ExceedingVisibilityContradictionRule moreRule = new ExceedingVisibilityContradictionRule();
passed = passed && fewRule.checkContradictionAt(newCase,newCell)!=null && moreRule.checkContradictionAt(newCase,newCell)!=null;
PreemptiveTooFewContradictionRule ViewRule = new PreemptiveTooFewContradictionRule();
passed = passed && ViewRule.checkContradictionAt(newCase,newCell)!=null;
}
if(passed){cases.add(newCase);}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType;

import java.awt.Point;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
Expand All @@ -18,7 +19,7 @@ public class FixedMaxBasicRule extends BasicRule {

public FixedMaxBasicRule() {
super("SKYS-BASC-0001", "Fixed Max",
"If the sum of two opposing edges is n+1, the maximum number appears at a position k spaces away from the edge, where k is the number at that edge.",
"This is the last cell for this number that does not create a visibility contradiction.",
"edu/rpi/legup/images/skyscrapers/rules/FixedMax.png");
}

Expand All @@ -42,34 +43,41 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
return super.getInvalidUseOfRuleMessage() + ": Modified cells must transition from unknown to number";
}

SkyscrapersBoard emptyCase = initialBoard.copy();
emptyCase.getPuzzleElement(finalCell).setData(0);
Point loc = finalCell.getLocation();
int north = initialBoard.getNorthClues().get(loc.x).getData();
int south = initialBoard.getSouthClues().get(loc.x).getData();
int west = initialBoard.getWestClues().get(loc.y).getData();
int east = initialBoard.getEastClues().get(loc.y).getData();
int max = initialBoard.getHeight();
System.out.println(north);
System.out.println(south);
if (north + south != max + 1 && west + east != max + 1) {
System.out.println("111");
return super.getInvalidUseOfRuleMessage() + ": Opposing clues must add up to max";
}
//set all rules used by case rule to false except for dupe, get all cases
boolean dupeTemp = initialBoard.getDupeFlag();
boolean viewTemp = initialBoard.getViewFlag();
initialBoard.setDupeFlag(false);
initialBoard.setViewFlag(true);
CellForNumberCaseRule caseRule = new CellForNumberCaseRule();
ArrayList<Board> XCandidates = caseRule.getCasesFor(initialBoard,initialBoard.getWestClues().get(finalCell.getLocation().y),(Integer)finalCell.getData());
ArrayList<Board> YCandidates = caseRule.getCasesFor(initialBoard,initialBoard.getNorthClues().get(finalCell.getLocation().x),(Integer)finalCell.getData());
initialBoard.setDupeFlag(dupeTemp);
initialBoard.setViewFlag(viewTemp);

if (finalCell.getData() != initialBoard.getWidth()) {
return super.getInvalidUseOfRuleMessage() + ": Modified cells must be the max";
}
System.out.println(XCandidates.size());
System.out.println(YCandidates.size());

if (north + south == max + 1 && loc.y + 1 == north) {
return null;
}
if (west + east == max + 1 && loc.x + 1 == west) {
//return null if either pass, both messages otherwise
String xCheck = candidateCheck(XCandidates,puzzleElement,finalCell);
String yCheck = candidateCheck(YCandidates,puzzleElement,finalCell);
if(xCheck==null || yCheck==null){
return null;
}
return super.getInvalidUseOfRuleMessage() + "\nRow" + xCheck + "\nCol" + yCheck;
}

return super.getInvalidUseOfRuleMessage() + ": This cell is not forced.";

//helper to check if candidate list is valid
private String candidateCheck(ArrayList<Board> candidates,PuzzleElement puzzleElement, SkyscrapersCell finalCell){
if(candidates.size() == 1){
if(((SkyscrapersCell) candidates.get(0).getPuzzleElement(puzzleElement)).getType() == SkyscrapersType.Number) {
if (candidates.get(0).getPuzzleElement(puzzleElement).getData() == finalCell.getData()) {
return null;
}
return ": Wrong number in the cell.";
}
return ": No case for this cell.";
}
return ": This cell is not forced.";
}

private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType;

import java.awt.Point;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
Expand All @@ -18,7 +19,7 @@ public class OneEdgeBasicRule extends BasicRule {

public OneEdgeBasicRule() {
super("SKYS-BASC-0005", "One Edge",
"If you have a 1 on an edge, put n in the adjacent square.",
"This is the last number for this cell that does not create a visibility contradiction",
"edu/rpi/legup/images/skyscrapers/rules/OneEdge.png");
}

Expand All @@ -42,32 +43,24 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
return super.getInvalidUseOfRuleMessage() + ": Modified cells must transition from unknown to number";
}

SkyscrapersBoard emptyCase = initialBoard.copy();
emptyCase.getPuzzleElement(finalCell).setData(0);
Point loc = finalCell.getLocation();
//set all rules used by case rule to false except for dupe, get all cases
boolean dupeTemp = initialBoard.getDupeFlag();
boolean viewTemp = initialBoard.getViewFlag();
initialBoard.setDupeFlag(false);
initialBoard.setViewFlag(true);
NumberForCellCaseRule caseRule = new NumberForCellCaseRule();
ArrayList<Board> candidates = caseRule.getCases(initialBoard,puzzleElement);
initialBoard.setDupeFlag(dupeTemp);
initialBoard.setViewFlag(viewTemp);

if (loc.x != 0 && loc.x != initialBoard.getWidth() - 1 && loc.y != 0 && loc.y != initialBoard.getHeight() - 1) {
return super.getInvalidUseOfRuleMessage() + ": Modified cells must be on the edge";
}

if (finalCell.getData() != initialBoard.getWidth()) {
return super.getInvalidUseOfRuleMessage() + ": Modified cells must be the max";
}

if (loc.x == 0 && initialBoard.getWestClues().get(loc.y).getData() == 1) {
return null;
}
else if (loc.x == initialBoard.getWidth() - 1 && initialBoard.getEastClues().get(loc.y).getData() == 1) {
return null;
}
else if (loc.y == 0 && initialBoard.getNorthClues().get(loc.x).getData() == 1) {
return null;
}
else if (loc.y == initialBoard.getHeight() - 1 && initialBoard.getSouthClues().get(loc.x).getData() == 1) {
return null;
} else {
return "This cell is not forced.";
//check if given value is the only remaining value
if(candidates.size() == 1){
if(candidates.get(0).getPuzzleElement(puzzleElement).getData() == finalCell.getData()){
return null;
}
return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell.";
}
return super.getInvalidUseOfRuleMessage() + ":This cell is not forced.";
}

private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) {
Expand Down

This file was deleted.

4 changes: 1 addition & 3 deletions src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ spreadsheet : https://docs.google.com/spreadsheets/d/1l7aUZtavtysM8dtGnaEIXhBKMR
- create and add rule icons
- check for overrides of by cell functions (ie checkContradiction)
- replace height/width with size (never not square)
- replace row,col,rowClues,colClues and corresponding functions with appropriate names
5. Flags
- review all basic/contradiction rules to put in terms of the new cases / add flags
- edit exporter to include flags in xml file format
- discuss use/not of unresolved flag
- edit exporter to include flags in xml file format (if needed)
6. Documentation
- UML diagram(s)