From 74b92f575ab1ce26bc2f9a7deb2b72aa89756b41 Mon Sep 17 00:00:00 2001 From: ThisMatt Date: Fri, 28 Oct 2022 22:45:16 -0400 Subject: [PATCH 1/2] Added a printBoard function to help with debugging --- .../puzzle/skyscrapers/SkyscrapersBoard.java | 17 +++++++++++++++++ .../rules/skyscrapers_reference_sheet.txt | 7 ++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java index 88f28dddf..13f771a29 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java @@ -226,6 +226,23 @@ public List 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 Date: Fri, 28 Oct 2022 22:46:30 -0400 Subject: [PATCH 2/2] PreemptiveVisibility rule now correctly checks all possibilities --- ...PreemptiveVisibilityContradictionRule.java | 95 ++++++++++++------- .../legup/puzzle/skyscrapers/rules/TODO.md | 9 +- 2 files changed, 62 insertions(+), 42 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PreemptiveVisibilityContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PreemptiveVisibilityContradictionRule.java index 88a9dd8f7..81533ff9c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PreemptiveVisibilityContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PreemptiveVisibilityContradictionRule.java @@ -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; @@ -54,84 +55,108 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { //check row west clue List 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 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); } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md index 294119409..d08b8f326 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md @@ -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) \ No newline at end of file