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 af031c46c..d28e99ecc 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java @@ -12,10 +12,15 @@ public class SkyscrapersBoard extends GridBoard { private ArrayList lines; + private ArrayList rowClues; + //EAST clues private ArrayList colClues; + //SOUTH clues private ArrayList row; + //WEST clues private ArrayList col; + //NORTH clues private boolean viewFlag = false; private boolean dupeFlag = true; @@ -53,19 +58,31 @@ public ArrayList getLines() { return lines; } - public ArrayList getRowClues() { //EAST CLUE + /** + * Returns a list of the eastern clues ordered from loc.y = 0->max + */ + public ArrayList getRowClues() { return rowClues; } - public ArrayList getColClues() { //SOUTH CLUE + /** + * Returns a list of the southern clues ordered from loc.x = 0->max + */ + public ArrayList getColClues() { return colClues; } - - public ArrayList getRow() { //WEST CLUE + + /** + * Returns a list of the western clues ordered from loc.y = 0->max + */ + public ArrayList getRow() { return row; } - public ArrayList getCol() { //NORTH CLUE + /** + * Returns a list of the northern clues ordered from loc.x = 0->max + */ + public ArrayList getCol() { return col; } @@ -123,6 +140,13 @@ public void notifyDeletion(PuzzleElement puzzleElement) { } } + /** + * Gets the cells of a certain type directly adjacent to a given cell + * + * @param cell at the center, + * type of cell to collect + * @return list of cells of the given type + */ public List getAdjacent(SkyscrapersCell cell, SkyscrapersType type) { List adj = new ArrayList<>(); Point loc = cell.getLocation(); @@ -130,21 +154,28 @@ public List getAdjacent(SkyscrapersCell cell, SkyscrapersType t SkyscrapersCell right = getCell(loc.x + 1, loc.y); SkyscrapersCell down = getCell(loc.x, loc.y + 1); SkyscrapersCell left = getCell(loc.x - 1, loc.y); - if (up != null && up.getType() == type) { + if (up != null && (up.getType() == type || type == SkyscrapersType.ANY)) { adj.add(up); } - if (right != null && right.getType() == type) { + if (right != null && (right.getType() == type || type == SkyscrapersType.ANY)) { adj.add(right); } - if (down != null && down.getType() == type) { + if (down != null && (down.getType() == type || type == SkyscrapersType.ANY)) { adj.add(down); } - if (left != null && left.getType() == type) { + if (left != null && (left.getType() == type || type == SkyscrapersType.ANY)) { adj.add(left); } return adj; } + /** + * Gets the cells of a certain type directly diagonal to a given cell + * + * @param cell at the center, + * type of cell to collect + * @return list of cells of the given type + */ public List getDiagonals(SkyscrapersCell cell, SkyscrapersType type) { List dia = new ArrayList<>(); Point loc = cell.getLocation(); @@ -152,16 +183,16 @@ public List getDiagonals(SkyscrapersCell cell, SkyscrapersType SkyscrapersCell downRight = getCell(loc.x + 1, loc.y + 1); SkyscrapersCell downLeft = getCell(loc.x - 1, loc.y + 1); SkyscrapersCell upLeft = getCell(loc.x - 1, loc.y - 1); - if (upRight != null && upRight.getType() == type) { + if (upRight != null && (upRight.getType() == type || type == SkyscrapersType.ANY)) { dia.add(upRight); } - if (downLeft != null && downLeft.getType() == type) { + if (downLeft != null && (downLeft.getType() == type || type == SkyscrapersType.ANY)) { dia.add(downLeft); } - if (downRight != null && downRight.getType() == type) { + if (downRight != null && (downRight.getType() == type || type == SkyscrapersType.ANY)) { dia.add(downRight); } - if (upLeft != null && upLeft.getType() == type) { + if (upLeft != null && (upLeft.getType() == type || type == SkyscrapersType.ANY)) { dia.add(upLeft); } return dia; @@ -177,19 +208,17 @@ public List getDiagonals(SkyscrapersCell cell, SkyscrapersType */ public List getRowCol(int index, SkyscrapersType type, boolean isRow) { List list = new ArrayList<>(); - if (isRow) { - for (int i = 0; i < dimension.height; i++) { - SkyscrapersCell cell = getCell(i, index); - if (cell.getType() == type) { - list.add(cell); - } + for (int i = 0; i < dimension.height; i++) { + SkyscrapersCell cell; + if (isRow) { + cell = getCell(i, index); } - } else { - for (int i = 0; i < dimension.width; i++) { - SkyscrapersCell cell = getCell(index, i); - if (cell.getType() == type) { - list.add(cell); - } + else { + cell = getCell(index, i); + } + + if (cell.getType() == type || type == SkyscrapersType.ANY) { + list.add(cell); } } return list; diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersType.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersType.java index 3340af8bf..1fdd668c1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersType.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersType.java @@ -1,7 +1,7 @@ package edu.rpi.legup.puzzle.skyscrapers; public enum SkyscrapersType { - UNKNOWN(0), Number(1), GRASS(2), TENT(3), CLUE_NORTH(-1), CLUE_EAST(-2), CLUE_SOUTH(-3), CLUE_WEST(-4); + UNKNOWN(0), Number(1), ANY(2), CLUE_NORTH(-1), CLUE_EAST(-2), CLUE_SOUTH(-3), CLUE_WEST(-4); public int value; 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 cdc9aa2a3..73de45b45 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 @@ -16,7 +16,10 @@ spreadsheet : https://docs.google.com/spreadsheets/d/1l7aUZtavtysM8dtGnaEIXhBKMR - review and identify dead code - create and add rule icons - check for overrides of by cell functions (ie checkContradiction) + - replace row,col,rowClues,colClues and corresponding functions with appropriate names 5. Flags - add to all case rules - review all basic/contradiction rules to put in terms of the new cases / add flags - - edit importer and exporter to include flags in xml file format \ No newline at end of file + - edit importer and exporter to include flags in xml file format + 6. Documentation + - UML diagram(s) \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/skyscrapers_reference_sheet.txt b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/skyscrapers_reference_sheet.txt index 8d17ee0b6..31f18b45e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/skyscrapers_reference_sheet.txt +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/skyscrapers_reference_sheet.txt @@ -14,14 +14,22 @@ RULE LIST: SKYS-CASE-0001 : NumberForCellCaseRule SKYS-CASE-0002 : CellForNumberCaseRule -HELPER FUNCTIONS: +HELPER FUNCTIONS: (check morgue for unused helpers, ctrl+f "helper function") -getRowCol Location: skyscrapersBoard - Use: returns all elements in a row or col + Use: returns elements in a row or col Notes: more than one element type? -CODE MOURGE: +CODE MORGUE: - isForced, getDefaultBoard - Locations: - Uses?: Unknown - Notes: \ No newline at end of file + Locations: + Uses?: Unknown + Notes: Seems like a sanity check, but I cannot find a situation where it runs + -getDiagonals + Location: skyscrapersBoard + Use: helper function - gets cells immediately diagonal to a cell + Note: If you implement this, move it from morgue to helper functions section! + -getAdjacent + Location: skyscrapersBoard + Use: helper function - gets cells immediately adjacent to a cell + Note: If you implement this, move it from morgue to helper functions section! \ No newline at end of file