module Chess (
Chess.Internal.Board.Board,
Chess.Internal.Board.Coordinates,
Chess.Internal.Board.Square(..),
Chess.Internal.Move.GameState,
Chess.Internal.Move.currentPlayer,
Chess.Internal.Piece.Color(..),
Chess.Internal.Piece.Piece(..),
Chess.Internal.Piece.PieceType(..),
Chess.Internal.Move.Move,
board,
fullMoveNumber,
isCheckmate,
isDraw,
isLegalMove,
isStalemate,
move,
newGame,
pieceAt,
winner,
legalMoves,
applyMove,
) where
import Chess.Internal.Board
import Chess.Internal.Move
import Chess.Internal.Piece
import qualified Chess.Internal.Game as G
import qualified Chess.Internal.Notation as N
isCheckmate :: GameState -> Bool
isCheckmate :: GameState -> Bool
isCheckmate = GameState -> Bool
G.isCheckmate
isStalemate :: GameState -> Bool
isStalemate :: GameState -> Bool
isStalemate = GameState -> Bool
G.isStalemate
isDraw :: GameState -> Bool
isDraw :: GameState -> Bool
isDraw = GameState -> Bool
G.isDraw
winner :: GameState -> Maybe Color
winner :: GameState -> Maybe Color
winner = GameState -> Maybe Color
G.getWinner
isLegalMove :: GameState
-> String
-> Bool
isLegalMove :: GameState -> String -> Bool
isLegalMove GameState
game String
moveStr = case GameState -> String -> Maybe Move
N.parseMove GameState
game String
moveStr of
Just Move
m -> Move
m Move -> [Move] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` GameState -> [Move]
generateAllMoves GameState
game
Maybe Move
Nothing -> Bool
False
move :: GameState
-> String
-> Maybe GameState
move :: GameState -> String -> Maybe GameState
move GameState
game String
moveStr = do Move
m <- GameState -> String -> Maybe Move
N.parseMove GameState
game String
moveStr
GameState -> Move -> Maybe GameState
applyMove GameState
game Move
m
board :: GameState -> Board
board :: GameState -> Board
board = GameState -> Board
stateBoard
newGame :: GameState
newGame :: GameState
newGame = GameState
initialState
pieceAt :: Board
-> String
-> Maybe Piece
pieceAt :: Board -> String -> Maybe Piece
pieceAt Board
b String
coordinateStr = do Coordinates
coords <- String -> Maybe Coordinates
parseCoordinate String
coordinateStr
Board -> Coordinates -> Maybe Piece
getPiece Board
b Coordinates
coords
fullMoveNumber :: GameState -> Integer
fullMoveNumber :: GameState -> Integer
fullMoveNumber = GameState -> Integer
moveNumber
legalMoves :: GameState -> [Move]
legalMoves :: GameState -> [Move]
legalMoves = GameState -> [Move]
generateAllMoves
applyMove :: GameState -> Move -> Maybe GameState
applyMove :: GameState -> Move -> Maybe GameState
applyMove GameState
game Move
m = case GameState -> Move -> Either MoveError GameState
G.applyMove GameState
game Move
m of
Left MoveError
_ -> Maybe GameState
forall a. Maybe a
Nothing
Right GameState
game' -> GameState -> Maybe GameState
forall a. a -> Maybe a
Just GameState
game'