Ludii Forum
Get board size - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Questions (https://ludii.games/forums/forumdisplay.php?fid=13)
+--- Forum: About Ludii (https://ludii.games/forums/forumdisplay.php?fid=14)
+--- Thread: Get board size (/showthread.php?tid=254)



Get board size - Quentin Cohen-Solal - 11-13-2020

Hello,

How can I retrieve the chosen size of a game with the ludii library ?

Thank you so much.


RE: Get board size - Eric Piette - 11-16-2020

Hi,

Depends what you mean by size. If you speak about the dimension of the board, no.
However, you can get the number of vertices/cells/edges in each container.
In your case, I guess you want the number of default graph element type in the board. For that you can get it with

Code:
final SiteType defaultType = context.board().defaultSite();
final Topology topologyBoard = context.game().board().topology();
final int sizeDefaultSite = topologyBoard.getGraphElements(defaultType).size();


(context is of the type Context, but I guess you know that)

Regards,
Eric


RE: Get board size - Quentin Cohen-Solal - 11-16-2020

I was rather thinking of the size chosen as an option (for games with such an option).


RE: Get board size - DennisSoemers - 11-16-2020

(11-16-2020, 01:03 PM)Quentin Cohen-Solal Wrote: I was rather thinking of the size chosen as an option (for games with such an option).

That's not really something we support currently, at least not in a very clean and easy way. The options are only used for preprocessing the contents of the game description file before compiling the game, and after game compilation the game itself is completely oblivious to the fact that it used to have different kinds of options available.

If you know that you're working with the GUI, you can try this code:

Code:
game.description().gameOptions().allOptionStrings(SettingsManager.userSelections.selectedOptionStrings())

That line should return a List<String> containing string descriptions of all the selected options (including ones that were left at their default values. That should include things like "Board Size/5x5" for example.

But that "SettingsManager.userSelections" thing used in there is only valid if you're working from inside the GUI, that provides access to what the user selected inside the GUI. If you're running experiments programmatically, without the GUI existing, this will either just be garbage data or maybe even cause crashes. Of course, in the programmatic use cases you probably also would have already written the code that chooses which games to compile, and with which options, yourself, so you would have to somehow save the options you used at that stage.