Skip to content

Commit

Permalink
Revert "Bugfix 549 (#682)"
Browse files Browse the repository at this point in the history
This reverts commit 5048ee6.
  • Loading branch information
Chase-Grajeda committed Jan 26, 2024
1 parent 5048ee6 commit e9fe310
Show file tree
Hide file tree
Showing 18 changed files with 994 additions and 1,354 deletions.
31 changes: 31 additions & 0 deletions puzzles files/skyscrapers/1646651
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Legup version="2.0.0">
<puzzle name="Skyscrapers">
<board height="8" width="8">
<cells>

</cells>
<axis side="east">
<clue index="5" value="3"/>
<clue index="2" value="0"/>
<clue index="1" value="2"/>
<clue index="4" value="1"/>
<clue index="5" value="2"/>
<clue index="6" value="1"/>
<clue index="7" value="1"/>
<clue index="8" value="2"/>
</axis>
<axis side="south">
<clue index="1" value="3"/>
<clue index="2" value="0"/>
<clue index="3" value="2"/>
<clue index="3" value="1"/>
<clue index="5" value="2"/>
<clue index="0" value="1"/>
<clue index="7" value="1"/>
<clue index="4" value="2"/>
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
47 changes: 47 additions & 0 deletions puzzles files/skyscrapers/easy1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!-- https://www.brainbashers.com/showskyscraper.asp?date=1014&size=4&diff=1 -->
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Legup version="2.0.0">
<puzzle name="Skyscrapers">
<board height="4" width="4">
<!-- cells begin empty -->
<cells>
</cells>
<!-- hints to display on side -->
<!-- read top-down left-right -->
<axis side="north">
<clue index="1" value="4"/>
<clue index="2" value="2"/>
<clue index="3" value="1"/>
<clue index="4" value="2"/>
</axis>
<axis side="south">
<clue index="1" value="1"/>
<clue index="2" value="2"/>
<clue index="3" value="4"/>
<clue index="4" value="2"/>
</axis>
<axis side="east">
<clue index="1" value="2"/>
<clue index="2" value="1"/>
<clue index="3" value="3"/>
<clue index="4" value="3"/>
</axis>
<axis side="west">
<clue index="1" value="3"/>
<clue index="2" value="3"/>
<clue index="3" value="2"/>
<clue index="4" value="1"/>
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
<!--
Clues layed out:
4 2 1 2
3 2
3 1
2 3
1 3
1 2 4 2
-->
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public void executeCommand() {
board.setModifiable(false);
transition.setBoard(board);
transition.setRule(caseRule);
transition.setSelection(elementView.getPuzzleElement().copy());
caseTrans.add(transition);

TreeNode childNode = (TreeNode) tree.addTreeElement(transition);
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public abstract class PuzzleElement<T> {
protected boolean isModified;
protected boolean isGiven;
protected boolean isValid;
protected int casesDepended;

/**
* PuzzleElement Constructor creates a new puzzle element.
Expand All @@ -23,7 +22,6 @@ public PuzzleElement() {
this.isModified = false;
this.isGiven = false;
this.isValid = true;
this.casesDepended = 0;
}

/**
Expand Down Expand Up @@ -150,24 +148,6 @@ public void setValid(boolean isValid) {
this.isValid = isValid;
}

/**
* Get the number of case rules that depend upon the state of this element
*
* @return number of cases
*/
public int getCasesDepended() {
return this.casesDepended;
}

/**
* Sets the number of case rules that depend upon the state of this element
*
* @param cases number of cases
*/
public void setCasesDepended(int cases) {
this.casesDepended = cases;
}

/**
* Tests whether two puzzle elements objects have the same puzzle element
*
Expand Down
29 changes: 2 additions & 27 deletions src/main/java/edu/rpi/legup/model/rules/CaseRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import edu.rpi.legup.model.tree.TreeTransition;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.Map;

import static edu.rpi.legup.model.rules.RuleType.CASE;

Expand Down Expand Up @@ -78,7 +79,6 @@ public String checkRule(TreeTransition transition) {

String check = checkRuleRaw(transition);

// Mark transition and new data as valid or not
boolean isCorrect = (check == null);
for (TreeTransition childTrans : parentNodes.get(0).getChildren()) {
childTrans.setCorrect(isCorrect);
Expand Down Expand Up @@ -125,31 +125,6 @@ public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement
*/
@Override
public abstract String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement);

/**
* Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid
* Overridden by case rules dependent on more than just the modified data
*
* @param board board state at application
* @param puzzleElement selected puzzleElement
* @return List of puzzle elements (typically cells) this application of the case rule depends upon.
* Defaults to any element modified by any case
*/
public List<PuzzleElement> dependentElements(Board board, PuzzleElement puzzleElement) {
List<PuzzleElement> elements = new ArrayList<>();

List<Board> cases = getCases(board,puzzleElement);
for (Board caseBoard : cases) {
Set<PuzzleElement> data = caseBoard.getModifiedData();
for (PuzzleElement element : data) {
if(!elements.contains(board.getPuzzleElement(element))){
elements.add(board.getPuzzleElement(element));
}
}
}

return elements;
}
}


