Ludii Forum
String move conversion ? - 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: String move conversion ? (/showthread.php?tid=168)

Pages: 1 2


String move conversion ? - Quentin Cohen-Solal - 09-12-2020

Is there a method in the ludii library to automatically convert a "string move", such as "A1" or "B3-C7" into a correct Move instance that can be played directly with game.apply(context, move) ? (at least for the pose and displacement games).


RE: String move conversion ? - Eric Piette - 09-12-2020

Hi Quentin,

No, and in reality that's possible to have many moves corresponding to the same 'from' and 'to' locations but with difference consequences. Consequently applying directly a move with only these information is not possible.
But we can get a sub list of the legal moves corresponding to these 'from' and 'to' locations, Matthew uses something similar to convert the mouse clicks to the corresponding playable sites and then to the corresponding legal moves.

That would be useful for you?

Regards,
Eric.


RE: String move conversion ? - Quentin Cohen-Solal - 09-12-2020

Yes, that will help me.

Thank you so much.
Regards.


RE: String move conversion ? - Eric Piette - 09-14-2020

Hi,

The method will be in Game.java with the signature
List<Move> getMovesFromCoordinates(final String str, final Context context, final List<Move> originalMoves)

The coordinates have to be in the format "A1" or "A1-B1"

For now that does not take in account the level in case of a stack or the siteType in case of move between different site types (Vertex, Cell or Edge). I will add that later, so the signature is able to change in the future.

Regards,
Eric


RE: String move conversion ? - Quentin Cohen-Solal - 09-14-2020

Very well, thank.

Today, I downloaded the new version of ludii. Not having found the method, I guess it hasn't been added yet.

Note: I saw that in Game there is the method createPassMove(). It would be useful to also have the method createSwapMove() . However, the availability of createSwapMove does not seem urgent to me, I thought I found a way to do otherwise.


RE: String move conversion ? - Eric Piette - 09-15-2020

Hi Quentin,

Did you try with the release of yesterday, the version 1.0.6?
The method should be on it.

public List<Move> getMovesFromCoordinates(final String str, final Context context,
final List<Move> originalMoves)

The createPassMove method is used for the forced pass in case of a player has no legal moves. The swap move does not need a such method.

Regards,
Eric


RE: String move conversion ? - Quentin Cohen-Solal - 09-15-2020

Hi,

Yes, I try the version 1.0.6. In game.Game, there is no subpackage java. Moreover, my IDE fails to automatically resolve the import of getMovesFromCoordinates().

Regards,
Quentin


RE: String move conversion ? - DennisSoemers - 09-15-2020

Eric meant the "Game.java" source file, with .java as file extension, not a subpackage named Java :)

Most of the standard AI methods (like selectAction()) already take a Game object as argument. If you have a variable of that type, you can just call the new getMovesFromCoordinates() method on that object (so it's a member of the Game objects, not a static method of the Game class).


RE: String move conversion ? - Quentin Cohen-Solal - 09-18-2020

Thank you very much, it works.

@Eric Piette: What I wanted to say is that the method getMovesFromCoordinates() does not allow one, as far as I know, to retrieve the swap action and therefore that it would have been interesting to have a method allowing to create the swap action.


RE: String move conversion ? - Eric Piette - 09-18-2020

Hi Quentin,

Ok. I added that method
public static Move createSwapMove(final int mover, final int player1, final int player2)
doing what you asked for.

That will be available in the next release (published this evening).

Regards,
Eric