Removed unused imports and provided JavaDocs.
This commit is contained in:
parent
e0932b4721
commit
d6a0ddcd8d
@ -3,14 +3,29 @@ package Assignments.A1.models;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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> {
|
public class BoardNode implements Comparable<BoardNode> {
|
||||||
|
|
||||||
|
/* Fields used to hold each node's data. */
|
||||||
public BoardNode parent;
|
public BoardNode parent;
|
||||||
public int heuristic, cost, expected;
|
|
||||||
public Board board;
|
public Board board;
|
||||||
public List<BoardNode> children;
|
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) {
|
public BoardNode(Board board, BoardNode parent) {
|
||||||
this.board = board;
|
this.board = board;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
@ -20,10 +35,40 @@ public class BoardNode implements Comparable<BoardNode> {
|
|||||||
this.children = new ArrayList<>();
|
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() {
|
private int getActualCost() {
|
||||||
if (this.parent != null) {
|
if (this.parent != null) {
|
||||||
return this.parent.cost + 10;
|
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() {
|
private int getHeuristic() {
|
||||||
int cost = 0;
|
int cost = 0;
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
@ -83,14 +124,4 @@ public class BoardNode implements Comparable<BoardNode> {
|
|||||||
}
|
}
|
||||||
return result;
|
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", " ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,22 @@ package Assignments.A1.models.helper;
|
|||||||
import Assignments.A1.models.Board;
|
import Assignments.A1.models.Board;
|
||||||
import Assignments.A1.models.BoardNode;
|
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 {
|
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);
|
BoardNode traverse(Board root);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user