Closed blunket closed 4 years ago
This is probably not high priority. Just may be convenient. The behavior I'd like to implement is that if the turn is considered invalid, all moves in the turn will be undone so the player can retry. (probably not all games will want to undo everything though.)
Quick update on this:
Actually as it turns out, I get the following error whenever my game move functions return ANYTHING (in this case, i have them returning INVALID_MOVE)
The error is because you're modifying G
in the same function where you return INVALID_MOVE
, which is not supported by Immer. You should either:
I can see how this might be inconvenient. We should find a workaround.
Oh! Thank you for the tip!
The more I use this library the more I love it. And I think I'll be able to start helping you out sooner or later!! Just still learning but I'll do my best
Great. Your feature requests and bug requests are quite helpful too, so keep them coming in as you notice issues!
@blunket I think your idea is a good one (having a condition be satisfied before the turn is ended). However, I'd prefer to not add too many conditionals and validators to the API at the moment. I'll close this given that you can implement this idea using an endTurn
move.
Hey @nicolodavis. Totally understandable for now, though I wonder how this will work with AI implementation given that it's not intended to be a valid move.
Can you elaborate? A bot would never make invalid moves in the first place (i.e you would not have it end the turn before the condition has been fulfilled), so I'm not sure if we need this for AI purposes.
Oh, okay, I'm sorry! Thanks for explaining.
Currently my game client can call endTurn. However, I need to validate the turn one last time on the server-side in such a way that cannot easily be done on the client side while the turn is being made. I'd like to validate turns on both the client and server anyhow.
So after reading this: https://github.com/nicolodavis/boardgame.io/issues/91 ... It looks like the best solution (as of now) is to disable client-side endTurn calls, add an actual "endTurn" move, validate the turn there, and then call
endTurn
from the actual Game instance.I really like that I can return
INVALID_MOVE
from a move function. Is there some possibility to have like anINVALID_TURN
constant that i can return from theonTurnEnd
hook?(For a clearer picture: in my game, capturing an enemy piece on a turn is mandatory if at all possible, similar to checkers; I need to check and make sure, at the end of the turn, that the player has made the mandatory captures)