Skip to content

Commit

Permalink
Merge branch 'dev' into TreeTent-Test-Suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jadeandtea authored Apr 16, 2024
2 parents 06eb109 + 4781736 commit a098868
Show file tree
Hide file tree
Showing 125 changed files with 3,115 additions and 127 deletions.
63 changes: 58 additions & 5 deletions .github/workflows/java-autoformat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ name: Java Code Auto Format
on: pull_request

jobs:
format:
if: github.event.pull_request.head.repo.full_name == github.repository
format_dev:
if: |
github.event.pull_request.head.ref == 'dev' &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -15,7 +17,6 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 21
distribution: temurin

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand All @@ -28,7 +29,58 @@ jobs:

- name: Check for modified files
id: git-check
run: echo "modified=$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT
run: echo "modified=$(if [[ -n $(git status -s) ]]; then echo "true"; else echo "false"; fi)" >> $GITHUB_OUTPUT

- name: Create temporary branch and pull request
if: steps.git-check.outputs.modified == 'true'
run: |
git config --global user.name 'Bram van Heuveln'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
branch_name="auto-format-code-$(date +%s)"
git checkout -b $branch_name
./gradlew :spotlessApply
git add .
git commit -am "Automated Java code formatting changes"
git push --set-upstream origin $branch_name
gh pr create -B dev -H $branch_name --title 'Automated Java code formatting changes' --body 'This pull request contains automated code formatting changes.' --reviewer ${{ github.actor }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Must approve auto-format pull request
if: steps.git-check.outputs.modified == 'true'
run: |
echo "Please review and approve the appropriate auto-format-code pull request."
exit 1
format_pull_request_to_dev:
if: |
github.event.pull_request.base.ref == 'dev' &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v1
with:
ref: ${{ github.head_ref }}

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

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

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

- name: Run spotless
run: ./gradlew :spotlessApply

- name: Check for modified files
id: git-check
run: echo "modified=$(if [[ -n $(git status -s) ]]; then echo "true"; else echo "false"; fi)" >> $GITHUB_OUTPUT

- name: Push changes
if: steps.git-check.outputs.modified == 'true'
Expand All @@ -37,4 +89,5 @@ jobs:
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git add .
git diff --cached --exit-code || git commit -am "Automated Java code formatting changes" && git push
git commit -am "Automated Java code formatting changes"
git push
13 changes: 8 additions & 5 deletions src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public class AutoCaseRuleCommand extends PuzzleCommand {

private List<TreeTransition> caseTrans;

private static final int MAX_CASES = 10;

/**
* AutoCaseRuleCommand Constructor creates a command for validating a case rule
*
Expand Down Expand Up @@ -118,9 +116,14 @@ public String getErrorString() {
return "The selection must produce at least one case";
}

if (caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement()).size()
> MAX_CASES) {
return "The selection can produce a max of " + MAX_CASES + " cases";
int numberOfCaseRules =
caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement()).size();
System.out.println("Number of cases:" + numberOfCaseRules);
if (numberOfCaseRules > caseRule.MAX_CASES) {
return "The selection can produce a max of " + caseRule.MAX_CASES + " cases";
}
if (numberOfCaseRules < caseRule.MIN_CASES) {
return "The selection must produce a minimum of " + caseRule.MIN_CASES + " cases";
}

return null;
Expand Down
108 changes: 55 additions & 53 deletions src/main/java/edu/rpi/legup/model/gameboard/GridRegion.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
package edu.rpi.legup.model.gameboard;

import java.util.ArrayList;
import java.util.List;

public abstract class GridRegion<T> {

protected List<T> regionCells;

/**
* Region Constructor
*/
public GridRegion() {
this.regionCells = new ArrayList<>();
}

/**
* Adds the cell to the region
* @param cell cell to be added to the region
*/
public void addCell(T cell) {
regionCells.add(cell);
}

/**
* Removes the cell from the region
* @param cell cell to be remove from the region
*/
public void removeCell(T cell) {
regionCells.remove(cell);
}

/**
* Returns the list of cells in the region
* @return list of cells in region
*/
public List<T> getCells() {
return regionCells;
}

/**
* Returns the number of cells in the region
* @return number of cells in the region
*/
public int getSize(){
return regionCells.size();
}

/*
public void colorRegion(){}
*/

}
package edu.rpi.legup.model.gameboard;

import java.util.ArrayList;
import java.util.List;

public abstract class GridRegion<T> {

protected List<T> regionCells;

/** Region Constructor */
public GridRegion() {
this.regionCells = new ArrayList<>();
}

/**
* Adds the cell to the region
*
* @param cell cell to be added to the region
*/
public void addCell(T cell) {
regionCells.add(cell);
}

/**
* Removes the cell from the region
*
* @param cell cell to be remove from the region
*/
public void removeCell(T cell) {
regionCells.remove(cell);
}

/**
* Returns the list of cells in the region
*
* @return list of cells in region
*/
public List<T> getCells() {
return regionCells;
}

/**
* Returns the number of cells in the region
*
* @return number of cells in the region
*/
public int getSize() {
return regionCells.size();
}

/*
public void colorRegion(){}
*/

}
5 changes: 4 additions & 1 deletion src/main/java/edu/rpi/legup/model/rules/CaseRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
public abstract class CaseRule extends Rule {

private final String INVALID_USE_MESSAGE;
public int MAX_CASES;
public int MIN_CASES;

/**
* CaseRule Constructor creates a new case rule.
Expand All @@ -27,6 +29,8 @@ public CaseRule(String ruleID, String ruleName, String description, String image
super(ruleID, ruleName, description, imageName);
this.ruleType = CASE;
this.INVALID_USE_MESSAGE = "Invalid use of the case rule " + this.ruleName;
this.MAX_CASES = 10;
this.MIN_CASES = 1; // By default, this will not actually have any effect
}

/**
Expand Down Expand Up @@ -68,7 +72,6 @@ public String checkRule(TreeTransition transition) {
return "All children nodes must be justified with the same case rule.";
}
}

String check = checkRuleRaw(transition);

// Mark transition and new data as valid or not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,28 @@ public String checkRuleRaw(TreeTransition transition) {
for (LightUpCell c : spots) {
ArrayList<Board> cases = getCases(parent.getBoard(), c);

// We will allow case rules to have only one option
if (cases.size() == childTransitions.size() && cases.size() >= 1) {
// Note: we will allow case rules to have only one option

// Some error checking to make sure that weird stuff doesn't happen
// if this case rule is incorrectly used to justify changes on the
// puzzle board
if (cases.size() == childTransitions.size() && cases.size() == 1) {
TreeTransition childTransition = childTransitions.get(0);

// If there is only 1 case, then this case rule should function no
// differently than the Finish With Bulbs Direct Rule
FinishWithBulbsDirectRule finishWithBulbs = new FinishWithBulbsDirectRule();
childTransition.setRule(finishWithBulbs);
boolean isCorrect = childTransition.isCorrect();

// Changes the transition back to this case rule
childTransition.setRule(this);

if (isCorrect) {
return null;
}
return super.getInvalidUseOfRuleMessage();
} else if (cases.size() == childTransitions.size() && cases.size() > 1) {
boolean foundSpot = true;
for (TreeTransition childTrans : childTransitions) {
LightUpBoard actCase = (LightUpBoard) childTrans.getBoard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public BlackOrWhiteCaseRule() {
"Black or White",
"Each blank cell is either black or white.",
"edu/rpi/legup/images/nurikabe/cases/BlackOrWhite.png");
this.MAX_CASES = 2;
}

/**
Expand Down
Loading

0 comments on commit a098868

Please sign in to comment.