Ludii Forum
Improved heuristic - Printable Version

+- Ludii Forum (
+-- Forum: Questions (
+--- Forum: About Ludii (
+--- Thread: Improved heuristic (/showthread.php?tid=731)

Improved heuristic - notpinkpotato - 10-11-2021

How can you improve the heuristics for a specific game?

I am trying to build my own heuristic for a game and I found this example of how to make use of some predefined heuristic functions :

But what if I need a more complex heuristic? How do I define it myself? Can I define it in the .lud file? Or do I need to define it in a new AI class? 

If I want to define a more complex heuristic in my AI class, how do I get access to the game state? From what I understand, variables of type Context give the description of the current game state, but how can I access the different pieces and their positions? I was trying to look through the repository but I couldn't figure it out.

RE: Improved heuristic - DennisSoemers - 10-11-2021

If you want to use more complex heuristics than those that are available through the metadata, you will indeed have to implement them from scratch in Java. Such custom code would also not be accessible as heuristics through the metadata, and therefore would not be possible to specify in .lud files. This means that you would have to write a custom AI class as well to actually use them.

The source code of all of our existing heuristic terms, which you can find on GitHub (see:, should be a useful starting point for how to access relevant state variables. For example, our implementation of the Material heuristic will demonstrate how you can access lists of positions occupied by different types of pieces for the different players.

RE: Improved heuristic - DennisSoemers - 10-11-2021

Note: the inability to access custom heuristic implementations through the metadata section of a .lud file is because we only look through our own codebase for heuristics we allow there. If you implement a new heuristic that you suspect we might be interested in including in the official Ludii codebase, and you're willing to share the implementation, you could always send a Pull Request for it on GitHub. If we then decide to merge it in and include it in the official codebase, it will after that also become accessible to any AI and any game through metadata.