From 408595cc7d98a777f4a258404af4a9a6948dbd4c Mon Sep 17 00:00:00 2001 From: 04vmatsibekker <117249183+04vmatsibekker@users.noreply.github.com> Date: Fri, 4 Aug 2023 18:07:07 -0400 Subject: [PATCH] finished making it work --- .../ValidateContradictionRuleCommand.java | 13 ++++-- .../legup/model/rules/ContradictionRule.java | 4 +- .../rpi/legup/model/tree/TreeTransition.java | 41 +++++++++++-------- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java index 628ec28a9..ba6d858d1 100644 --- a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java @@ -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 { @@ -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); } diff --git a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java index fd30d8bcb..b327ed2da 100644 --- a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java @@ -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)) { diff --git a/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java b/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java index 0195e162d..f7f0a3159 100644 --- a/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java +++ b/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java @@ -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 @@ -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 @@ -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; } @@ -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; + } }