Removed unused imports and provided JavaDocs.

This commit is contained in:
Jonathan Turner 2024-02-11 20:24:59 -05:00
parent e0932b4721
commit d6a0ddcd8d
2 changed files with 64 additions and 20 deletions

View File

@ -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<BoardNode> {
/* Fields used to hold each node's data. */
public BoardNode parent;
public int heuristic, cost, expected;
public Board board;
public List<BoardNode> 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<BoardNode> {
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<BoardNode> {
}
}
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<BoardNode> {
}
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", " ");
}
}

View File

@ -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);
}