Skip to content

Instantly share code, notes, and snippets.

@DennisSoemers
Created June 12, 2020 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DennisSoemers/73b9699e2747bafe0b68d167f607a25f to your computer and use it in GitHub Desktop.
Save DennisSoemers/73b9699e2747bafe0b68d167f607a25f to your computer and use it in GitHub Desktop.
Listing rulesets available in games in Ludii, and compiling with them
import java.util.List;
import game.Game;
import main.options.Ruleset;
import util.GameLoader;
/**
* Simple test class to print all the rulesets that a Ludii game has
* to standard out.
*
* NOTE: this code was written for some in-dev version of Ludii after 0.9.3. Should
* mostly work with Ludii 0.9.3 (and probably also with some later versions in the future),
* but especially some of the imports might have to be slightly different. Not sure.
*
* @author Dennis Soemers
*/
public class ListingAllRulesets
{
/**
* Main method
* @param args
*/
public static void main(final String[] args)
{
// We'll first load Cercar La Liebre with all defaults (this is a game that has rulesets)
final Game game = GameLoader.loadGameFromName("Cercar La Liebre.lud");
// Get all the rulesets that were discovered when compiling with defaults
final List<Ruleset> rulesets = game.description().rulesets();
for (final Ruleset ruleset : rulesets)
{
System.out.println("Found ruleset: " + ruleset.heading());
System.out.println("This ruleset sets the following options: " + ruleset.optionSettings());
// We can use the options of a ruleset to re-compile the game
final Game gameWithRuleset = GameLoader.loadGameFromName("Cercar La Liebre.lud", ruleset.optionSettings());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment