Skip to content

Commit

Permalink
October Merge (#636)
Browse files Browse the repository at this point in the history
* Region Based Changes (#559)

Co-authored-by: Hanson Gu <[email protected]>

* Short Truth Table Puzzle Editor (#451)

* Created files for STT elements

* Renamed Tiles classes to Elements to match package name

Also added an elements reference sheet and renamed rules reference sheet accordingly

* More progress made

This won't compile, just saving progress made

* More progress being made

* Fixed file name typo and added placeholder tiles

* Added image paths

* Created element classes and added placeholder tile images (#452)

* Renamed Tiles classes to Elements to match package name

Also added an elements reference sheet and renamed rules reference sheet accordingly

* More progress made

This won't compile, just saving progress made

* More progress being made

* Fixed file name typo and added placeholder tiles

* Added image paths

* Set the current board on boardView

* Fixed typo and turned on STT puzzle editor for testing

* Added preliminary valid dimensions checker

This will most definitely change in the future, hopefully can change to accept a number of statements

* Fixed image file paths

* Added ActionListener

Allows us to determine what puzzle is selected by the user

* Hide rows and columns input for Short Truth Table

* Added text area for Short Truth Table

* Added scrollbars to show up as needed

* Reformatted code

* More code reformatting

* Even more reformatting

* Separate the data from the TextArea into different lines

* Did some researching/testing

Tested certain variable values with a STT file with no true/false values

* Made more progress

Added new methods to handle creating Short Truth Table boards from an array of strings

* Added a bunch of TODOs

- Implemented a couple functions to be used later
- Added a bunch of TODO comments for future work

* Made some more progress

* Implemented abstract methods from PuzzleImporter

* Added abstract methods to Fillapix and added other exception reporting

* CheckStyle formatting

* Removed a TODO comment

* Statements show up in puzzle editor

Fixed a bug where the importer was not properly being initialized. Statements now show up in the puzzle editor.

* Removed empty statements

* Changed InvalidFormatException to IllegalArgumentException

* Remove argument that has already been caught

* Removed elements that will not be used

* Added puzzle editor cell clicking functionality

* Added ability to toggle certain logical elements

* New icons and more functionality implemented

* Fixed a bug where spacer rows could be modified

* Added statement error checking

* Fixed formatting

* Only one logic symbol element needed

* Changed InputMismatchException to UnsupportedOperationException

* Renamed variables to not be STT specific

* Finding initial issue and starting fix

* Issue is statement copying and modifying

* STT exporter now working. Overrode setCell for STTBoard.

* Added code documentation

* removed testing println()

* Gradle fixes

* Revert "Merge pull request #545 from MMosley502/puzzle_editor-short_truth_table-file_saving"

This reverts commit 2e82547, reversing
changes made to beb60a2.

* Saving files now works

* Fixed the blank element to be categorized as a placeable element

* Fixed a bug where file wouldn't save due to batch grader updates

* Reformatted code in STT

* Reformatted code again

* MORE REFORMATTING

Pls like my code CheckStyle

---------

Co-authored-by: Matthew Mosley <[email protected]>
Co-authored-by: MMosley502 <[email protected]>

* Have null changes be valid and fix IsolatedBlackContradicitonRule error message (#561)

* Get Tests to be called

Revert "Create first cypress test template"

This reverts commit 3e50909.

First commit

Finish Lightup tests

* Add more tests

Update TestRunner.java

* Somehow ended up in the wrong spot

Fix Import

* Please let this be the fix

Update TreeTransition.java

Update TreeTransition.java

Update DirectRule.java

Check to see which is not correct

Update ElementController.java

Revert "maybe the null is making it think that it's not valid"

This reverts commit 7bf1de0d66ced6749ee37fbb9c252636b2fcdc79.

Just trying to change color

Revert "Just trying to change color"

This reverts commit ec44695ee578d664055d135a668927a0fd900f5d.

Revert "maybe the null is making it think that it's not valid"

This reverts commit 3f162fbdc32e6fbd23da321a14a6af96f0ff520d.

Check to see which is not correct

Revert "Check to see which is not correct"

This reverts commit 136b0a41b9d103e6f3e9a7f8cd5d970bf76b050b.

Update TreeTransition.java

Update TreeTransition.java

Revert "Update TreeTransition.java"

This reverts commit cde45bb9001cfbfa4f6e2a49b4e9990d2fa7ad33.

* Fix error with isolated Black

Fix error message with isolated black

* Removed excess whitespace and imports. Added short JavaDoc for `TestRunner.java`

---------

Co-authored-by: Charles Tian <[email protected]>
Co-authored-by: Bram van Heuveln <[email protected]>
Co-authored-by: Corppet <[email protected]>

* Fixed a bug

* Update BlackTile.java

Black tile should not be placeable

* Added unknown tile stuff

* ID error

* Some Fixes to Recently Discussed UX Bugs (#563)

* frame and panels default sizes, default pos on screen

* hardcoded version number

* homepanel default size

* set panels' own sizes

* some changes

* Removed unused import

---------

Co-authored-by: Charles Tian <[email protected]>
Co-authored-by: Corppet <[email protected]>

* Oops pushed the wrong file

Yeah some tiles work now but this is the ID error

* Number Tile working

* Update Exporter (#627)

* Update Exporter

* Delete Test_Save

---------

Co-authored-by: Charles Tian <[email protected]>

* Create run-tests.yml

* Update run-tests.yml

* Update run-tests.yml

* Update run-tests.yml

* Update run-tests.yml

* Windows things

* Added print messages

* More Windows things

* Debugging

* Update run-tests.yml

* Update run-tests.yml

* Maybe this will work now?

* Didn't work

* Update run-tests.yml

* Update run-tests.yml

* Create DummyTest.java

For debugging purposes

* Added another dummy test

* Update run-tests.yml

* Update run-tests.yml

Get rid of all this info

* Deleted the dummy tests

---------

Co-authored-by: Antonio Orta <[email protected]>
Co-authored-by: Hanson Gu <[email protected]>
Co-authored-by: Charles Tian <[email protected]>
Co-authored-by: Matthew Mosley <[email protected]>
Co-authored-by: MMosley502 <[email protected]>
Co-authored-by: Viane Matsibekker <[email protected]>
Co-authored-by: Bram van Heuveln <[email protected]>
Co-authored-by: Corppet <[email protected]>
Co-authored-by: charlestian23 <[email protected]>
Co-authored-by: ThisMatt <[email protected]>
  • Loading branch information
11 people authored Oct 10, 2023
1 parent 12eb296 commit 7aba3f3
Show file tree
Hide file tree
Showing 61 changed files with 915 additions and 101 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Run JUnit Tests

on:
push:
branches:
- master
- dev
pull_request:
branches:
- master
- dev

jobs:
ubuntu-test:
runs-on: ubuntu-latest

steps:
- name: Check Out Code
uses: actions/checkout@v2

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build -x test

- name: Run JUnit Tests on Linux
run: |
./gradlew test
test-macos:
runs-on: macos-latest

steps:
- name: Check Out Code
uses: actions/checkout@v2

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build -x test

- name: Run JUnit Tests on macOS
run: |
./gradlew test
test-windows:
runs-on: windows-latest

steps:
- name: Check Out Code
uses: actions/checkout@v2

- name: Set up JDK and Gradle on Windows
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'adopt'

- name: Run JUnit Tests on Windows
run: |
.\gradlew.bat test
2 changes: 1 addition & 1 deletion bin/main/edu/rpi/legup/legup/config
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<puzzle name="ShortTruthTable"
qualifiedClassName="edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTable"
fileType=".xml"
fileCreationDisabled="true"/>
fileCreationDisabled="false"/>
<puzzle name="Sudoku" qualifiedClassName="edu.rpi.legup.puzzle.sudoku.Sudoku"
fileType=".xml"
fileCreationDisabled="true"/>
Expand Down
14 changes: 14 additions & 0 deletions puzzles files/shorttruthtable/empty_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Legup version="2.0.0">
<puzzle name="ShortTruthTable">
<board>
<data>
<statement representation="A>(B^C)" row_index="0"/>
<statement representation="C-B" row_index="1"/>
<statement representation="~C" row_index="2"/>
<statement representation="~A" row_index="3"/>
</data>
</board>
</puzzle>
<Solved isSolved="false"/>
</Legup>
84 changes: 76 additions & 8 deletions src/main/java/edu/rpi/legup/app/GameBoardFacade.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package edu.rpi.legup.app;

import edu.rpi.legup.history.History;
import edu.rpi.legup.history.IHistoryListener;
import edu.rpi.legup.history.IHistorySubject;
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.PuzzleImporter;
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.tree.Tree;
import edu.rpi.legup.save.InvalidFileFormatException;
import edu.rpi.legup.ui.LegupUI;
import edu.rpi.legup.ui.ProofEditorPanel;
import edu.rpi.legup.ui.PuzzleEditorPanel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import edu.rpi.legup.save.InvalidFileFormatException;
import edu.rpi.legup.ui.LegupUI;
import edu.rpi.legup.history.History;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -144,6 +143,30 @@ public boolean validateDimensions(String game, int rows, int columns) throws Run
}
}

/**
* Validates the given text input for the given puzzle
*
* @param game the name of the puzzle
* @param statements an array of statements
* @return true if it is possible to create a board for the given game with the given statements,
* false otherwise
* @throws RuntimeException if any of the input is invalid
*/
public boolean validateTextInput(String game, String[] statements) throws RuntimeException {
String qualifiedClassName = config.getPuzzleClassForName(game);
try {
Class<?> c = Class.forName(qualifiedClassName);
Constructor<?> constructor = c.getConstructor();
Puzzle puzzle = (Puzzle) constructor.newInstance();
return puzzle.isValidTextInput(statements);
}
catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException |
InstantiationException e) {
LOGGER.error(e);
throw new RuntimeException("Error validating puzzle text input");
}
}

/**
* Loads an empty puzzle
*
Expand All @@ -159,14 +182,20 @@ public void loadPuzzle(String game, int rows, int columns) throws RuntimeExcepti
Class<?> c = Class.forName(qualifiedClassName);
Constructor<?> cons = c.getConstructor();
Puzzle puzzle = (Puzzle) cons.newInstance();
setWindowTitle(puzzle.getName(), "New " + puzzle.getName() + " Puzzle");

PuzzleImporter importer = puzzle.getImporter();
if (importer == null) {
LOGGER.error("Puzzle importer is null");
throw new RuntimeException("Puzzle importer null");
}

// Theoretically, this exception should never be thrown, since LEGUP should not be
// allowing the user to give row/column input for a puzzle that doesn't support it
if (!importer.acceptsRowsAndColumnsInput()) {
throw new IllegalArgumentException(puzzle.getName() + " does not accept rows and columns input");
}

setWindowTitle(puzzle.getName(), "New " + puzzle.getName() + " Puzzle");
importer.initializePuzzle(rows, columns);

puzzle.initializeView();
Expand All @@ -183,6 +212,45 @@ public void loadPuzzle(String game, int rows, int columns) throws RuntimeExcepti
}
}

public void loadPuzzle(String game, String[] statements) {
String qualifiedClassName = config.getPuzzleClassForName(game);
LOGGER.debug("Loading " + qualifiedClassName);

try {
Class<?> c = Class.forName(qualifiedClassName);
Constructor<?> cons = c.getConstructor();
Puzzle puzzle = (Puzzle) cons.newInstance();

PuzzleImporter importer = puzzle.getImporter();
if (importer == null) {
LOGGER.error("Puzzle importer is null");
throw new RuntimeException("Puzzle importer null");
}

// Theoretically, this exception should never be thrown, since LEGUP should not be
// allowing the user to give text input for a puzzle that doesn't support it
if (!importer.acceptsTextInput()) {
throw new IllegalArgumentException(puzzle.getName() + " does not accept text input");
}

setWindowTitle(puzzle.getName(), "New " + puzzle.getName() + " Puzzle");
importer.initializePuzzle(statements);

puzzle.initializeView();
// puzzle.getBoardView().onTreeElementChanged(puzzle.getTree().getRootNode());
setPuzzleEditor(puzzle);
}
catch (IllegalArgumentException exception) {
throw new IllegalArgumentException(exception.getMessage());
}
catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
IllegalAccessException | InstantiationException e) {
LOGGER.error(e);
throw new RuntimeException("Puzzle creation error");
}

}

/**
* Loads a puzzle file
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,17 @@ public void executeCommand() {
}
else {
TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView;
finalTreeElement = transitionView.getChildView().getTreeElement();
if (transitionView.getChildView() != null) {
finalTreeElement = transitionView.getChildView().getTreeElement();
}
else {
finalTreeElement = null;
}
}

if (finalTreeElement != null) {
puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
}
puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection));
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/edu/rpi/legup/model/Puzzle.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,26 @@ public boolean isValidDimensions(int rows, int columns) {
return rows > 0 && columns > 0;
}

/**
* Checks if the given array of statements is valid text input for the given puzzle
*
* @param statements
* @return
*/
public boolean isValidTextInput(String[] statements) {
return statements.length > 0;
}

/**
* Determines if the edu.rpi.legup.puzzle was solves correctly
*
* @return true if the board was solved correctly, false otherwise
*/
public boolean isPuzzleComplete() {
if (tree == null) {
return false;
}

boolean isComplete = tree.isValid();
if (isComplete) {
for (TreeElement leaf : tree.getLeafTreeElements()) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/edu/rpi/legup/model/PuzzleExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public abstract class PuzzleExporter {

/**
* PuzzleExporter Constructor exports the puzzle object to a file
*
* @param puzzle puzzle that is to be exported
*/
public PuzzleExporter(Puzzle puzzle) {
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/edu/rpi/legup/model/PuzzleImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public abstract class PuzzleImporter {
private static final Logger LOGGER = LogManager.getLogger(PuzzleImporter.class.getName());
Expand All @@ -24,12 +21,17 @@ public abstract class PuzzleImporter {

/**
* PuzzleImporter Constructor creates the puzzle object
*
* @param puzzle puzzle that is imported
*/
public PuzzleImporter(Puzzle puzzle) {
this.puzzle = puzzle;
}

public abstract boolean acceptsRowsAndColumnsInput();

public abstract boolean acceptsTextInput();

/**
* Initializes an empty puzzle
*
Expand All @@ -46,6 +48,13 @@ public void initializePuzzle(int rows, int columns) throws RuntimeException {
}
}

public void initializePuzzle(String[] statements) throws InputMismatchException, IllegalArgumentException {
// Note: Error checking for the statements will be left up to the puzzles that support
// text input. For example, some puzzles may be okay with "blank" statements (Strings with
// length = 0) while others may not.
initializeBoard(statements);
}

/**
* Initializes the puzzle attributes
*
Expand Down Expand Up @@ -116,6 +125,8 @@ public void initializePuzzle(Node node) throws InvalidFileFormatException {
*/
public abstract void initializeBoard(Node node) throws InvalidFileFormatException;

public abstract void initializeBoard(String[] statements) throws UnsupportedOperationException, IllegalArgumentException;

/**
* Creates the proof for building
*
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/edu/rpi/legup/model/rules/DirectRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,12 @@ public DirectRule(String ruleID, String ruleName, String description, String ima
*/
public String checkRule(TreeTransition transition) {
Board finalBoard = transition.getBoard();

if (!finalBoard.isModified()) {
return "State must be modified";
if (transition.getParents().size() != 1 ||
transition.getParents().get(0).getChildren().size() != 1) {
return "State must have only 1 parent and 1 child";
}
else {
if (transition.getParents().size() != 1 ||
transition.getParents().get(0).getChildren().size() != 1) {
return "State must have only 1 parent and 1 child";
}
else {
return checkRuleRaw(transition);
}
return checkRuleRaw(transition);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/edu/rpi/legup/model/tree/Tree.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public Set<TreeElement> getLeafTreeElements() {

/**
* Gets a Set of TreeNodes that are leaf nodes from the sub tree rooted at the specified node
*
* @param node node that is input
* @return Set of TreeNodes that are leaf nodes from the sub tree
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.rpi.legup.model.PuzzleExporter;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard;
import org.w3c.dom.Document;

public class BattleshipExporter extends PuzzleExporter {
Expand All @@ -18,7 +19,13 @@ public BattleshipExporter(Battleship battleShip) {
*/
@Override
protected org.w3c.dom.Element createBoardElement(Document newDocument) {
BattleshipBoard board = (BattleshipBoard) puzzle.getTree().getRootNode().getBoard();
BattleshipBoard board;
if (puzzle.getTree() != null) {
board = (BattleshipBoard) puzzle.getTree().getRootNode().getBoard();
}
else {
board = (BattleshipBoard) puzzle.getBoardView().getBoard();
}

org.w3c.dom.Element boardElement = newDocument.createElement("board");
boardElement.setAttribute("width", String.valueOf(board.getWidth()));
Expand Down
Loading

0 comments on commit 7aba3f3

Please sign in to comment.