Closed cojoko closed 3 years ago
moves.length % 2
is perfectly fine and is how lichess itself knows the side to play, unless the game started from a position.
Which API endpoint are you talking about?
So for instance if I want to tell if a it is currently a user's turn in any of their active games, I hit get active games for a user, filter by which games have an "unterminated" tag, then compare the color of the player to moves.length % 2
. Maybe there is an easier way but I havnt found it.
The problem is if moves.length
=== 5, it could be anybody's turn, since moves.length
hangs at 5 moves for 3 moves. Am I over complicating this problem?
Otherwise, how would you suggest getting all active games for a user where it is their turn?
@ornicar bump
Otherwise, how would you suggest getting all active games for a user where it is their turn?
With https://lichess.org/api#operation/apiAccountPlaying. It has an isMyTurn
field.
I know the last three turns get hidden to avoid cheatbots, but AFAIK there is no way to get which color plays next with 100% accuracy from turns 5 - 8. I am using
moves.length % 2
to return whose turn it is to play, so unless there is a cleaner way that I am missing, would there be any harm in adding an endpoint or field in the game data indicating turn?I assume there is a reason I am missing for this omission (or i am blind to an extant solution), but I would be happy to submit a PR for this feature if not.