markovjs-immutable

0.1.1 • Public • Published

markovjs-immutable

npm install markovjs-immutable

Release License

This is a memory implementation for markovjs based on immutablejs.

It provides an easier way to code the observation function while adding support for immutable data structures, enforcing great design patterns on your game model code.

Usage

This package exports the required update and rater functions, alongside an init one used for getting the initial value.

import markov from 'markovjs'
import * as memory from 'markovjs-immutable'
 
const m = memory.init(0.0, a => a)
markov().memory(memory, m)

The initializer function has the following signature:

// A: action type
// G: game state type
// O: observation type
type Init = <A, G, O>(number, G=> O) => MemoryState<A, G, O>

The first parameter is the initial value for all unset memory slots.

The second one is the observe function. It maps a game state type (G) to an observation type (O). It serves the same purpose as toString does in the default memory implementation, but expecting an immutable value as the return type instead of a string.

This is one of the great things this package provides: a way for you to code your state and agent observation in a higher level letting the package figure how to store the data.

It's important to note that while the observation value needs to be immutable, your game state value does not. That said, it's encouraged that you code it as an immutable value as well.

Thanks

ImmutableJS, man. What an awesome package.

Package Sidebar

Install

npm i markovjs-immutable

Weekly Downloads

0

Version

0.1.1

License

MIT

Last publish

Collaborators

  • lsunsi