I am trying to implement the UCS algorithm for a game in Java and I am now in the stage where I need to calculate the costs of each state.
I made a Node
class with 4 fields (a Table
state, double
cost, a Node
parent and an ArrayList<Node>
children) where i have a private static double calculateCost(Node starting, Node next)
method, which returns the cost of transitioning from the starting
node to the next
node.
Ignore the Table class, there is no need to explain what it does.
I also made the following generateChildren()
method:
public void generateChildren(){
ArrayList<Table> allStates = this.state.generateMoves();
for(Table state : allStates){
Node child = new Node(state, calculateCost(this, ???), this);
children.add(child);
}
}
It generates all the possible moves from a given state, and for each move it creates a child.
What I want is to pass child
as the second argument of the calculateCost()
, so that this
object is the starting Node, and the child
is the next Node. Is it possible at all?