From d6a0ddcd8d0f612cf85c3a3978480d72cf9638a8 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 11 Feb 2024 20:24:59 -0500 Subject: [PATCH] Removed unused imports and provided JavaDocs. --- .../java/Assignments/A1/models/BoardNode.java | 67 ++++++++++++++----- .../Assignments/A1/models/helper/Solver.java | 17 ++++- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/src/main/java/Assignments/A1/models/BoardNode.java b/src/main/java/Assignments/A1/models/BoardNode.java index 08fe999..5e72ace 100644 --- a/src/main/java/Assignments/A1/models/BoardNode.java +++ b/src/main/java/Assignments/A1/models/BoardNode.java @@ -3,14 +3,29 @@ package Assignments.A1.models; import java.util.ArrayList; import java.util.List; +/** + * Used to represent a board on a spanning tree. + * + * @author Jonathan Turner + * @version Spring 2024 + */ public class BoardNode implements Comparable { + /* Fields used to hold each node's data. */ public BoardNode parent; - public int heuristic, cost, expected; public Board board; public List children; - public int depth = -1; + public int heuristic, cost, expected, depth; + /** + * Used to create a board with a parent and child nodes. + * + * @precondition none + * @postcondition none + * + * @param board the board representing the node. + * @param parent the parent node, can be null. + */ public BoardNode(Board board, BoardNode parent) { this.board = board; this.parent = parent; @@ -20,10 +35,40 @@ public class BoardNode implements Comparable { this.children = new ArrayList<>(); } - public void setDepth(int depth) { - this.depth = depth; + /** + * adds a child to the node. + * + * @precondition child != null + * @postcondition the child is added.. + */ + public void addChild(BoardNode node) { + children.add(node); } + /* Overrides */ + + /** + * Overrides the Object compareTo method. Is a placehold for specifying priority in queues. + * Default: BFS + * + * @param o the object to be compared. + */ + @Override + public int compareTo(BoardNode o) { // BFS + return Integer.compare(this.heuristic, o.heuristic); + } + + /** + * Represents the board in a single string (no line breaks) + * @return the formatting string + */ + @Override + public String toString() { + return this.board.toString().replaceAll("\n", " "); + } + + /* Private Classes: End of JavaDocs */ + private int getActualCost() { if (this.parent != null) { return this.parent.cost + 10; @@ -32,10 +77,6 @@ public class BoardNode implements Comparable { } } - public void addChild(BoardNode node) { - children.add(node); - } - private int getHeuristic() { int cost = 0; for (int i = 0; i < 9; i++) { @@ -83,14 +124,4 @@ public class BoardNode implements Comparable { } return result; } - - @Override - public int compareTo(BoardNode o) { // BFS - return Integer.compare(this.heuristic, o.heuristic); - } - - @Override - public String toString() { - return this.board.toString().replaceAll("\n", " "); - } } diff --git a/src/main/java/Assignments/A1/models/helper/Solver.java b/src/main/java/Assignments/A1/models/helper/Solver.java index 8ed5934..ac58546 100644 --- a/src/main/java/Assignments/A1/models/helper/Solver.java +++ b/src/main/java/Assignments/A1/models/helper/Solver.java @@ -3,9 +3,22 @@ package Assignments.A1.models.helper; import Assignments.A1.models.Board; import Assignments.A1.models.BoardNode; -import java.util.Comparator; - +/** + * Interface used for implementing a solver when there are multiple different variations and classes. + * + * @author Jonathan Turner + * @version Spring 2024 + */ public interface Solver { + /** + * Solves for, finds and creates a spanning representing the solving pattern. + * + * @precondition none + * @postcondition none + * + * @param root the first node/initial start. + * @return the solved leaf node. + */ BoardNode traverse(Board root); }