-
Notifications
You must be signed in to change notification settings - Fork 716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(events): Don’t leak stage events across turns & allow self-ending turns/phases #957
feat(events): Don’t leak stage events across turns & allow self-ending turns/phases #957
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @cristiands7 — great to see those issues all targeted by a single PR :-)
One thought: do you think we could use the value of ctx
when Events
is instantiated to track how many turns have ended? That way we could also protect against infinite loops by setting a maximum number of turn endings and bail when we hit that. For now it could be some arbitrarily large number like 10 * ctx.numPlayers
, but we could potentially also make it configurable just in case someone wants to increase the threshold.
(Side note: in this kind of scenario it could be helpful if there was an API for plugins declaring the action invalid along the lines of the INVALID_MOVE
constant moves can use — it might be better to have a harder break like that rather than just ending 20 turns and logging a warning.)
@delucis I don't like the name |
Maybe something like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @cristiands7! Here are a few more comments/details.
@cristiands7 Just merged #963 so you should be able to merge that in to this branch and use the new |
@delucis I'm happy that you can submit the pending changes. I've been a bit busy these days and couldn't take the time to do it. Thanks. |
@cristiands7 Thanks — I didn’t want to jump on your toes, but I had a bit of time and thought it would be best to help with this PR, which should be a nice fix for some users. |
Looks great! For a moment I thought you had solved the halting problem https://en.m.wikipedia.org/wiki/Halting_problem hahaha, but having a theshold on number of actions per turn LGTM, just left a comment |
@cristiands7 I think #769 is clear enough about wanting to check |
Thanks for the work getting this started @cristiands7! This is now released on npm as part of v0.46.0 🎉 |
Closes #899
Closes #526
Closes #558
An important side effect of this change is that it opens up the possibility to produce infinite loops using effects on hooks. We should add some check to prevent this, or at least warn about it.
We should also evaluate the possibility of remove ctx from endIf, because the developers expect its value to be up-to-date and it can be confusing.
Edit (by @delucis): This does not yet address #769 because that needs
endIf
to run afteractivePlayers
has been updated.