forked from Bram-Hub/LEGUP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thermometer Importer Functionality + Thermometer Puzzle Factory (Bram…
…-Hub#756) (#1) * Fixed Short Truth Table case rule bug (Bram-Hub#707) * Revert "Bugfix 549 (Bram-Hub#682)" This reverts commit 5048ee6. * Case rule test fix (Bram-Hub#705) * Rapid fix for STT case rules Case rules broke at some point from legacy code or merge conflict. Provided is a quick fix in CaseRule and CaseRule_Generic * Revert "Revert "Bugfix 549 (Bram-Hub#682)"" (Bram-Hub#706) This reverts commit e9fe310. --------- * Starting work on thermometer class * Added Vial Class Added the vial class which will be helpful for checking rules down the line * Discontinuous Mercury Rule added Added the Discontinuous Mercury contradiciton rule. Added variables to the ThermometerBoard class to keep track of the numbers on the perimiter of the board as well as accessors/setters for these variables. Rewrote a section of the Vials code to make sure cells are added correctly as well as added some accessor functions. * Importer written First draft of the importer written and setData refactored * small bug fixes * Added Puzzle Factory and Importer Refactored a bunch of code so we now (in theory) import correctly --------- Co-authored-by: ZevCe <[email protected]> Co-authored-by: Charles Tian <[email protected]> Co-authored-by: Chase-Grajeda <[email protected]> Co-authored-by: Chase Grajeda <[email protected]>
- Loading branch information
1 parent
f37a834
commit bcfd6db
Showing
8 changed files
with
243 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerImporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package edu.rpi.legup.puzzle.thermometer; | ||
|
||
import edu.rpi.legup.model.PuzzleImporter; | ||
import edu.rpi.legup.puzzle.thermometer.ThermometerVialFactory; | ||
import edu.rpi.legup.save.InvalidFileFormatException; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
import java.awt.*; | ||
|
||
public class ThermometerImporter extends PuzzleImporter { | ||
public ThermometerImporter(Thermometer thermometer) { | ||
super(thermometer); | ||
} | ||
|
||
@Override | ||
public boolean acceptsRowsAndColumnsInput() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean acceptsTextInput() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void initializeBoard(int rows, int columns) { | ||
|
||
} | ||
|
||
@Override | ||
public void initializeBoard(Node node) throws InvalidFileFormatException { | ||
try { | ||
if (!node.getNodeName().equalsIgnoreCase("board")) { | ||
throw new InvalidFileFormatException("thermometer Importer: cannot find board puzzleElement"); | ||
} | ||
Element boardElement = (Element) node; | ||
if (boardElement.getElementsByTagName("vials").getLength() == 0) { | ||
throw new InvalidFileFormatException("thermometer Importer: no puzzleElement found for board"); | ||
} | ||
Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0); | ||
NodeList elementDataList = dataElement.getElementsByTagName("cell"); | ||
|
||
ThermometerBoard thermometerBoard = null; | ||
if (!boardElement.getAttribute("size").isEmpty()) { | ||
int size = Integer.parseInt(boardElement.getAttribute("size")); | ||
thermometerBoard = new ThermometerBoard(size); | ||
if (boardElement.getElementsByTagName("rowNumbers").getLength() != size) { | ||
throw new InvalidFileFormatException("thermometer Importer: no rowNumbers found for board"); | ||
} | ||
if (boardElement.getElementsByTagName("colNumbers").getLength() != size) { | ||
throw new InvalidFileFormatException("thermometer Importer: no colNumbers found for board"); | ||
} | ||
} else if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { | ||
int width = Integer.parseInt(boardElement.getAttribute("width")); | ||
int height = Integer.parseInt(boardElement.getAttribute("height")); | ||
if (boardElement.getElementsByTagName("colNumbers").getLength() != width) { | ||
throw new InvalidFileFormatException("thermometer Importer: no colNumbers found for board"); | ||
} | ||
if (boardElement.getElementsByTagName("rowNumbers").getLength() != height) { | ||
throw new InvalidFileFormatException("thermometer Importer: no rowNumbers found for board"); | ||
} | ||
//TODO: potentially have to deal with size issues and non interactable cells | ||
thermometerBoard = new ThermometerBoard(width, height); | ||
} | ||
|
||
if (thermometerBoard == null) { | ||
throw new InvalidFileFormatException("thermometer Importer: invalid board dimensions"); | ||
} | ||
|
||
int width = thermometerBoard.getWidth(); | ||
int height = thermometerBoard.getHeight(); | ||
|
||
for (int i = 0; i < elementDataList.getLength(); i++) { | ||
ThermometerVialFactory.importThermometerVial(elementDataList.item(i), thermometerBoard); | ||
} | ||
|
||
//verifying all vials were used | ||
for (int y = 0; y < height; y++) { | ||
for (int x = 0; x < width; x++) { | ||
if (thermometerBoard.getCell(x, y) == null) { | ||
throw new InvalidFileFormatException("thermometer Importer: invalid puzzle, unused tiles"); | ||
} | ||
} | ||
} | ||
|
||
puzzle.setCurrentBoard(thermometerBoard); | ||
} catch (NumberFormatException e) { | ||
throw new InvalidFileFormatException("thermometer Importer: unknown value where integer expected"); | ||
} | ||
} | ||
|
||
@Override | ||
public void initializeBoard(String[] statements) throws UnsupportedOperationException, IllegalArgumentException { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.