Ludii Forum
lastMove : bug ? - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Problems (https://ludii.games/forums/forumdisplay.php?fid=5)
+--- Forum: Ludii Player Problems (https://ludii.games/forums/forumdisplay.php?fid=6)
+--- Thread: lastMove : bug ? (/showthread.php?tid=23)



lastMove : bug ? - Quentin Cohen-Solal - 01-29-2020

Is it normal that the method context.trial().LastMove() can return the move [..., SetNextPlayer (1)] ?

If yes, what method should be used to obtain the move chosen by the previous player?

Thank you


RE: lastMove : bug ? - DennisSoemers - 01-29-2020

Yes that's correct, it always just gives the last move that was played, regardless of who selected that move.

Currently we don't have a method that directly returns the last move made by a mover different from the current mover. I suppose that would be a sensible method for us to add for convenience in a future version, but for now it should be relatively easy to implement yourself. The full history of ALL moves in a trial can be obtained using context.trial().moves(). That just returns an ArrayList<Move>. So you'd probably want to do something like:



Code:
public static Move lastOpponentMove(final Context context)
{
    final int currentMover = context.state().mover();
    final List<Move> movesHistory = context.trial().moves();

    for (int i = movesHistory.size() - 1; i >= 0; --i)
    {
        final Move m = movesHistory.get(i);
        if (m.mover() != currentMover)    // Found move made by someone else
            return m;
    }

    return null;
}

I just wrote that here and didn't test it, but pretty sure this should work correctly for now.


RE: lastMove : bug ? - Quentin Cohen-Solal - 02-16-2020

We did not understand each other. I find surprising that there is no correspondence between the actions of game.moves(context).moves() and context.trial().Moves() (or equivalently context.trial().LastMove( )).

For example, in the Amazons game, a player can play the action Move(60-70) while the corresponding action given by context.trial().LastMove() is, for example, [Move (60-70), SetNextPlayer (2)], and not just "Move(60-70)". My initial question was: is there a method that returns the action as it was chosen by the previous player (possibly the same player), i.e., without any enrichment of the action due to the rules of the game.


RE: lastMove : bug ? - DennisSoemers - 02-17-2020

Aaah, like that. Hmmm no, not directly. The list of moves returned by game.moves(context).moves() is the list of legal moves. For computational efficiency, these do not always include all the actions that will be applied to the game state, but sometimes contain "consequents", which are basically some additional rules to be resolved once that move is picked. These do not show up in Strings. Only once the move is actually applied are these rules computed, and then that's what gets stored in the Trial.

Why do you need this information?

For the internal MCTS implementation we have inside Ludii, I remember needing something similar for tree reuse across turns. When we've previously run a search, made a move, and then start a new search, I want to reuse relevant parts of the search tree. This means I need to traverse from the old root along branches corresponding to the move that I made, and any moves that any opponents might have made, to find the new root node for the new situation. For this purpose, I need the "full" move with the additional actions appended. But for other purposes (like, finding which child node corresponds to any given un-applied legal move in a state), I need the "smaller" moves.

So what I basically do in my MCTS nodes is that I simply store both versions of the move when I create a node; I store the move that was "picked" (without additional actions appended) in the node as "parentMoveWithoutConseq", and I store the move that appears at the end of the trial after applying it in the node as "parentMove".


RE: lastMove : bug ? - FirstAI - 06-15-2022

(01-29-2020, 08:14 PM)DennisSoemers Wrote: Yes that's correct, it always just gives the last move that was played, regardless of who selected that move.

Currently we don't have a method that directly returns the last move made by a mover different from the current mover. I suppose that would be a sensible method for us to add for convenience in a future version, but for now it should be relatively easy to implement yourself. The full history of ALL moves in a trial can be obtained using context.trial().moves(). That just returns an ArrayList<Move>. So you'd probably want to do something like:

it seems that there is no moves() functions in Trial class. So how to obtain the moves history from Trial?

Code:
public static Move lastOpponentMove(final Context context)
{
    final int currentMover = context.state().mover();
    final List<Move> movesHistory = context.trial().moves();

    for (int i = movesHistory.size() - 1; i >= 0; --i)
    {
        final Move m = movesHistory.get(i);
        if (m.mover() != currentMover)    // Found move made by someone else
            return m;
    }

    return null;
}

I just wrote that here and didn't test it, but pretty sure this should work correctly for now.