Skip to content

Commit

Permalink
Merge branch 'thermometer' into thermometer
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuzzabee authored Mar 14, 2024
2 parents 68fa815 + f37a834 commit 31ee7e6
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 0 deletions.
27 changes: 27 additions & 0 deletions puzzles files/thermometer/therm_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Legup version="5.1.0">
<puzzle name="Thermometer">
<board height="4" width="4">
<vials>
<vial headx="0" heady="0" tailx="2" taily="0"/>
<vial headx="3" heady="0" tailx="3" taily="3"/>
<vial headx="0" heady="1" tailx="1" taily="1"/>
<vial headx="2" heady="1" tailx="2" taily="3"/>
<vial headx="0" heady="3" tailx="0" taily="2"/>
<vial headx="1" heady="2" tailx="1" taily="3"/>
</vials>
<rowNumbers>
<row value="3"/>
<row value="2"/>
<row value="2"/>
<row value="2"/>
</rowNumbers>
<colNumbers>
<col value="2"/>
<col value="4"/>
<col value="2"/>
<col value="1"/>
</colNumbers>
</board>
</puzzle>
</Legup>
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public int getColNumber(int col){
return colNumbers.get(col);
}

// Accessors for saving row/column
public ArrayList<Integer> getRowNumbers() { return rowNumbers; }
public ArrayList<Integer> getColNumbers() { return colNumbers; }


