Created
June 12, 2020 12:15
-
-
Save DennisSoemers/73b9699e2747bafe0b68d167f607a25f to your computer and use it in GitHub Desktop.
Listing rulesets available in games in Ludii, and compiling with them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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