4 changes: 0 additions & 4 deletions src/main/java/edu/rpi/legup/model/rules/DirectRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ public String checkRule(TreeTransition transition) {
transition.getParents().get(0).getChildren().size() != 1) {
return "State must have only 1 parent and 1 child";
}
else if (finalBoard.getModifiedData().isEmpty()) {
// null transition
return null;
}
else {
return checkRuleRaw(transition);
}
Expand Down
64 changes: 5 additions & 59 deletions src/main/java/edu/rpi/legup/model/tree/TreeTransition.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.rules.Rule;
import edu.rpi.legup.model.rules.RuleType;

Expand All @@ -13,8 +12,6 @@ public class TreeTransition extends TreeElement {
private ArrayList<TreeNode> parents;
private TreeNode childNode;
private Rule rule;

private PuzzleElement selection;
private boolean isCorrect;
private boolean isVerified;

Expand All @@ -29,7 +26,6 @@ public TreeTransition(Board board) {
this.childNode = null;
this.board = board;
this.rule = null;
this.selection = null;
this.isCorrect = false;
this.isVerified = false;
}
Expand Down Expand Up @@ -91,42 +87,13 @@ public void propagateChange(PuzzleElement element) {
}
}
else {
// Overwrite previous modifications to this element
board.removeModifiedData(board.getPuzzleElement(element));

// apply changes to tranistion
board.notifyChange(element);

// mark first transition as modified
if (!board.getPuzzleElement(element).equalsData(parents.get(0).getBoard().getPuzzleElement(element))) {
board.addModifiedData(element);
}

// propagate to children
if (childNode != null) {

// find starting board
TreeNode head = childNode;
while (head.getParent() != null) {
head = head.getParent().getParents().get(0);
}
Board headBoard = head.getBoard();

PuzzleElement copy = element.copy();
// Set as modifiable if reverted to starting value (and started modifiable)
if (headBoard.getPuzzleElement(element).equalsData(element)) {
copy.setModifiable(headBoard.getPuzzleElement(element).isModifiable());
}
else{
copy.setModifiable(false);
}

// apply changes to result node
childNode.getBoard().notifyChange(copy);

// apply to all child transitions
board.notifyChange(element);
childNode.getBoard().notifyChange(element.copy());
for (TreeTransition child : childNode.getChildren()) {
child.propagateChange(copy.copy());
PuzzleElement copy = element.copy();
copy.setModifiable(false);
child.propagateChange(copy);
}
}
}
Expand Down Expand Up @@ -360,27 +327,6 @@ public void setRule(Rule rule) {
isVerified = false;
}

/**
* Gets he selected element associated with this transition
*
* @return If this is a case rule, the selected element for that rule, null otherwise
*/
public PuzzleElement getSelection() {
if (this.rule instanceof CaseRule) {
return selection;
}
return null;
}

/**
* Sets the selected element associated with this transition
*
* @param selection selected element for this transition
*/
public void setSelection(PuzzleElement selection) {
this.selection = selection;
}

/**
* Gets whether this transition is correctly justified
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,67 +287,4 @@ private List<LightUpCell> getAdjacentCells(LightUpBoard board, LightUpCell cell)
}
return cells;
}

/**
* Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid
* Overridden by case rules dependent on more than just the modified data
*
* @param board board state at application
* @param puzzleElement selected puzzleElement
* @return List of puzzle elements (typically cells) this application of the case rule depends upon.
* Defaults to any element modified by any case
*/
@Override
public List<PuzzleElement> dependentElements(Board board, PuzzleElement puzzleElement) {
List<PuzzleElement> elements = new ArrayList<>();

LightUpBoard puzzleBoard = (LightUpBoard) board;
LightUpCell point = (LightUpCell)puzzleBoard.getPuzzleElement(puzzleElement);

List<LightUpCell> cells = getAdjacentCells(puzzleBoard,point);

for (LightUpCell cell : cells) {
//add cells that can light adjacents from any direction
Point location = cell.getLocation();
for (int i = location.x; i < puzzleBoard.getWidth(); i++) {
System.out.println(i);
LightUpCell c = puzzleBoard.getCell(i, location.y);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
}
else if (!elements.contains(board.getPuzzleElement(c))) {
elements.add(board.getPuzzleElement(c));
}
}
for (int i = location.x; i >= 0; i--) {
LightUpCell c = puzzleBoard.getCell(i, location.y);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
}
else if (!elements.contains(board.getPuzzleElement(c))) {
elements.add(board.getPuzzleElement(c));
}
}
for (int i = location.y; i < puzzleBoard.getHeight(); i++) {
LightUpCell c = puzzleBoard.getCell(location.x, i);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
}
else if (!elements.contains(board.getPuzzleElement(c))) {
elements.add(board.getPuzzleElement(c));
}
}
for (int i = location.y; i >= 0; i--) {
LightUpCell c = puzzleBoard.getCell(location.x, i);
if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) {
break;
}
else if (!elements.contains(board.getPuzzleElement(c))) {
elements.add(board.getPuzzleElement(c));
}
}
}

return elements;
}
}
Loading

0 comments on commit e9fe310

Please sign in to comment.