Safe Haskell | None |
---|
A monad for working with game trees.
- data GoT m a
- type GoM = GoT Identity
- runGoT :: Monad m => GoT m a -> Cursor -> m (a, Cursor)
- runGo :: GoM a -> Cursor -> (a, Cursor)
- evalGoT :: Monad m => GoT m a -> Cursor -> m a
- evalGo :: GoM a -> Cursor -> a
- execGoT :: Monad m => GoT m a -> Cursor -> m Cursor
- execGo :: GoM a -> Cursor -> Cursor
- getCursor :: MonadGo go => go Cursor
- getCoordState :: MonadGo go => Coord -> go CoordState
- data Step
- goUp :: MonadGo go => go ()
- goDown :: MonadGo go => Int -> go ()
- goToRoot :: MonadGo go => go ()
- goToGameInfoNode :: MonadGo go => Bool -> go Bool
- pushPosition :: MonadGo go => go ()
- popPosition :: MonadGo go => go ()
- dropPosition :: MonadGo go => go ()
- getProperties :: MonadGo go => go [Property]
- modifyProperties :: MonadGo go => ([Property] -> go [Property]) -> go ()
- getProperty :: (MonadGo go, Descriptor d) => d -> go (Maybe Property)
- getPropertyValue :: (MonadGo go, ValuedDescriptor d v) => d -> go (Maybe v)
- putProperty :: MonadGo go => Property -> go ()
- deleteProperty :: (MonadGo go, Descriptor d) => d -> go ()
- modifyProperty :: (MonadGo go, Descriptor d) => d -> (Maybe Property -> Maybe Property) -> go ()
- modifyPropertyValue :: (MonadGo go, ValuedDescriptor d v) => d -> (Maybe v -> Maybe v) -> go ()
- modifyPropertyString :: (MonadGo go, Stringlike s, ValuedDescriptor d s) => d -> (String -> String) -> go ()
- modifyPropertyCoords :: (MonadGo go, ValuedDescriptor d CoordList) => d -> ([Coord] -> [Coord]) -> go ()
- modifyGameInfo :: MonadGo go => (GameInfo -> GameInfo) -> go GameInfo
- modifyVariationMode :: MonadGo go => (VariationMode -> VariationMode) -> go ()
- getMark :: MonadGo go => Coord -> go (Maybe Mark)
- modifyMark :: MonadGo go => (Maybe Mark -> Maybe Mark) -> Coord -> go ()
- addChild :: MonadGo go => Int -> Node -> go ()
- data Event go h
- on :: MonadGo go => Event go h -> h -> go ()
- fire :: Monad m => Event (GoT m) h -> (h -> GoT m ()) -> GoT m ()
- childAddedEvent :: Event go (ChildAddedHandler go)
- type ChildAddedHandler go = Int -> Cursor -> go ()
- gameInfoChangedEvent :: Event go (GameInfoChangedHandler go)
- type GameInfoChangedHandler go = GameInfo -> GameInfo -> go ()
- navigationEvent :: Event go (NavigationHandler go)
- type NavigationHandler go = Step -> go ()
- propertiesModifiedEvent :: Event go (PropertiesModifiedHandler go)
- type PropertiesModifiedHandler go = [Property] -> [Property] -> go ()
- variationModeChangedEvent :: Event go (VariationModeChangedHandler go)
- type VariationModeChangedHandler go = VariationMode -> VariationMode -> go ()
The Go monad
The regular monad transformer for MonadGo
.
MonadTrans GoT | |
MonadWriter w m => MonadWriter w (GoT m) | |
Monad m => Monad (GoT m) | |
Monad m => Functor (GoT m) | |
Monad m => Applicative (GoT m) | |
MonadIO m => MonadIO (GoT m) |
runGoT :: Monad m => GoT m a -> Cursor -> m (a, Cursor)Source
Executes a Go monad transformer on a cursor, returning in the underlying monad a tuple that contains the resulting value and the final cursor.
evalGoT :: Monad m => GoT m a -> Cursor -> m aSource
Executes a Go monad transformer on a cursor, returning in the underlying monad the value in the transformer.
execGoT :: Monad m => GoT m a -> Cursor -> m CursorSource
Executes a Go monad transformer on a cursor, returning in the underlying monad the final cursor.
getCoordState :: MonadGo go => Coord -> go CoordStateSource
Returns the CoordState
at the given point.
Navigation
A single step along a game tree. Either up or down.
goUp :: MonadGo go => go ()Source
Navigates up the tree. It must be valid to do so, otherwise fail
is
called. Fires a navigationEvent
after moving.
goDown :: MonadGo go => Int -> go ()Source
Navigates down the tree to the child with the given index. The child
must exist. Fires a navigationEvent
after moving.
goToRoot :: MonadGo go => go ()Source
Navigates up to the root of the tree. Fires navigationEvent
s for each
step.
:: MonadGo go | |
=> Bool | When no node with game info is found, then if false, return to the original node, otherwise finish at the root node. |
-> go Bool |
Navigates up the tree to the node containing game info properties, if any. Returns true if a game info node was found.
Remembering positions
pushPosition :: MonadGo go => go ()Source
Pushes the current location in the game tree onto an internal position
stack, such that popPosition
is capable of navigating back to the same
position, even if the game tree has been modified (though the old position
must still exist in the tree to return to it).
popPosition :: MonadGo go => go ()Source
Returns to the last position pushed onto the internal position stack via
pushPosition
. This action must be balanced by a pushPosition
.
dropPosition :: MonadGo go => go ()Source
Drops the last position pushed onto the internal stack by pushPosition
off of the stack. This action must be balanced by a pushPosition
.
Properties
getProperties :: MonadGo go => go [Property]Source
Returns the set of properties on the current node.
modifyProperties :: MonadGo go => ([Property] -> go [Property]) -> go ()Source
Modifies the set of properties on the current node.
The given function must end on the same node on which it started.
getProperty :: (MonadGo go, Descriptor d) => d -> go (Maybe Property)Source
Searches for a property on the current node, returning it if found.
getPropertyValue :: (MonadGo go, ValuedDescriptor d v) => d -> go (Maybe v)Source
Searches for a valued property on the current node, returning its value if found.
putProperty :: MonadGo go => Property -> go ()Source
Sets a property on the current node, replacing an existing property with the same name, if one exists.
deleteProperty :: (MonadGo go, Descriptor d) => d -> go ()Source
Deletes a property from the current node, if it's set.
Note that although a Property
is a Descriptor
, giving a valued
Property
here will not cause deletion to match on the value of the
property. That is, the following code will result in Nothing
, because
the deletion only cares about the name of the property.
do putProperty $ PL Black deleteProperty $ PL White getPropertyValue propertyPL
modifyProperty :: (MonadGo go, Descriptor d) => d -> (Maybe Property -> Maybe Property) -> go ()Source
modifyPropertyValue :: (MonadGo go, ValuedDescriptor d v) => d -> (Maybe v -> Maybe v) -> go ()Source
Calls the given function to modify the state of the given valued property
(descriptor) on the current node. Nothing
represents the property not
existing on the node, and a Just
with the property's value marks the
property's presence. This function does not do any validation to check
that the resulting tree state is valid.
modifyPropertyString :: (MonadGo go, Stringlike s, ValuedDescriptor d s) => d -> (String -> String) -> go ()Source
Mutates the string-valued property attached to the current node according to the given function. The input string will be empty if the current node either has the property with an empty value, or doesn't have the property. Returning an empty string removes the property from the node, if it was set.
modifyPropertyCoords :: (MonadGo go, ValuedDescriptor d CoordList) => d -> ([Coord] -> [Coord]) -> go ()Source
Mutates the CoordList
-valued property attached to the current node
according to the given function. Conversion between CoordList
and
[Coord]
is performed automatically. The input list will be empty if the
current node either has the property with an empty value, or doesn't have
the property. Returning an empty list removes the property from the node,
if it was set.
Importantly, this might not be specific enough for properties such as DD
and VW
where a present, empty list has different semantics from the
property not being present. In that case, modifyPropertyValue
is better.
modifyGameInfo :: MonadGo go => (GameInfo -> GameInfo) -> go GameInfoSource
Mutates the game info for the current path, returning the new info. If the current node or one of its ancestors has game info properties, then that node is modified. Otherwise, properties are inserted on the root node.
modifyVariationMode :: MonadGo go => (VariationMode -> VariationMode) -> go ()Source
Sets the game's VariationMode
via the ST
property on the root node,
then fires a variationModeChangedEvent
if the variation mode has changed.
getMark :: MonadGo go => Coord -> go (Maybe Mark)Source
Returns the Mark
at a point on the current node.
modifyMark :: MonadGo go => (Maybe Mark -> Maybe Mark) -> Coord -> go ()Source
Calls the given function to modify the presence of a Mark
on the
current node.
Children
addChild :: MonadGo go => Int -> Node -> go ()Source
Adds a child node to the current node at the given index, shifting all
existing children at and after the index to the right. The index must in
the range [0, numberOfChildren]
. Fires a childAddedEvent
after the
child is added.
Event handling
A type of event in the Go monad transformer that can be handled by
executing an action. go
is the type of the type of the Go
monad/transformer. h
is the type of monad or monadic function which will
be used by Go actions that can trigger the event. For example, a navigation
event is characterized by a Step
that cannot easily be recovered from the
regular monad state, and comparing before-and-after states would be a pain.
So h
for navigation events is
; a handler takes a Step
-> go ()Step
and returns a Go action to run as a result.
on :: MonadGo go => Event go h -> h -> go ()Source
Registers a new event handler for a given event type.
fire :: Monad m => Event (GoT m) h -> (h -> GoT m ()) -> GoT m ()Source
Fires all of the handlers for the given event, using the given function to create a Go action from each of the handlers (normally themselves functions that create Go actions, if they're not just Go actions directly, depending on the event).
Events
childAddedEvent :: Event go (ChildAddedHandler go)Source
An event corresponding to a child node being added to the current node.
type ChildAddedHandler go = Int -> Cursor -> go ()Source
A handler for childAddedEvent
s.
gameInfoChangedEvent :: Event go (GameInfoChangedHandler go)Source
An event that is fired when the current game info changes, either by navigating past a node with game info properties, or by modifying the current game info properties.
type GameInfoChangedHandler go = GameInfo -> GameInfo -> go ()Source
A handler for gameInfoChangedEvent
s. It is called with the old game info
then the new game info.
navigationEvent :: Event go (NavigationHandler go)Source
An event that is fired when a single step up or down in a game tree is made.
type NavigationHandler go = Step -> go ()Source
A handler for navigationEvent
s.
A navigation handler may navigate further, but beware infinite recursion. A navigation handler must end on the same node on which it started.
propertiesModifiedEvent :: Event go (PropertiesModifiedHandler go)Source
An event corresponding to a modification to the properties list of the current node.
type PropertiesModifiedHandler go = [Property] -> [Property] -> go ()Source
A handler for propertiesModifiedEvent
s. It is called with the old
property list then the new property list.
variationModeChangedEvent :: Event go (VariationModeChangedHandler go)Source
An event corresponding to a change in the active VariationMode
. This can
happen when modifying the ST
property, and also when navigating between
collections (as they have different root nodes).
type VariationModeChangedHandler go = VariationMode -> VariationMode -> go ()Source
A handler for variationModeChangedEvent
s. It is called with the old
variation mode then the new variation mode.