init: Add timeout validation tests and enhance doTimeout logic#498
init: Add timeout validation tests and enhance doTimeout logic#498jdabapo wants to merge 7 commits intozengm-games:masterfrom
Conversation
| } | ||
|
|
||
| doTimeout(t: TeamNum, toStopClock: boolean) { | ||
| doTimeout(t: TeamNum, toStopClock: boolean, playType: teamPlayType) { |
There was a problem hiding this comment.
Can be slightly more concise by changing it to playType: ReturnType<GameSim["getPlayType"]> then you don't need an extra type.
| return new Promise<void>((resolve) => { | ||
| server.listen(port, exposeToNetwork ? "0.0.0.0" : "localhost", () => { | ||
| console.log(`Local: http://localhost:${port}`); | ||
| console.log("Worker console: chrome://inspect/#workers"); |
There was a problem hiding this comment.
Would rather not put this here since it's Chrome specific, other browsers have different ways of accessing it.
| if (playType === "kickoff" || playType === "punt") { | ||
| return; | ||
| } | ||
| if (playType === "extraPoint" || playType === "twoPointConversion") { | ||
| return; | ||
| } | ||
| if (this.awaitingKickoff) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
I would move this logic out of here, and instead up to line 977. Reasons:
- When
toStopClockis true, we don't care about these constraints, they are superseded by the other logic aboutisClockRunningetc - Weird to have a function
doTimeoutthat doesn't always do a timeout.
Also, for some of these (punt) we probably want "fewer timeouts" rather than "absolutely no timeouts".
If this logic becomes too complex, abstract into its own function. Like shouldCallTimeout which takes down, distance, clock, quarter, score, etc. and returns a boolean (or undefined/"toStopClock"/"other". Cleaner. Because ultimately to do a good job with timeout logic (especially for the clock management ones) it'll need to be a little complex.
| if (playType === "extraPoint" || playType === "twoPointConversion") { | ||
| return; | ||
| } | ||
| if (this.awaitingKickoff) { |
There was a problem hiding this comment.
If this.awaitingKickoff is defined, that means the next play will be "kickoff" or "onsideKick" so just use those playTypes directly in your logic.
If the goal is to detect the first play of a drive, I'm not sure if there is a simple way to do that right now, so you could add some new variable similar to the awaiting* ones.
add test cases for doTimeout and make it so its impossible to call timeouts in scenarios where its not allowed (XP, 2pt conversion, during kickoff, before kickoff (I believe is managed by the awaiting Kickoff variable?)