Files
functional-programming-snake/js/src/game.js
T

27 lines
1.2 KiB
JavaScript

import { todo } from './todo.js'
/**
* How many frames pass between game steps (m10): `max(2, 8 - floor(score / 3))`.
* Score 0-2 -> 8, 3-5 -> 7, ..., 18 and up -> 2.
*/
export const movesEvery = (score) => todo('m10')
/**
* The one function that says how the game changes: `(state, action) -> state`.
*
* m05: `Tick` runs a game step (`tick`), `Turn` asks to change direction (`turn`);
* every other action returns the state unchanged.
*
* (m10) `TogglePause` switches Playing <-> Paused and does nothing in any other status.
* (m10) `Restart` gives `newGame(state.seed)`, whatever the status.
* (m10) `Frame` does nothing unless Playing; otherwise it adds 1 to `frame`, and when the new `frame` is a multiple of
* `movesEvery(score)` it also runs a game step (`tick`) on that incremented state.
*/
export const update = (state, action) => todo('m05')
/** Apply all actions in order, starting from `state`, and return the final state. */
export const replay = (state, actions) => todo('m05')
/** Like `replay`, but keep every state: `[state, afterFirst, afterSecond, ...]`, so its length is `actions.length + 1`. */
export const history = (state, actions) => todo('m05')