@Override
public ThermometerCell getCell(int x, int y){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,62 @@

public class ThermometerExporter {
}

import java.util.ArrayList;

import edu.rpi.legup.model.PuzzleExporter;
import org.w3c.dom.Document;
import edu.rpi.legup.puzzle.thermometer.elements.Vial;

public class ThermometerExporter extends PuzzleExporter {

public ThermometerExporter(Thermometer thermometer) {
super(thermometer);
}

@Override
protected org.w3c.dom.Element createBoardElement(Document newDocument) {
ThermometerBoard board = (ThermometerBoard) puzzle.getTree().getRootNode().getBoard();

// Creating the XML section for the board
org.w3c.dom.Element boardElement = newDocument.createElement("board");
boardElement.setAttribute("width", String.valueOf(board.getWidth()));
boardElement.setAttribute("height", String.valueOf(board.getHeight()));

// Creating the XML section for the vials and appending to the board
org.w3c.dom.Element vialsElement = newDocument.createElement("vials");
ArrayList<Vial> vials = board.getVials();
for (Vial vial : vials) {
org.w3c.dom.Element vialElement = newDocument.createElement("vial");
// Temp for now, waiting on final implementation of vial
// vialElement.setAttribute("headx", vial.getHeadX());
// vialElement.setAttribute("heady", vial.getHeadY());
// vialElement.setAttribute("tailx", vial.getTailX());
// vialElement.setAttribute("taily", vial.getTailY());
vialsElement.appendChild(vialElement);
}
boardElement.appendChild(vialsElement);

// Creating the XML section for the row numbers and appending to the board
org.w3c.dom.Element rowNumbersElement = newDocument.createElement("rowNumbers");
ArrayList<Integer> rowNumbers = board.getRowNumbers();
for (int number : rowNumbers) {
org.w3c.dom.Element rowNumberElement = newDocument.createElement("row");
rowNumberElement.setAttribute("value", String.valueOf(number));
rowNumbersElement.appendChild(rowNumberElement);
}
boardElement.appendChild(rowNumbersElement);

// Creating the XML section for the col numbers and appending ot the board
org.w3c.dom.Element colNumbersElement = newDocument.createElement("colNumbers");
ArrayList<Integer> colNumbers = board.getColNumbers();
for (int number : colNumbers) {
org.w3c.dom.Element colNumberElement = newDocument.createElement("col");
colNumberElement.setAttribute("value", String.valueOf(number));
colNumbersElement.appendChild(colNumberElement);
}
boardElement.appendChild(colNumbersElement);

return boardElement;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package edu.rpi.legup.puzzle.thermometer.rules;

import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.DirectRule;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.thermometer.ThermometerBoard;

public class FinishColumnWithEmptyDirectRule extends DirectRule {

public FinishColumnWithEmptyDirectRule() {
super("FCE",
"Finish Column with Empty",
"When a column is filled with mercury equal to the corresponding edge number, the rest are blocked.",
"edu/rpi/legup/images/nurikabe/rules/FinishColumnWithEmpty.png");
}

/**
* Checks whether the child node logically follows from the parent node at the specific
* puzzleElement index using this rule
*
* @param transition transition to check
* @param puzzleElement equivalent puzzleElement
* @return null if the child node logically follow from the parent node at the specified
* puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
ThermometerBoard board = (ThermometerBoard) transition.getBoard();
ThermometerBoard origBoard = (ThermometerBoard) transition.getParents().get(0).getBoard();

// Grab the puzzleElement (Array of X'd cells? Or compare board to origBoard?)
// Get the column that is being changed
// Get the number of filled vials in the row
// If the number filled != number given, throw error

// All is well, valid
return null;
}

@Override
public Board getDefaultBoard(TreeNode node) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package edu.rpi.legup.puzzle.thermometer.rules;

import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.DirectRule;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.thermometer.ThermometerBoard;

public class FinishRowWithEmptyDirectRule extends DirectRule {

public FinishRowWithEmptyDirectRule() {
super("FRE",
"Finish Row with Empty",
"When a row is filled with mercury equal to the corresponding edge number, the rest are blocked.",
"edu/rpi/legup/images/nurikabe/rules/FinishRowWithEmpty.png");
}

/**
* Checks whether the child node logically follows from the parent node at the specific
* puzzleElement index using this rule
*
* @param transition transition to check
* @param puzzleElement equivalent puzzleElement
* @return null if the child node logically follow from the parent node at the specified
* puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
ThermometerBoard board = (ThermometerBoard) transition.getBoard();
ThermometerBoard origBoard = (ThermometerBoard) transition.getParents().get(0).getBoard();

// Grab the puzzleElement (Array of X'd cells? Or compare board to origBoard?)
// Get the row that is being changed
// Get the number of filled vials in the row
// If the number filled != number given, throw error

// All is well, valid
return null;
}

@Override
public Board getDefaultBoard(TreeNode node) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package edu.rpi.legup.puzzle.thermometer.rules;

import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.DirectRule;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.thermometer.ThermometerBoard;

public class RestIsEmptyDirectRule extends DirectRule {

public RestIsEmptyDirectRule() {
super("RIE",
"Rest Is Empty",
"If mercury is blocked at a non-tail section, the rest of the thermometer is also blocked.",
"edu/rpi/legup/images/nurikabe/rules/RestIsEmpty.png");
}

/**
* Checks whether the child node logically follows from the parent node at the specific
* puzzleElement index using this rule
*
* @param transition transition to check
* @param puzzleElement equivalent puzzleElement
* @return null if the child node logically follow from the parent node at the specified
* puzzleElement, otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
ThermometerBoard board = (ThermometerBoard) transition.getBoard();
ThermometerBoard origBoard = (ThermometerBoard) transition.getParents().get(0).getBoard();

// Grab the puzzleElement (Array of X'd cells? Or compare board to origBoard?)
// Ensure we only X'd a single vial, else return error
// Find the closest cell to the head of the vial
// If vertical, check to ensure # of filled cells in that row = outside #, else return error
// If horizontal, check to ensure # of filled cells in that column = outside #, else return error
// Make sure every vial from the closest to head cell to the tail is X'd, else return error

// All is well, valid
return null;
}

@Override
public Board getDefaultBoard(TreeNode node) {
return null;
}
}

0 comments on commit 31ee7e6

Please sign in to comment.