Skip to content
Snippets Groups Projects
Commit f950c07d authored by Elnath's avatar Elnath
Browse files

Implemented/added Move and State class

To represent a single move or a state in the search tree
parent 6a4971c9
No related branches found
No related tags found
No related merge requests found
Pipeline #
package model; package model;
public class Move { public class Move
{
private Car car;
private boolean forward; private Car car;
private int movement_size; private boolean forward;
private int movement_size;
public Move(Car car, boolean forward, int movement_size) {
super(); public Move(Car car, boolean forward, int movement_size)
this.car = car; {
this.forward = forward; super();
this.movement_size = movement_size; this.car = car;
} this.forward = forward;
this.movement_size = movement_size;
}
public Car getCar() {
return car; public void play(int[][] board)
} {
public void setCar(Car car) { if(forward)
this.car = car; car.moveForward(board, movement_size);
} else
public boolean isForward() { car.moveBackwards(board, movement_size);
return forward; }
}
public void setForward(boolean forward) { public Move getOpposite()
this.forward = forward; {
} return new Move(this.car, !this.forward, this.movement_size);
public int getMovement_size() { }
return movement_size;
} public Car getCar()
public void setMovement_size(int movement_size) { {
this.movement_size = movement_size; return car;
} }
public void setCar(Car car)
{
this.car = car;
}
public boolean isForward()
{
return forward;
}
public void setForward(boolean forward)
{
this.forward = forward;
}
public int getMovement_size()
{
return movement_size;
}
public void setMovement_size(int movement_size)
{
this.movement_size = movement_size;
}
} }
package model;
public class State implements Comparable<State>
{
private int heuristic, cost;
private Move move;
private State parent;
public State(int[][] board, Move move, State parent)
{
this.move = move;
this.parent = parent;
this.cost = parent.cost + 1;
this.heuristic = naiveHeuristic(board);
}
public State getParent()
{
return parent;
}
public Move getMove()
{
return move;
}
public int getEvaluation()
{
return heuristic + cost;
}
/**
* Compute the heuristic of the state starting from a board.
* This is intended to be called at start
*/
private int naiveHeuristic(int[][] board)
{
//TODO: heuristic
return 0;
}
@Override
public int compareTo(State o)
{
return Integer.compare(getEvaluation(), o.getEvaluation());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment