09-24-2021, 01:02 PM
(This post was last modified: 10-11-2021, 10:57 AM by DennisSoemers.)
The Heuristics class has, very similar to the abstract AI class, an (EDIT:) "init(game)" "initAI(Game)" method. If you're loading and using your AI inside the GUI, we already make sure to call initAI() on your AI class for you whenever necessary, but we can't know about anything else that might require initialising --- like heuristics --- inside of your own custom AI class, so you'll have to ensure to call that at least once before trying to use it. Doing that should solve the NullPointerException you're getting.
Aside from that, your loop through the player indices would likely cause issues because you're starting from index j = 0, but in Ludii we have a convention of starting to count at 1 for anything related to Player indices (such that Player 1 has index 1, Player 2 index 2, etc.). So you'd likely want to change the loop to be more like:
" for (int j = 1; j <= numPlayers; j++) "
i.e. start counting at 1, and keep going up to and INCLUDING numPlayers.
As a more general note on efficiency, loading heuristics from metadata like that --- and especially initialising it when you also do that to fix the bug --- can be kind of expensive, and is only actually required once per game. So I would recommend moving that into an initAI() method for your AI class (maybe it's already there, can't tell from your code snippet).
Aside from that, your loop through the player indices would likely cause issues because you're starting from index j = 0, but in Ludii we have a convention of starting to count at 1 for anything related to Player indices (such that Player 1 has index 1, Player 2 index 2, etc.). So you'd likely want to change the loop to be more like:
" for (int j = 1; j <= numPlayers; j++) "
i.e. start counting at 1, and keep going up to and INCLUDING numPlayers.
As a more general note on efficiency, loading heuristics from metadata like that --- and especially initialising it when you also do that to fix the bug --- can be kind of expensive, and is only actually required once per game. So I would recommend moving that into an initAI() method for your AI class (maybe it's already there, can't tell from your code snippet).