bishbosh- Plays chess.

Safe HaskellNone




Dr. Alistair Ward
  • Defines chess as a constant tree of all possible moves.
  • Because of the conceptually infinite size of this data-structure, care must be taken not to attempt to call show, '(==)', ...




type MoveFrequency x y = MoveFrequency (Move x y) Source #

Focus the underlying type.


data GameTree x y Source #

Wrap a BareGameTree.


(Show y, Show x, Ord y, Ord x, Enum y, Enum x) => Show (GameTree x y) Source # 


showsPrec :: Int -> GameTree x y -> ShowS #

show :: GameTree x y -> String #

showList :: [GameTree x y] -> ShowS #

(Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Default (GameTree x y) Source # 


def :: GameTree x y #

Prunable (GameTree x y) Source # 


prune :: Depth -> GameTree x y -> GameTree x y Source #

(Enum x, Enum y) => ShowNotation (GameTree x y) Source # 


countGames :: Depth -> NGames Source #

  • Counts the number of game-states in the constant game of chess, at the specified depth, including any which terminated earlier.
  • N.B.: some of the game-states may have identical positions, reached by different sequences of moves.

countMoves :: Depth -> NGames Source #

Counts the number of possible plies in chess, down to the specified depth.

traceRoute Source #


:: (Eq x, Eq y) 
=> GameTree x y 
-> [Turn x y]

The data against which, nodes from the tree should be matched.

-> Maybe [Game x y]

Returns Nothing on match-failure.

Trace the route down the tree which matches the specified list of turns.

sortGameTree Source #


:: (Integral x, Integral y, Num rankValue, Ord rankValue) 
=> Bool


-> Maybe CaptureMoveSortAlgorithm 
-> EvaluateRank rankValue 
-> MoveFrequency x y 
-> Transformation x y 
  • Independently sorts the forest of moves at each node of the tree, without regard to runtime-data.
  • Depending on preferences, the list of moves available to each game is sequentially sorted by: those which reduce the radius from the centre of the board. either those which capture a valuable piece using a cheap piece, or those which win extended battles at a specific location.
  • The above sort-algorithms are stable & can therefore be applied independently.

toMoveFrequency :: (Ord x, Ord y) => GameTree x y -> MoveFrequency x y Source #

  • Count the instances of each move in the specified tree, including any pre-applied to the apex game.
  • CAVEAT: ambiguity remains regarding the move-type (especially any piece taken).
  • CAVEAT: a node is counted as just one instance of the move, rather than the number of games which passed through that node. Had the move-frequency been derived from a list of games, a different distribution would result, but then early moves would appear popular rather than just the consequence of limited choice.


fromBareGameTree :: BareGameTree x y -> GameTree x y Source #


fromGame :: (Enum x, Enum y, Ord x, Ord y, Show x, Show y) => Game x y -> GameTree x y Source #

Constructs a game-tree with the specified game at its root.