diff --git a/bin/main/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md b/bin/main/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md index 94ef1e214..4695f25f2 100644 --- a/bin/main/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md +++ b/bin/main/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md @@ -11,7 +11,7 @@ spreadsheet : https://docs.google.com/spreadsheets/d/1l7aUZtavtysM8dtGnaEIXhBKMR 4. Refactoring: - document utility functions in the reference sheet, COMMENTS! - review and identify dead code - - remove all these damn print statments (commented ones too if they aren't useful) + - remove all these damn print statements (commented ones too if they aren't useful) - Edit to allow blank clues - Display flags somewhere 5. Flags diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java index d084cd2ff..e5011182a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java @@ -4,6 +4,7 @@ import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.puzzle.lightup.LightUpCell; import edu.rpi.legup.puzzle.shorttruthtable.*; import java.awt.*; @@ -42,6 +43,11 @@ public ShortTruthTableCell getCellFromElement(PuzzleElement element) { return (ShortTruthTableCell) getPuzzleElement(element); } + @Override + public ShortTruthTableCell getCell(int x, int y) { + return (ShortTruthTableCell) super.getCell(x, y); + } + @Override public ShortTruthTableBoard copy() { @@ -93,6 +99,17 @@ public static List copyStatementList(List getCells(String statement, int y) { * @param statements returns all the statements * @return the length, in chars, of the longest statement */ - private int parseAllStatmentsAndCells(final NodeList statementData, + private int parseAllStatementsAndCells(final NodeList statementData, List> allCells, List statements) throws InvalidFileFormatException { @@ -167,7 +167,7 @@ private ShortTruthTableBoard generateBoard(List> allCe //get the cell at this location; or create a not_in_play one if necessary ShortTruthTableCell cell = null; - //for a cell to exist at (x, y), it must be a valid row and within the statment length + //for a cell to exist at (x, y), it must be a valid row and within the statement length if (y % 2 == 0 && x < statements.get(statementIndex).getLength()) { cell = allCells.get(statementIndex).get(x); System.out.println("Importer: check cell statement ref: " + cell.getStatementReference()); @@ -195,7 +195,7 @@ private void setGivenCells(ShortTruthTableBoard sttBoard, List statements) throws InvalidFileFormatException { - //if it is normal, set all predicats to true and the conclusion to false + //if it is normal, set all predicates to true and the conclusion to false if (dataElement.getAttribute("normal").equalsIgnoreCase("true")) { //set all predicates to true (all but the last one) for (int i = 0; i < statements.size() - 1; i++) { @@ -264,7 +264,7 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { //Parse the data - int maxStatementLength = parseAllStatmentsAndCells(statementData, allCells, statements); + int maxStatementLength = parseAllStatementsAndCells(statementData, allCells, statements); //generate the board ShortTruthTableBoard sttBoard = generateBoard(allCells, statements, maxStatementLength); diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableStatement.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableStatement.java index bb0ffcf08..e40a10cf0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableStatement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableStatement.java @@ -95,7 +95,7 @@ static String removeParens(String statement) { if (c == ')') openParenCount--; } - //if the first paren has been closed and it is not the end of the string, + //if the first paren has been closed, and it is not the end of the string, //then there is no whole statement parens to remove if (openParenCount == 0 && i != statement.length() - 1) { return statement; @@ -164,7 +164,7 @@ static void removeParens(List cells) { if (c == ')') openParenCount--; } - //if the first paren has been closed and it is not the end of the string, + //if the first paren has been closed, and it is not the end of the string, //then there is no whole statement parens to remove if (openParenCount == 0 && i != cells.size() - 1) { return; @@ -241,7 +241,7 @@ public Set getCellsWithSymbol(char symbol) { * Returns an array of three elements where [0] is the left * statement type, [1] is this statement type, and [2] is the * right statement type. null means either the statement doesn't - * exist or is is an unknown value. + * exist or is an unknown value. * * @return the assigned values to this statement and its sub-statements */ @@ -285,14 +285,29 @@ public void setCellLocations(int rowIndex) { public ShortTruthTableStatement copy() { //copy all the cells - List cellsCopy = new ArrayList(); + List cellsCopy = new ArrayList<>(); for (ShortTruthTableCell c : cells) { cellsCopy.add(c.copy()); } //make a copy of the statement with all the copied cells - ShortTruthTableStatement statementCopy = new ShortTruthTableStatement(stringRep, cellsCopy); //return the new statement - return statementCopy; + return new ShortTruthTableStatement(stringRep, cellsCopy); + } + + public ShortTruthTableStatement replace(int column, ShortTruthTableCell cell) { + //copy all the cells (replacing one) + List cellsCopy = new ArrayList<>(); + for (ShortTruthTableCell c : cells) { + if (c.getX() == column) { + cellsCopy.add(cell); + } + else { + cellsCopy.add(c); + } + } + //make a copy of the statement with all the copied cells + //return the new statement + return new ShortTruthTableStatement(stringRep, cellsCopy); } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md index d0be95913..60a8bd19d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md @@ -11,7 +11,7 @@ spreadsheet : https://docs.google.com/spreadsheets/d/1l7aUZtavtysM8dtGnaEIXhBKMR 4. Refactoring: - document utility functions in the reference sheet, COMMENTS! - review and identify dead code - - remove all these damn print statments (commented ones too if they aren't useful) + - remove all these damn print statements (commented ones too if they aren't useful) - Edit to allow blank clues - Display flags somewhere 5. Flags