Skip to content

Commit

Permalink
Merge branch 'dev' into file-path
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram28 authored Jun 23, 2023
2 parents 886ea3d + 0ca6926 commit c8cbc44
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bin/main/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -93,6 +99,17 @@ public static List<ShortTruthTableStatement> copyStatementList(List<ShortTruthTa
// cell.setType(cellElement.getType());
// }

@Override
public void notifyChange(PuzzleElement puzzleElement) {
ShortTruthTableCell cell = (ShortTruthTableCell) puzzleElement;
int r = cell.getY();
int c = cell.getX();
if (r % 2 == 0 && c < statements[r / 2].getLength()) {
statements[r / 2] = statements[r / 2].replace(c, cell);
setCell(c, r, statements[r / 2].getCell(c));
}
super.notifyChange(cell);
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ShortTruthTableImporter(ShortTruthTable stt) {


/**
* Parse a string into all te cells, the y position of the statement is passed so the y position can be set
* Parse a string into all the cells, the y position of the statement is passed so the y position can be set
*
* @param statement
* @param y
Expand Down Expand Up @@ -54,7 +54,7 @@ private List<ShortTruthTableCell> 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<List<ShortTruthTableCell>> allCells,
List<ShortTruthTableStatement> statements) throws InvalidFileFormatException {

Expand Down Expand Up @@ -167,7 +167,7 @@ private ShortTruthTableBoard generateBoard(List<List<ShortTruthTableCell>> 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());
Expand Down Expand Up @@ -195,7 +195,7 @@ private void setGivenCells(ShortTruthTableBoard sttBoard,
List<ShortTruthTableStatement> 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++) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -164,7 +164,7 @@ static void removeParens(List<ShortTruthTableCell> 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;
Expand Down Expand Up @@ -241,7 +241,7 @@ public Set<ShortTruthTableCell> 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
*/
Expand Down Expand Up @@ -285,14 +285,29 @@ public void setCellLocations(int rowIndex) {

public ShortTruthTableStatement copy() {
//copy all the cells
List<ShortTruthTableCell> cellsCopy = new ArrayList<ShortTruthTableCell>();
List<ShortTruthTableCell> 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<ShortTruthTableCell> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c8cbc44

Please sign in to comment.