Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Haskell library for creating simple deterministic games, such as tic-tac-toe. The engine requires a minimal set of actions related to the game, and then will run the game until a terminal state is reached.
Simple generic example below. See the specs for a more detailed example.
import Game.Deterministic.GameEngine game :: Monad m => GameEngine m Int Int game = GameEngine gameActions initialState gameActions :: Monad m => GameActions m Int Int gameActions = GameActions { getPlayer = -- find the next player from a game state, getMove = -- find a move from the game state, getResult = -- transitions from a state to another state, isTerminal = -- determines if the game is terminal, getScore = -- get score from a terminal state } initialState :: GameState Int initialState = GameState 0 -- run the game engine until a terminal state is reached playSimple game
- type Symbol = Char
- data GameState a = GameState a
- data Player = Player Symbol
- data Move a = Move a
- data GameActions m a b = GameActions {}
- data GameEngine m a b = GameEngine {
- actions :: GameActions m a b
- state :: GameState a
- type GameEngineSimple a b = GameEngine Identity a b
- type GameEngineIO a b = GameEngine IO a b
- play :: Monad m => GameEngine m a b -> m Int
- playSimple :: GameEngineSimple a b -> Int
- playIO :: GameEngineIO a b -> IO Int
Documentation
data GameActions m a b Source
Set of actions that defines how the game will be played
GameActions | |
|
data GameEngine m a b Source
Holds information about how the game is played, and the current state of the game.
GameEngine | |
|
type GameEngineSimple a b = GameEngine Identity a b Source
type GameEngineIO a b = GameEngine IO a b Source
play :: Monad m => GameEngine m a b -> m Int Source
Run the provided game engine under a monadic context until a terminal state is reached.
playSimple :: GameEngineSimple a b -> Int Source
Run the provided game engine without a context until a terminal state is reached.
playIO :: GameEngineIO a b -> IO Int Source
Run the provided game engine within an IO context until a terminal state is reached.