module Game.Chess.Tree (positionTree, positionForest, plyTree, plyForest) where

import           Data.Tree           (Forest, Tree (Node))
import           Game.Chess.Internal

positionTree :: Position -> Tree Position
positionTree :: Position -> Tree Position
positionTree Position
pos = forall a. a -> [Tree a] -> Tree a
Node Position
pos forall a b. (a -> b) -> a -> b
$ Position -> Forest Position
positionForest Position
pos

positionForest :: Position -> Forest Position
positionForest :: Position -> Forest Position
positionForest Position
pos = Position -> Tree Position
positionTree forall b c a. (b -> c) -> (a -> b) -> a -> c
. Position -> Ply -> Position
unsafeDoPly Position
pos forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Position -> [Ply]
legalPlies Position
pos

plyForest :: Position -> Forest Ply
plyForest :: Position -> Forest Ply
plyForest Position
pos = Position -> Ply -> Tree Ply
plyTree Position
pos forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Position -> [Ply]
legalPlies Position
pos

plyTree :: Position -> Ply -> Tree Ply
plyTree :: Position -> Ply -> Tree Ply
plyTree Position
pos Ply
ply = forall a. a -> [Tree a] -> Tree a
Node Ply
ply forall b c a. (b -> c) -> (a -> b) -> a -> c
. Position -> Forest Ply
plyForest forall a b. (a -> b) -> a -> b
$ Position -> Ply -> Position
unsafeDoPly Position
pos Ply
ply