09-24-2021, 12:49 PM
I want to get the score after each move in the Ludi AI, and I try below code (study from your source code of AlphaBetaSearch.java) ,however ,when I move a piece of Town in the first step error comes as below:
Could you tell me how to get the score after each step?
Code:
Heuristics heuristicValueFunction = null;
final metadata.ai.Ai aiMetadata = game.metadata().ai();
if (aiMetadata != null && aiMetadata.heuristics() != null) {
heuristicValueFunction = Heuristics.copy(aiMetadata.heuristics());
}
final Context copyContext = copyContext(context);
final Move m = currentRootMoves.get(0);
game.apply(copyContext, m);
final int maximisingPlayer = context.state().playerToAgent(context.state().mover());
final int numPlayers = game.players().count();
for (int j = 0; j < numPlayers; j++) {
if(j!=maximisingPlayer){
float heuristicScore = heuristicValueFunction.computeValue(copyContext, j, -100.f);
System.out.println(heuristicScore);
}
}
Exception in thread "Thread-4" java.lang.NullPointerException: Cannot invoke "main.collections.FVector.get(int)"
because "this.pieceWeights" is null
at metadata.ai.heuristics.terms.Material.computeValue(Material.java:138)
at metadata.ai.heuristics.Heuristics.computeValue(Heuristics.java:114)
at CannonAI.selectAction(CannonAI.java:50)
at other.ThinkingThread$ThinkingThreadRunnable.run(ThinkingThread.java:188)
at java.base/java.lang.Thread.run(Thread.java:831)
(metadata
(graphics
(board Style chess)
)
(ai
(bestAgent "Alpha-Beta")
(heuristics {
(material transformation:(divNumInitPlacement) pieceWeights:{
(pair "Pawn1" 1.0)
(pair "Pawn2" 1.0)
(pair "Town1" 5.0)
(pair "Town2" 5.0)
})
})
)
)
Could you tell me how to get the score after each step?