source_code
source_code
/*
* Người viết:
* Ngày viết:
* Version:
*/
import java.util.*;
this.state = state;
this.goal = goal;
this.cost = cost;
this.heuristic = calculateHeuristic();
this.col = col;
this.row = row;
}
// public Vertex(int[][] state, int cost) {
// this.state = state;
// this.cost = cost;
// }
return state;
this.goal = goal;
return cost;
return heuristic;
return parent;
neighbor.parent = this;
neighbor.row = move[0];
neighbor.col = move[1];
neighbors.add(neighbor);
return neighbors;
if (newRow >= 0 && newRow < 3 && newCol >= 0 && newCol < 3) {
return moves;
int distance = 0;
if (state[i][j] != goal[i][j])
distance++;
return distance ;
state[i][j] = state[x][y];
state[x][y] = temp;
@Override
if (this == o)
return true;
return false;
@Override
return Arrays.deepHashCode(state);
}
package Taci_Algorithm;
import java.util.*;
}
System.out.println();
visited.add(current);
if (Arrays.deepEquals(current.getState(), goal)) {
System.out.println("Goal reached!");
return getPath(current);
}
if (solution == null) {
System.out.println("No Result!");
} else {
System.out.println("Result: ");
for (Vertex node : solution) {
int[][] state = node.getState();
System.out.println("----------");
for (int[] row : state) {
System.out.println(Arrays.toString(row));
}
}
System.out.println("----------");
}
}
}