Created
March 23, 2022 03:55
-
-
Save RoyalIcing/78eed77ca2e1908e0b90d4bf616fea1a to your computer and use it in GitHub Desktop.
Modelling Formula One qualifying as a state machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const S1Time = Symbol('S1Time'); | |
function DriverTime() { | |
function* NoTime() { | |
yield on('sector1Set', SectorTime, id('Sector1')); | |
yield on('sector2Set', SectorTime, id('Sector2')); | |
yield on('sector3Set', SectorTime, id('Sector3')); | |
} | |
function* SectorTime() { | |
const previousBest = yield read('bestTime'); | |
const newTime = yield read('duration'); | |
const runIndex = yield read('runIndex'); | |
yield cond(previousBest == null, set('bestTime', newTime)); | |
yield cond(newTime < previousBest, set('bestTime', newTime)); | |
// Or: | |
yield new Map([ | |
[previousBest == null, set('bestTime', newTime)], | |
[newTime < previousBest, set('bestTime', newTime)], | |
]); | |
} | |
return NoTime; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment