Skip to content

Commit

Permalink
finished making it work
Browse files Browse the repository at this point in the history
  • Loading branch information
04vmatsibekker committed Aug 4, 2023
1 parent c5badab commit 408595c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ public void executeCommand() {
for (TreeElementView view : selectedViews) {
BoardView boardView = puzzle.getBoardView();
TreeTransition thisTreeTransition = (TreeTransition) boardView.getTreeElement();

TreeElement treeElement = view.getTreeElement();
TreeNode treeNode;
if (treeElement.getType() == TreeElementType.TRANSITION) {
TreeTransition transition = (TreeTransition) treeElement;
transition.setCurrentParent(thisTreeTransition.getParents()[0]);
transition.setCurrentBoard( boardView.getBoard() );
if (thisTreeTransition.getParents().size() >0) {
transition.setPrevBoard(thisTreeTransition.getParents().get(0).getBoard());
}
transition.setCurrentBoard( thisTreeTransition.getBoard() );
treeNode = transition.getParents().get(0);
}
else {
Expand All @@ -70,8 +73,10 @@ public void executeCommand() {
TreeTransition transition = addTran.get(treeElement);
if (transition == null) {
transition = tree.addNewTransition(treeNode);
transition.setCurrentParent(thisTreeTransition.getParents()[0]);
transition.setCurrentBoard( boardView.getBoard() );
if (thisTreeTransition.getParents().size() >0) {
transition.setPrevBoard(thisTreeTransition.getParents().get(0).getBoard());
}
transition.setCurrentBoard( thisTreeTransition.getBoard() );
transition.setRule(newRule);
tree.addTreeElement(transition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public ContradictionRule(String ruleID, String ruleName, String description, Str
*/
@Override
public String checkRule(TreeTransition transition) {
Board prevBoard = transition.getCurrentParent().getBoard();
Board board = transition.getBoard();
Board prevBoard = transition.getPrevBoard();
Board board = transition.getCurrentBoard();
System.out.println("Changed puzzleElement indexes: ");
for (PuzzleElement puzzleElement : board.getPuzzleElements()) {
if (prevBoard.getPuzzleElement(puzzleElement).equalsData(puzzleElement)) {
Expand Down
41 changes: 23 additions & 18 deletions src/main/java/edu/rpi/legup/model/tree/TreeTransition.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class TreeTransition extends TreeElement {
private Rule rule;
private boolean isCorrect;
private boolean isVerified;
private Board currentBoard;
private Board prevBoard;

/**
* TreeTransition Constructor create a transition from one node to another
Expand Down Expand Up @@ -276,23 +278,7 @@ public void addParent(TreeNode parent) {
parents.add(parent);
}

/**
* Adds a parent tree node to this tree transition
*
* @param parent parent tree node to add
*/
public void setCurrentParent(TreeNode parent) {
currentParent = parent;
}

/**
* Adds a parent tree node to this tree transition
*
* @param parent parent tree node to add
*/
public TreeNode getCurrentParent() {
return this.currentParent;
}

/**
* Removes a parent tree node to this tree transition
Expand Down Expand Up @@ -402,7 +388,7 @@ public boolean isJustified() {
*
* @param board board state of the transition
*/
public void setCurrentBoard(Board board) {
public void setCurrentBoard(Board currentBoard) {
this.currentBoard = currentBoard;
}

Expand All @@ -412,7 +398,26 @@ public void setCurrentBoard(Board board) {
*
* @param board board state of the transition
*/
public Board getCurrentBoard(Board board) {
public Board getCurrentBoard() {
return this.currentBoard;
}

/**
* Changes current board
*
* @param board board state of the transition
*/
public void setPrevBoard(Board prevBoard) {
this.prevBoard = prevBoard;
}


/**
* Changes board
*
* @param board board state of the transition
*/
public Board getPrevBoard() {
return this.prevBoard;
}
}

0 comments on commit 408595c

Please sign in to comment.