Skip to content

Commit

Permalink
Merge pull request #332 from ThisMatt/new_puzzle-skyscrapers
Browse files Browse the repository at this point in the history
New puzzle skyscrapers
  • Loading branch information
ThisMatt authored Oct 11, 2022
2 parents 245ffda + ad60e4d commit 921d8cc
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public class SkyscrapersBoard extends GridBoard {
private ArrayList<SkyscrapersLine> lines;


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

private boolean viewFlag = false;
Expand All @@ -31,22 +31,16 @@ public SkyscrapersBoard(int width, int height) {

this.lines = new ArrayList<>();

this.rowClues = new ArrayList<>();
this.colClues = new ArrayList<>();
this.row = new ArrayList<>();
this.col = new ArrayList<>();
this.eastClues = new ArrayList<>();
this.southClues = new ArrayList<>();
this.westClues = new ArrayList<>();
this.northClues = new ArrayList<>();

for (int i = 0; i < height; i++) {
rowClues.add(null);
}
for (int i = 0; i < width; i++) {
colClues.add(null);
}
for (int i = 0; i < height; i++) {
row.add(null);
}
for (int i = 0; i < width; i++) {
col.add(null);
eastClues.add(null);
southClues.add(null);
westClues.add(null);
northClues.add(null);
}
}

Expand All @@ -61,29 +55,27 @@ public ArrayList<SkyscrapersLine> getLines() {
/**
* Returns a list of the eastern clues ordered from loc.y = 0->max
*/
public ArrayList<SkyscrapersClue> getRowClues() {
return rowClues;
public ArrayList<SkyscrapersClue> getEastClues() {
return eastClues;
}

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

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

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

public boolean getDupeFlag(){return dupeFlag;}
Expand Down Expand Up @@ -270,10 +262,10 @@ public SkyscrapersBoard copy() {
for (PuzzleElement e : modifiedData) {
copy.getPuzzleElement(e).setModifiable(false);
}
copy.rowClues = rowClues;
copy.colClues = colClues;
copy.row = row;
copy.col = col;
copy.eastClues = eastClues;
copy.southClues = southClues;
copy.westClues = westClues;
copy.northClues = northClues;

copy.dupeFlag=dupeFlag;
copy.viewFlag=viewFlag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {

org.w3c.dom.Element axisEast = newDocument.createElement("axis");
axisEast.setAttribute("side", "east");
for (SkyscrapersClue clue : board.getRowClues()) {
for (SkyscrapersClue clue : board.getEastClues()) {
org.w3c.dom.Element clueElement = newDocument.createElement("clue");
clueElement.setAttribute("value", String.valueOf(clue.getData()));
clueElement.setAttribute("index", SkyscrapersClue.colNumToString(clue.getIndex()));
Expand All @@ -40,7 +40,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {

org.w3c.dom.Element axisSouth = newDocument.createElement("axis");
axisSouth.setAttribute("side", "south");
for (SkyscrapersClue clue : board.getRowClues()) {
for (SkyscrapersClue clue : board.getSouthClues()) {
org.w3c.dom.Element clueElement = newDocument.createElement("clue");
clueElement.setAttribute("value", String.valueOf(clue.getData()));
clueElement.setAttribute("index", String.valueOf(clue.getIndex()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
if (treeTentBoard.getRowClues().get(index - 1) != null) {
throw new InvalidFileFormatException("TreeTent Importer: duplicate clue index");
}*/
treeTentBoard.getRow().set(/*index - 1*/i, new SkyscrapersClue(index, i, SkyscrapersType.CLUE_WEST));
treeTentBoard.getRowClues().set(/*index - 1*/i, new SkyscrapersClue(value, i, SkyscrapersType.CLUE_EAST));
treeTentBoard.getWestClues().set(/*index - 1*/i, new SkyscrapersClue(index, i, SkyscrapersType.CLUE_WEST));
treeTentBoard.getEastClues().set(/*index - 1*/i, new SkyscrapersClue(value, i, SkyscrapersType.CLUE_EAST));
}

for (int i = 0; i < southClues.getLength(); i++) {
Expand All @@ -130,8 +130,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
if (treeTentBoard.getColClues().get(index - 1) != null) {
throw new InvalidFileFormatException("TreeTent Importer: duplicate clue index");
}*/
treeTentBoard.getCol().set(/*index - 1*/i, new SkyscrapersClue(index, i, SkyscrapersType.CLUE_NORTH));
treeTentBoard.getColClues().set(/*index - 1*/i, new SkyscrapersClue(value, i, SkyscrapersType.CLUE_SOUTH));
treeTentBoard.getNorthClues().set(/*index - 1*/i, new SkyscrapersClue(index, i, SkyscrapersType.CLUE_NORTH));
treeTentBoard.getSouthClues().set(/*index - 1*/i, new SkyscrapersClue(value, i, SkyscrapersType.CLUE_SOUTH));
}

if (boardElement.getElementsByTagName("lines").getLength() == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public SkyscrapersView(SkyscrapersBoard board) {

for (int i = 0; i < gridSize.height; i++) {
//SkyscrapersClueView row = new SkyscrapersClueView(new SkyscrapersClue(i, i, SkyscrapersType.CLUE_WEST));
SkyscrapersClueView row = new SkyscrapersClueView(board.getRow().get(i));
SkyscrapersClueView row = new SkyscrapersClueView(board.getWestClues().get(i));
row.setLocation(new Point(0, (i + 1) * elementSize.height));
row.setSize(elementSize);

SkyscrapersClueView clue = new SkyscrapersClueView(board.getRowClues().get(i));
SkyscrapersClueView clue = new SkyscrapersClueView(board.getEastClues().get(i));
clue.setLocation(new Point((gridSize.height + 1) * elementSize.height, (i + 1) * elementSize.height));
clue.setSize(elementSize);

Expand All @@ -78,11 +78,11 @@ public SkyscrapersView(SkyscrapersBoard board) {

for (int i = 0; i < gridSize.width; i++) {
//SkyscrapersClueView col = new SkyscrapersClueView(new SkyscrapersClue(i, i, SkyscrapersType.CLUE_NORTH));
SkyscrapersClueView col = new SkyscrapersClueView(board.getCol().get(i));
SkyscrapersClueView col = new SkyscrapersClueView(board.getNorthClues().get(i));
col.setLocation(new Point((i + 1) * elementSize.width, 0));
col.setSize(elementSize);

SkyscrapersClueView clue = new SkyscrapersClueView(board.getColClues().get(i));
SkyscrapersClueView clue = new SkyscrapersClueView(board.getSouthClues().get(i));
clue.setLocation(new Point((i + 1) * elementSize.width, (gridSize.width + 1) * elementSize.width));
clue.setSize(elementSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public CaseBoard getCaseBoard(Board board) {
SkyscrapersBoard currentBoard = (SkyscrapersBoard) board.copy();
currentBoard.setModifiable(false);
CaseBoard caseBoard = new CaseBoard(currentBoard, this);
for (SkyscrapersClue data : currentBoard.getRow()) {
for (SkyscrapersClue data : currentBoard.getWestClues()) {
System.out.println(data.getType());
caseBoard.addPickableElement(data);
}
for (SkyscrapersClue data : currentBoard.getCol()) {
for (SkyscrapersClue data : currentBoard.getNorthClues()) {
System.out.println(data.getType());
caseBoard.addPickableElement(data);
}
Expand Down Expand Up @@ -88,14 +88,14 @@ public String checkRuleRaw(TreeTransition transition) {

//find changed row/col
SkyscrapersClue modClue = null;
for(SkyscrapersClue clue : ((SkyscrapersBoard)childTransitions.get(0).getBoard()).getRow()){
for(SkyscrapersClue clue : ((SkyscrapersBoard)childTransitions.get(0).getBoard()).getWestClues()){
if(clue.isModified()){
modClue = clue;
break;
}
}
if(modClue!=null){
for(SkyscrapersClue clue : ((SkyscrapersBoard)childTransitions.get(0).getBoard()).getCol()){
for(SkyscrapersClue clue : ((SkyscrapersBoard)childTransitions.get(0).getBoard()).getNorthClues()){
if(clue.isModified()){
modClue = clue;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
Point loc = cell.getLocation();

//get borders
int west = skyscrapersboard.getRow().get(loc.y).getData();
int east = skyscrapersboard.getRowClues().get(loc.y).getData();
int north = skyscrapersboard.getCol().get(loc.x).getData();
int south = skyscrapersboard.getColClues().get(loc.x).getData();
int west = skyscrapersboard.getWestClues().get(loc.y).getData();
int east = skyscrapersboard.getEastClues().get(loc.y).getData();
int north = skyscrapersboard.getNorthClues().get(loc.x).getData();
int south = skyscrapersboard.getSouthClues().get(loc.x).getData();

//check row
int max = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
SkyscrapersBoard emptyCase = initialBoard.copy();
emptyCase.getPuzzleElement(finalCell).setData(0);
Point loc = finalCell.getLocation();
int north = initialBoard.getCol().get(loc.x).getData();
int south = initialBoard.getColClues().get(loc.x).getData();
int west = initialBoard.getRow().get(loc.y).getData();
int east = initialBoard.getRowClues().get(loc.y).getData();
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
Point loc = cell.getLocation();

//get borders
int west = skyscrapersboard.getRow().get(loc.y).getData();
int east = skyscrapersboard.getRowClues().get(loc.y).getData();
int north = skyscrapersboard.getCol().get(loc.x).getData();
int south = skyscrapersboard.getColClues().get(loc.x).getData();
int west = skyscrapersboard.getWestClues().get(loc.y).getData();
int east = skyscrapersboard.getEastClues().get(loc.y).getData();
int north = skyscrapersboard.getNorthClues().get(loc.x).getData();
int south = skyscrapersboard.getSouthClues().get(loc.x).getData();

//check row
int max = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
initialBoard.setDupeFlag(true);
initialBoard.setViewFlag(false);
CellForNumberCaseRule caseRule = new CellForNumberCaseRule();
ArrayList<Board> XCandidates = caseRule.getCasesFor(initialBoard,initialBoard.getRow().get(finalCell.getLocation().y),(Integer)finalCell.getData());
ArrayList<Board> YCandidates = caseRule.getCasesFor(initialBoard,initialBoard.getCol().get(finalCell.getLocation().x),(Integer)finalCell.getData());
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
Point loc = finalCell.getLocation();
int max = initialBoard.getHeight();

if (initialBoard.getRow().get(loc.y).getData() == max && finalCell.getData() == loc.x + 1) {
if (initialBoard.getWestClues().get(loc.y).getData() == max && finalCell.getData() == loc.x + 1) {
return null;
}
if (initialBoard.getRowClues().get(loc.y).getData() == max && finalCell.getData() == max - loc.x) {
if (initialBoard.getEastClues().get(loc.y).getData() == max && finalCell.getData() == max - loc.x) {
return null;
}
if (initialBoard.getCol().get(loc.x).getData() == max && finalCell.getData() == loc.y + 1) {
if (initialBoard.getNorthClues().get(loc.x).getData() == max && finalCell.getData() == loc.y + 1) {
return null;
}
if (initialBoard.getColClues().get(loc.x).getData() == max && finalCell.getData() == max - loc.y) {
if (initialBoard.getSouthClues().get(loc.x).getData() == max && finalCell.getData() == max - loc.y) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
return super.getInvalidUseOfRuleMessage() + ": Modified cells must be the max";
}

if (loc.x == 0 && initialBoard.getRow().get(loc.y).getData() == 1) {
if (loc.x == 0 && initialBoard.getWestClues().get(loc.y).getData() == 1) {
return null;
}
else if (loc.x == initialBoard.getWidth() - 1 && initialBoard.getRowClues().get(loc.y).getData() == 1) {
else if (loc.x == initialBoard.getWidth() - 1 && initialBoard.getEastClues().get(loc.y).getData() == 1) {
return null;
}
else if (loc.y == 0 && initialBoard.getCol().get(loc.x).getData() == 1) {
else if (loc.y == 0 && initialBoard.getNorthClues().get(loc.x).getData() == 1) {
return null;
}
else if (loc.y == initialBoard.getHeight() - 1 && initialBoard.getColClues().get(loc.x).getData() == 1) {
else if (loc.y == initialBoard.getHeight() - 1 && initialBoard.getSouthClues().get(loc.x).getData() == 1) {
return null;
} else {
return "This cell is not forced.";
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ spreadsheet : https://docs.google.com/spreadsheets/d/1l7aUZtavtysM8dtGnaEIXhBKMR
- Cell for number - waiting on ui
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)
- 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
}
if(!exists){
//and no possible cases
if(caseRule.getCasesFor(board,skyscrapersBoard.getRow().get(loc.y),num).size()==0) {
if(caseRule.getCasesFor(board,skyscrapersBoard.getWestClues().get(loc.y),num).size()==0) {
return null;
}
}
Expand All @@ -65,7 +65,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
}
}
if(!exists){
if(caseRule.getCasesFor(board,skyscrapersBoard.getCol().get(loc.x),num).size()==0) {
if(caseRule.getCasesFor(board,skyscrapersBoard.getNorthClues().get(loc.x),num).size()==0) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ HELPER FUNCTIONS: (check morgue for unused helpers, ctrl+f "helper function")
Notes: more than one element type?

CODE MORGUE:
- Exporter has no known use, to has not been updated
- SkyscapersLine, SkyscrapersLineView
Locations: above classes, Board, Importer, CellFactory, View
Uses: drawing lines between cells on the board
Expand Down

0 comments on commit 921d8cc

Please sign in to comment.