Skip to content

v2.0.0

Choose a tag to compare

@bracketdash bracketdash released this 02 Aug 19:15
· 2 commits to main since this release

new MinnieMax(config)

Config object properties:

  • el:
    Required. Mounting element for the control bar.

  • localStorageKey:
    Required. Key to use for localStorage.

  • initialMovesAhead:
    Required. Number of moves to simulate in the minimax search.

  • initialState:
    Required. The initial game state.

  • getMoves({ minnie, state, player }):
    Required. Returns an array of all legal moves for the given player and state.

  • getNextState({ minnie, state, player, move }):
    Required. Returns a new { state, player } after applying the move.

  • getStateScore({ minnie, state, player, movesRemaining }):
    Required. Returns a numeric score for the given state from the perspective of the given player.

  • isGameOver({ minnie, state }):
    Required. Returns true if the game is over in the given state.

  • onChange({ minnie }):
    Optional. Fires after a change to movesAhead or the game state.

  • onReady({ minnie }):
    Optional. Fires after the control bar has been mounted.

getScoredMoves(state, player): Promise<Array<{ move, score }>>

Returns a Promise that resolves to an array of all legal moves for the given state and player, each paired with a numeric score. The returned array is sorted in descending order of score (best moves first).

getState(): { state, player }

Returns the current game state.

pushState(state, player)

Adds the given state and player to the game history and stores it in localStorage.