cx-0.1.0.0: Chess eXperiment

Safe HaskellNone
LanguageHaskell2010

Game.Chess.Position

Synopsis

Documentation

movePosition :: (Int, Int) -> Position -> Maybe Position #

Given a position vector in the form (file, rank), add it to a given Position, and return the result so long as we remain in a valid Position.

apVector :: MovingVector Int -> Position -> [(MovingVector Int, Position)] #

Given a MovingVector Int and a starting Position, "slide" the piece to each square recursively in the direction of moving vector. Note that here we don't take into account whether or not the move is actually valid, other than ensuring that we remain on the board.

apVectors :: [MovingVector Int] -> Position -> [[(MovingVector Int, Position)]] #

Given a list of moving vectors and a position, return a list of lists, where each inner list contains possible (unvalidated) moves in each possible direction.

getValidSlidingMoves #

Arguments

:: Board

The current game state

-> Position

The originating position

-> [(MovingVector Int, Position)]

A list of unvalidated positions

-> [Position]

A list of validated positions

Given a Board and a list of unvalidated Positions we might want to move to, validate each position and see if we can, in fact, move there. In the future, the validator will need to know the kind of Piece being moved so it can check for things like the moving side being in check.

This function lets us move up until a move becomes invalid.

The third parameter carries along a MovingVector Int which is used for validation later on. Namely, it is used for as a justification for why a particular position has been reached. This is important because we must handle pawns differently due to how they capture, although there might be a cleaner approach.

getValidMoves :: Board -> [MovingVector Int] -> Position -> [Position] #

Given a Board, a list of moving vectors, and the Position that we are currently at, return a list of validated positions to which we can move.

This basically just combines all of the above machinery into an easy-to-use function that we can use in generate below.

isAttacked :: Board -> Position -> Position -> [MovingVector Int] -> Bool #

Given a Board, an origin Position, a query Position and a list of moving vectors, determine whether or not the query Position is currently under attack.

We generate a list of valid moves, and simply determine if the query position is one of those moves. Note that this does _NOT_ yet account for pawn-takes.

This can be specialized to test for check.

validateMove #

Arguments

:: Board

The current game state

-> MovingVector Int

The MovingVector that made us go to the Position

-> Position

The originating position

-> Position

The new Position we would go to

-> MoveValidity 

Can the given move legally be made?

It checks the following things:

  • We are not trying to move from an empty square.
  • The moving side cannot capture/land on its own piece.
  • (TODO!) The move will not place the moving side in check.
  • We are not capturing a king.
  • We are not moving a piece that is not ours.
  • A pawn can only move diagonally if it is capturing (legally).

getValidSingleMovePieceMoves :: Board -> Position -> [MovingVector Int] -> [Position] #

Given a current Position and a list of 'Moving Vector' Int, assume that the piece is NOT a sliding one and generate the list of valid Positions to which it can move.

generate :: Board -> Position -> [Board] #

Move generation!

allMoves :: Board -> [Board] #

Determine possible moves for the side to move.

movesTree :: Board -> Int -> GameTree #

Generate a GameTree by calling allMoves the appropriate number of times depending on the depth.