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

New puzzle skyscrapers #355

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 @@ -226,6 +226,23 @@ public List<SkyscrapersCell> getRowCol(int index, SkyscrapersType type, boolean
return list;
}

/**
* Prints a semblance of the board to console (helps in debugging)
*/
public void printBoard(){
for(int i =0; i<this.dimension.height; i++){
for(SkyscrapersCell cell : this.getRowCol(i, SkyscrapersType.ANY,true)){
if(cell.getType() == SkyscrapersType.Number){
System.out.print(cell.getData()+" ");
}
else {
System.out.print(0+ " ");
}
}
System.out.println();
}
}

/**
* Determines if this board contains the equivalent puzzle elements as the one specified
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import edu.rpi.legup.model.rules.ContradictionRule;
import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard;
import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell;
import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType;

import java.awt.*;
import java.util.Queue;
Expand Down Expand Up @@ -54,84 +55,108 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
//check row west clue
List<Board> rows;

for(int j = 0; j < rowQ.size(); j++) {
int size = rowQ.size();
for(int j = 0; j < size; j++) {
SkyscrapersBoard temp = rowQ.poll(); //get row from the top of the stack

//set flags
boolean dupeTemp = temp.getDupeFlag();
boolean viewTemp = temp.getViewFlag();
temp.setDupeFlag(true);
temp.setViewFlag(false);
//don't do anything if already in row
boolean exists = false;
for(SkyscrapersCell c : temp.getRowCol(loc.y,SkyscrapersType.Number,true)){
if(c.getData()==num) {
exists = true;
break;
}
}

//get all cases for corresponding row based on west clue
rows = caseRule.getCasesFor(temp, skyscrapersBoard.getWestClues().get(loc.y), num);
if(exists) {
rowQ.add(temp);
}
else{
//set flags
boolean dupeTemp = temp.getDupeFlag();
boolean viewTemp = temp.getViewFlag();
temp.setDupeFlag(false);
temp.setViewFlag(false);

//reset flags
temp.setDupeFlag(dupeTemp);
temp.setViewFlag(viewTemp);
//get all cases for corresponding row based on west clue
rows = caseRule.getCasesFor(temp, skyscrapersBoard.getWestClues().get(loc.y), num);

//add all row cases to row queue
if (rows.size() == 0)
rowQ.add(temp);
else {
//reset flags
temp.setDupeFlag(dupeTemp);
temp.setViewFlag(viewTemp);

//add all row cases to row queue
for (Board k : rows) {
rowQ.add((SkyscrapersBoard) k);
}
}
}


//check col north clue
List<Board> cols;

for(int j = 0; j < colQ.size(); j++) {
size = colQ.size();
for(int j = 0; j < size; j++) {
SkyscrapersBoard temp = colQ.poll(); //get row from the top of the stack

//set flags
boolean dupeTemp = temp.getDupeFlag();
boolean viewTemp = temp.getViewFlag();
temp.setDupeFlag(true);
temp.setViewFlag(false);
//don't do anything if already in col
boolean exists = false;
for(SkyscrapersCell c : temp.getRowCol(loc.x,SkyscrapersType.Number,false)){
if(c.getData()==num) {
exists = true;
break;
}
}

if(exists){
colQ.add(temp);
}
else{
//set flags
boolean dupeTemp = temp.getDupeFlag();
boolean viewTemp = temp.getViewFlag();
temp.setDupeFlag(false);
temp.setViewFlag(false);

//get all cases for corresponding col based on north clue
cols = caseRule.getCasesFor(temp, skyscrapersBoard.getNorthClues().get(loc.x), num);
//get all cases for corresponding col based on north clue
cols = caseRule.getCasesFor(temp, skyscrapersBoard.getNorthClues().get(loc.x), num);

//reset flags
temp.setDupeFlag(dupeTemp);
temp.setViewFlag(viewTemp);
//reset flags
temp.setDupeFlag(dupeTemp);
temp.setViewFlag(viewTemp);

//add all row cases to row queue
if(cols.size() == 0)
colQ.add(temp);
else {
//add all row cases to row queue
for(Board k : cols)
colQ.add((SkyscrapersBoard) k);
}
}

}

String rowTooFew;
String rowTooMany;
boolean rowContradiction = true;
//check if each case board has a contradiction
for(int j = 0; j < rowQ.size(); j++) {
while(rowQ.size()>0) {
SkyscrapersBoard fullRow = rowQ.poll();

//checks if there is a contradiction given the row based on the west clue
rowTooFew = tooFew.checkContradictionAt(fullRow, cell); // is cell the correct puzzle element to check?
rowTooMany = tooMany.checkContradictionAt(fullRow, cell);

//boolean that checks if there is a contradiction within all rows
rowContradiction = rowContradiction && (rowTooFew == null || rowTooMany == null); // !null means there isn't a contradiction, so there must be a valid permutation of the array
rowContradiction = rowContradiction && (rowTooFew == null || rowTooMany == null);// !null means there isn't a contradiction, so there must be a valid permutation of the array
}

String colTooFew;
String colTooMany;
boolean colContradiction = true;
for(int j = 0; j < colQ.size(); j++) {
while(colQ.size()>0) {
SkyscrapersBoard fullCol = colQ.poll();

//checks if there is a contradiction given the col baesd on the north clue
colTooFew = tooFew.checkContradictionAt(fullCol, cell);
colTooMany = tooMany.checkContradictionAt(fullCol, cell);

//boolean that checks if there is a contradiction within all the cols
colContradiction = colContradiction && (colTooFew == null || colTooMany == null);
}
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@
spreadsheet : https://docs.google.com/spreadsheets/d/1l7aUZtavtysM8dtGnaEIXhBKMRGxekhnLIVoYIHYZi8/edit#gid=0

1. Basic Rules:
- Rename to fit uses
- Last visible/singular number/cell?
- Come up with better names for 1Edge and FixedMax, they are now more general
2. Contradiction Rules:
- Generalize visibility rules to non-full lines
- Figure out why these aren't static methods
3. Case Rules:
4. Refactoring:
- Remove references to lightup and treetent in variable names
- View contains a few of these
- document utility functions in the reference sheet, COMMENTS!
- review and identify dead code
- create and add rule icons
- check for overrides of by cell functions (ie checkContradiction)
- Save rule icons from compression
- replace height/width with size (never not square)
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 (if needed)
6. Documentation
- UML diagram(s)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RULE LIST:
SKYS-CONT-0003 : InsufficientVisibilityContradictionRule
SKYS-CONT-0004 : NoNumberForCellContradictionRule/UnresoveldCell
SKYS-CONT-0005 : NoCellForNumberContradictionRule/UnresoveldNumber
SKYS-CONT-0006 : PreemptiveVisibilityContradictionRule

SKYS-CASE-0001 : NumberForCellCaseRule
SKYS-CASE-0002 : CellForNumberCaseRule
Expand All @@ -18,7 +19,11 @@ HELPER FUNCTIONS: (check morgue for unused helpers, ctrl+f "helper function")
-getRowCol
Location: skyscrapersBoard
Use: returns elements in a row or col
Notes: more than one element type?
Notes: more than one element type? (Added an Any type to help with this!)
-printBoard
Location: skyscrapersBoard
Use: Prints the data array to console
Notes: Pretty useful for debugging where boards aren't printed

CODE MORGUE:
- Exporter has no known use, to has not been updated
Expand Down