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 #284

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 @@ -12,10 +12,15 @@ public class SkyscrapersBoard extends GridBoard {

private ArrayList<SkyscrapersLine> lines;


private ArrayList<SkyscrapersClue> rowClues;
//EAST clues
private ArrayList<SkyscrapersClue> colClues;
//SOUTH clues
private ArrayList<SkyscrapersClue> row;
//WEST clues
private ArrayList<SkyscrapersClue> col;
//NORTH clues

private boolean viewFlag = false;
private boolean dupeFlag = true;
Expand Down Expand Up @@ -53,19 +58,31 @@ public ArrayList<SkyscrapersLine> getLines() {
return lines;
}

public ArrayList<SkyscrapersClue> getRowClues() { //EAST CLUE
/**
* Returns a list of the eastern clues ordered from loc.y = 0->max
*/
public ArrayList<SkyscrapersClue> getRowClues() {
return rowClues;
}

public ArrayList<SkyscrapersClue> getColClues() { //SOUTH CLUE
/**
* Returns a list of the southern clues ordered from loc.x = 0->max
*/
public ArrayList<SkyscrapersClue> getColClues() {
return colClues;
}

public ArrayList<SkyscrapersClue> getRow() { //WEST CLUE

/**
* Returns a list of the western clues ordered from loc.y = 0->max
*/
public ArrayList<SkyscrapersClue> getRow() {
return row;
}

public ArrayList<SkyscrapersClue> getCol() { //NORTH CLUE
/**
* Returns a list of the northern clues ordered from loc.x = 0->max
*/
public ArrayList<SkyscrapersClue> getCol() {
return col;
}

Expand Down Expand Up @@ -123,45 +140,59 @@ 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<SkyscrapersCell> getAdjacent(SkyscrapersCell cell, SkyscrapersType type) {
List<SkyscrapersCell> adj = new ArrayList<>();
Point loc = cell.getLocation();
SkyscrapersCell up = getCell(loc.x, loc.y - 1);
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<SkyscrapersCell> getDiagonals(SkyscrapersCell cell, SkyscrapersType type) {
List<SkyscrapersCell> dia = new ArrayList<>();
Point loc = cell.getLocation();
SkyscrapersCell upRight = getCell(loc.x + 1, loc.y - 1);
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;
Expand All @@ -177,19 +208,17 @@ public List<SkyscrapersCell> getDiagonals(SkyscrapersCell cell, SkyscrapersType
*/
public List<SkyscrapersCell> getRowCol(int index, SkyscrapersType type, boolean isRow) {
List<SkyscrapersCell> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- edit importer and exporter to include flags in xml file format
6. Documentation
- UML diagram(s)
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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!