Skip to content

Commit

Permalink
Merge pull request #2 from ThisMatt/new_puzzle-skyscrapers
Browse files Browse the repository at this point in the history
New puzzle skyscrapers
  • Loading branch information
ThisMatt authored Sep 22, 2023
2 parents f6418b6 + 04fdbd2 commit 9968640
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

import java.awt.*;

public class SkyscrapersCell extends GridCell<SkyscrapersType> {
import static edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType.convertToSkyType;

public class SkyscrapersCell extends GridCell<Integer> {
private int max;

public SkyscrapersCell(SkyscrapersType value, Point location, int size) {
public SkyscrapersCell(Integer value, Point location, int size) {
super(value, location);
this.max = size;
}

public SkyscrapersType getType() {
switch (data) {
switch (convertToSkyType(data)){
case UNKNOWN:
return SkyscrapersType.UNKNOWN;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat
throw new InvalidFileFormatException("TreeTent Factory: cell unknown value");
}

SkyscrapersCell cell = new SkyscrapersCell(SkyscrapersType.convertToSkyType(value), new Point(x, y), width);
SkyscrapersCell cell = new SkyscrapersCell(value, new Point(x, y), width);
cell.setIndex(y * height + x);
return cell;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,22 @@ public void mouseReleased(MouseEvent e) {
public void changeCell(MouseEvent e, PuzzleElement element) {
SkyscrapersCell cell = (SkyscrapersCell) element;
if (e.getButton() == MouseEvent.BUTTON1) {
if (cell.getData().value < cell.getMax()) {
int num = cell.getData().value + 1;
cell.setData(cell.getData().convertToSkyType(num));
if (cell.getData() < cell.getMax()) {
int num = cell.getData() + 1;
cell.setData(num);
}
else {
cell.setData(SkyscrapersType.UNKNOWN);
cell.setData(SkyscrapersType.UNKNOWN.value);
}
}
else {
if (e.getButton() == MouseEvent.BUTTON3) {
if (cell.getData().value > 0) {
int num = cell.getData().value - 1;
cell.setData(cell.getData().convertToSkyType(num));
if (cell.getData() > 0) {
int num = cell.getData() - 1;
cell.setData(num);
}
else {
cell.setData(cell.getData().convertToSkyType(cell.getMax()));
cell.setData(cell.getMax());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void drawElement(Graphics2D graphics2D) {
graphics2D.drawRect(location.x, location.y, size.width, size.height);

SkyscrapersCell cell = (SkyscrapersCell) puzzleElement;
int val = cell.getData().value;
int val = cell.getData();
if (val != 0) {
graphics2D.setColor(FONT_COLOR);
graphics2D.setFont(FONT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
org.w3c.dom.Element cellsElement = newDocument.createElement("cells");
for (PuzzleElement puzzleElement : board.getPuzzleElements()) {
SkyscrapersCell cell = (SkyscrapersCell) puzzleElement;
if (cell.getData().value != 0) {
if (cell.getData() != 0) {
org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement);
cellsElement.appendChild(cellElement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
for (int i = 0; i < elementDataList.getLength(); i++) {
SkyscrapersCell cell = (SkyscrapersCell) puzzle.getFactory().importCell(elementDataList.item(i), skyscrapersBoard);
Point loc = cell.getLocation();
if (cell.getData().value != 0) {
if (cell.getData() != 0) {
cell.setModifiable(false);
cell.setGiven(true);
}
Expand All @@ -72,7 +72,7 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
if (skyscrapersBoard.getCell(x, y) == null) {
SkyscrapersCell cell = new SkyscrapersCell(SkyscrapersType.UNKNOWN, new Point(x, y), size);
SkyscrapersCell cell = new SkyscrapersCell(SkyscrapersType.UNKNOWN.value, new Point(x, y), size);
cell.setIndex(y * size + x);
cell.setModifiable(true);
skyscrapersBoard.setCell(x, y, cell);
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), ANY(2), CLUE_NORTH(-1), CLUE_EAST(-2), CLUE_SOUTH(-3), CLUE_WEST(-4);
UNKNOWN(0), Number(1), CLUE_NORTH(-1), CLUE_EAST(-2), CLUE_SOUTH(-3), CLUE_WEST(-4), ANY(-5);

public int value;

Expand All @@ -11,10 +11,8 @@ public enum SkyscrapersType {

public static SkyscrapersType convertToSkyType(int num) {
switch (num) {
case 1:
return Number;
case 2:
return ANY;
case 0:
return UNKNOWN;
case -1:
return CLUE_NORTH;
case -2:
Expand All @@ -23,8 +21,10 @@ public static SkyscrapersType convertToSkyType(int num) {
return CLUE_SOUTH;
case -4:
return CLUE_WEST;
case -5:
return ANY;
default:
return UNKNOWN;
return Number;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
if (row.size() == skyscrapersboard.getWidth()) {
//from west border
for (SkyscrapersCell c : row) {
if (c.getData().value > max) {
System.out.print(c.getData());
if (c.getData() > max) {
//System.out.print(c.getData());
//System.out.println(cell.getData());
max = c.getData().value;
max = c.getData();
count++;
}
}
Expand All @@ -64,10 +64,10 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
//from east border
Collections.reverse(row);
for (SkyscrapersCell c : row) {
if (c.getData().value > max) {
if (c.getData() > max) {
System.out.print(c.getData());
//System.out.println(cell.getData());
max = c.getData().value;
max = c.getData();
count++;
}
}
Expand All @@ -84,10 +84,10 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
count = 0;
for (SkyscrapersCell c : col) {
System.out.println(c.getData());
if (c.getData().value > max) {
if (c.getData() > max) {

//System.out.println(cell.getData());
max = c.getData().value;
max = c.getData();
count++;
}
}
Expand All @@ -101,10 +101,10 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
Collections.reverse(col);
for (SkyscrapersCell c : col) {
System.out.println(c.getData());
if (c.getData().value > max) {
if (c.getData() > max) {

//System.out.println(cell.getData());
max = c.getData().value;
max = c.getData();
count++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
if (row.size() == skyscrapersboard.getWidth()) {
//from west border
for (SkyscrapersCell c : row) {
if (c.getData().value > max) {
if (c.getData() > max) {
System.out.print(c.getData());
//System.out.println(cell.getData());
max = c.getData().value;
max = c.getData();
count++;
}
}
Expand All @@ -64,10 +64,10 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
//from east border
Collections.reverse(row);
for (SkyscrapersCell c : row) {
if (c.getData().value > max) {
if (c.getData() > max) {
System.out.print(c.getData());
//System.out.println(cell.getData());
max = c.getData().value;
max = c.getData();
count++;
}
}
Expand All @@ -84,10 +84,10 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
count = 0;
for (SkyscrapersCell c : col) {
System.out.println(c.getData());
if (c.getData().value > max) {
if (c.getData() > max) {

//System.out.println(cell.getData());
max = c.getData().value;
max = c.getData();
count++;
}
}
Expand All @@ -101,10 +101,10 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
Collections.reverse(col);
for (SkyscrapersCell c : col) {
System.out.println(c.getData());
if (c.getData().value > max) {
if (c.getData() > max) {

//System.out.println(cell.getData());
max = c.getData().value;
max = c.getData();
count++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,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.getWestClues().get(finalCell.getLocation().y), (Integer) finalCell.getData().value);
ArrayList<Board> YCandidates = caseRule.getCasesFor(initialBoard, initialBoard.getNorthClues().get(finalCell.getLocation().x), (Integer) finalCell.getData().value);
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 Expand Up @@ -77,7 +77,7 @@ private String candidateCheck(ArrayList<Board> candidates, PuzzleElement puzzleE

private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) {
SkyscrapersBoard emptyCase = board.copy();
emptyCase.getPuzzleElement(cell).setData(0);
emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value);
DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule();
if (duplicate.checkContradictionAt(emptyCase, cell) == null) {
System.out.println("no contradiction ln");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem

private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) {
SkyscrapersBoard emptyCase = board.copy();
emptyCase.getPuzzleElement(cell).setData(0);
emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value);
DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule();
if (duplicate.checkContradictionAt(emptyCase, cell) == null) {
System.out.println("no contradiction ln");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
initialBoard.setDupeFlag(false);
initialBoard.setViewFlag(true);
CellForNumberCaseRule caseRule = new CellForNumberCaseRule();
ArrayList<Board> XCandidates = caseRule.getCasesFor(initialBoard, initialBoard.getWestClues().get(finalCell.getLocation().y), (Integer) finalCell.getData().value);
ArrayList<Board> YCandidates = caseRule.getCasesFor(initialBoard, initialBoard.getNorthClues().get(finalCell.getLocation().x), (Integer) finalCell.getData().value);
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 Expand Up @@ -78,7 +78,7 @@ private String candidateCheck(ArrayList<Board> candidates, PuzzleElement puzzleE

private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) {
SkyscrapersBoard emptyCase = board.copy();
emptyCase.getPuzzleElement(cell).setData(0);
emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value);
DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule();
if (duplicate.checkContradictionAt(emptyCase, cell) == null) {
System.out.println("no contradiction ln");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem

private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) {
SkyscrapersBoard emptyCase = board.copy();
emptyCase.getPuzzleElement(cell).setData(0);
emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value);
DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule();
if (duplicate.checkContradictionAt(emptyCase, cell) == null) {
System.out.println("no contradiction ln");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class NEdgeDirectRule extends DirectRule {

public NEdgeDirectRule() {
super("SKYS-BASC-0004", "N Edge",
"If the maximum number appears on an edge, the row or column��s numbers appear in ascending order, starting at that edge.",
"If the maximum number appears on an edge, the row or column's numbers appear in ascending order, starting at that edge.",
"edu/rpi/legup/images/skyscrapers/rules/NEdge.png");
}

Expand All @@ -39,20 +39,20 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
}

SkyscrapersBoard emptyCase = initialBoard.copy();
emptyCase.getPuzzleElement(finalCell).setData(0);
emptyCase.getPuzzleElement(finalCell).setData(SkyscrapersType.UNKNOWN.value);
Point loc = finalCell.getLocation();
int max = initialBoard.getHeight();

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

Expand All @@ -62,7 +62,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem

private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) {
SkyscrapersBoard emptyCase = board.copy();
emptyCase.getPuzzleElement(cell).setData(0);
emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value);
DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule();
if (duplicate.checkContradictionAt(emptyCase, cell) == null) {
System.out.println("no contradiction ln");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
//don't do anything if already in row
boolean exists = false;
for (SkyscrapersCell c : temp.getRowCol(loc.y, SkyscrapersType.Number, true)) {
if (c.getData().value == num) {
if (c.getData() == num) {
exists = true;
break;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
//don't do anything if already in col
boolean exists = false;
for (SkyscrapersCell c : temp.getRowCol(loc.x, SkyscrapersType.Number, false)) {
if (c.getData().value == num) {
if (c.getData() == num) {
exists = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
//isn't already present
boolean exists = false;
for (SkyscrapersCell presentCell : skyscrapersBoard.getRowCol(loc.y, SkyscrapersType.Number, true)) {
if (presentCell.getData().value == num) {
if (presentCell.getData() == num) {
exists = true;
break;
}
Expand All @@ -59,7 +59,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
//same process as for row
exists = false;
for (SkyscrapersCell presentCell : skyscrapersBoard.getRowCol(loc.x, SkyscrapersType.Number, false)) {
if (presentCell.getData().value == num) {
if (presentCell.getData() == num) {
exists = true;
break;
}
Expand Down

0 comments on commit 9968640

Please sign in to comment.