Skip to content

Commit 42d92e7

Browse files
committed
Shift goal to be component of Puzzle
1 parent c9b4b07 commit 42d92e7

File tree

9 files changed

+88
-29
lines changed

9 files changed

+88
-29
lines changed

src/main/java/edu/rpi/legup/model/Goal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* which holds the type of cell and the cell's location. Goal's should only be constructed
1111
* twice; once upon loading the puzzle, and once upon saving the puzzle.
1212
* <p>
13-
* If the GoalType is NONE, cellList must be null.
13+
* If the GoalType is DEFAULT, cellList must be null.
1414
*/
1515
public class Goal {
1616
private ArrayList<GridCell> cellList;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Goal Condition
2+
3+
The 'goal' of a goal condition is to make LEGUP more similar to a formal logic proof.
4+
Currently, the win condition of a puzzle is to `find all possible solutions`, which is unlike
5+
the end goal of any formal proof. Instead, a puzzle should be validated when a goal condition is met,
6+
such as `Prove the cell at (1, 1) is White`.
7+
8+
This markdown document is meant to record how the goal condition is meant to work, any changes
9+
made to the repository to allow the goal condition to show up in the puzzle, be validated by
10+
the puzzle checker.
11+
12+
## Expected Functionality
13+
14+
When opening a puzzle, there should a sentence for what the goal of the proof is. The
15+
full goal statement `Prove the cell at (1, 1) is White` would be best. Additionally,
16+
the cell on the board should be highlighted in `Some color lol`. `The color` should not be
17+
by any other puzzles.
18+
19+
The `check proof` button should then reflect this goal condition when validating a proof.
20+
Depending on the goal, the checker needs to look for different things depending on the goal.
21+
22+
Currently, __all branches__ must either contain a full board or be closed by a contradition rule
23+
for the puzzle to be solved.
24+
25+
| Goal scope \ Task type | **Prove** | **Disprove** |
26+
|------------------------|--------------------------------------|--------------------------------------|
27+
| **Specific type** | - Prove cell value is as indicated | - Prove cell might not be indicated |
28+
| **Unknown type** | - Prove a cell must be a given value | - Prove a cell can be multiple types |
29+
30+
To prove a cell is as indicated, __all branches__ need to be valid and the cell must be as indicated.
31+
32+
To prove a cell might not be as indicated, only __one branch__ needs to be valid and the cell not as
33+
indicated for the puzzle to valid.
34+
35+
To prove a cell must be a given type, the same condition as proving a specific type holds.
36+
37+
To prove a cell might be multiple types, only __two valid branches__ need to exist, where the cell is
38+
a different type in each, for the puzzle to be valid.
39+
40+
### Goal Rule
41+
42+
We would also need a rule that corresponds to the goal. For example, we should be allowed to show
43+
by contradiction that a goal condition holds. If we want to `prove that cell (1, 1) is White`, we can
44+
show via contradiction that if (1,1) is white, the puzzle would be unsolvable. This type of puzzle solution
45+
should be valid.
46+
47+
I have no idea how to make this happen.
48+
49+
## Possible UI
50+
Puzzle Board:
51+
- Goal should be highlighted (in brown?) at all times
52+
- Hovering should specify exactly what the goal wants like how rule tooltips work
53+
- Different indicators for the different types of rules?
54+
- Goal text nearby the board (below?)
55+
- The goal text will be different for each goal type
56+
Puzzle Editor:
57+
- Default 'Goal' element highlight
58+
- Clicking on same cell cycles through goal types
59+
- Visual is curved arrow
60+
- Highlight is independent of cell type

src/main/java/edu/rpi/legup/model/Puzzle.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public abstract class Puzzle implements IBoardSubject, ITreeSubject {
4747
protected String tag = "";
4848
protected Board currentBoard;
4949
protected Tree tree;
50+
protected Goal goal;
5051
protected BoardView boardView;
5152
protected PuzzleImporter importer;
5253
protected PuzzleExporter exporter;
@@ -210,6 +211,25 @@ public boolean isValidTextInput(String[] statements) {
210211
return statements.length > 0;
211212
}
212213

214+
215+
/**
216+
* Sets the Goal of the board
217+
*
218+
* @param goal Goal to be set
219+
*/
220+
public void setGoal(Goal goal) {
221+
this.goal = goal;
222+
}
223+
224+
/**
225+
* Gets the Goal of the board
226+
*
227+
* @return Goal object
228+
*/
229+
public Goal getGoal() {
230+
return goal;
231+
}
232+
213233
/**
214234
* Determines if the edu.rpi.legup.puzzle was solves correctly
215235
*

src/main/java/edu/rpi/legup/model/gameboard/Board.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,6 @@ public void removeModifiedData(PuzzleElement data) {
147147
data.setModified(false);
148148
}
149149

150-
/**
151-
* Sets the Goal of the board
152-
*
153-
* @param goal Goal to be set
154-
*/
155-
public void setGoal(Goal goal) {
156-
this.goal = goal;
157-
}
158-
159-
/**
160-
* Gets the Goal of the board
161-
*
162-
* @return Goal object
163-
*/
164-
public Goal getGoal() {
165-
return goal;
166-
}
167-
168150
/**
169151
* Called when a {@link PuzzleElement} data on this has changed and passes in the equivalent
170152
* puzzle element with the new data.

src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public boolean isBoardComplete(Board board) {
6666
}
6767
}
6868

69-
Goal goal = board.getGoal();
69+
Goal goal = this.getGoal();
7070
return switch (goal.getType()) {
7171
case PROVE_CELL_MUST_BE -> // Every goal cell is forced
7272
checkGoalCells(nurikabeBoard, goal);

src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeBoard.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public NurikabeBoard copy() {
5252
copy.getPuzzleElement(e).setModifiable(false);
5353
}
5454

55-
copy.setGoal(this.goal);
5655
return copy;
5756
}
5857
}

src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public Goal importGoal(Node node, Board board) throws InvalidFileFormatException
6464

6565
NamedNodeMap attributeList = node.getAttributes();
6666
String goalTypeString = attributeList.getNamedItem("type").getNodeValue();
67-
GoalType goalType = goalTypeString == null ? GoalType.NONE : GoalType.valueOf(goalTypeString.toUpperCase());
67+
GoalType goalType = goalTypeString == null ? GoalType.DEFAULT : GoalType.valueOf(goalTypeString.toUpperCase());
6868

69-
if (goalType != GoalType.NONE) {
69+
if (goalType != GoalType.DEFAULT) {
7070
return new Goal(null, goalType);
7171
} else{
7272
return new Goal(null, goalType);

src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeExporter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
3232
boardElement.setAttribute("width", String.valueOf(board.getWidth()));
3333
boardElement.setAttribute("height", String.valueOf(board.getHeight()));
3434

35-
if (board.getGoal() != null && board.getGoal().getType() != GoalType.DEFAULT){
35+
if (puzzle.getGoal() != null && puzzle.getGoal().getType() != GoalType.DEFAULT){
3636
org.w3c.dom.Element goalElement = newDocument.createElement("goal");
37-
goalElement.setAttribute("type", String.valueOf(board.getGoal().getType()));
37+
goalElement.setAttribute("type", String.valueOf(puzzle.getGoal().getType()));
3838

39-
for (GridCell gridCell : board.getGoal().getCells()) {
39+
for (GridCell gridCell : puzzle.getGoal().getCells()) {
4040
NurikabeCell cell = (NurikabeCell) gridCell;
4141
if (cell.getData() != -2) {
4242
org.w3c.dom.Element cellElement =

src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,10 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
101101
.importCell(cellList.item(i), nurikabeBoard);
102102
goal.addCell(cell);
103103
}
104-
105-
nurikabeBoard.setGoal(goal);
106104
} else {
107105
Goal goal = new Goal(null, GoalType.DEFAULT);
108106

109-
nurikabeBoard.setGoal(goal);
107+
puzzle.setGoal(goal);
110108
}
111109

112110
Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0);

0 commit comments

Comments
 (0)