Safe Haskell | None |
---|---|
Language | Haskell2010 |
- movePosition :: (Int, Int) -> Position -> Maybe Position
- apVector :: MovingVector Int -> Position -> [(MovingVector Int, Position)]
- apVectors :: [MovingVector Int] -> Position -> [[(MovingVector Int, Position)]]
- getValidSlidingMoves :: Board -> Position -> [(MovingVector Int, Position)] -> [Position]
- getValidMoves :: Board -> [MovingVector Int] -> Position -> [Position]
- isAttacked :: Board -> Position -> Position -> [MovingVector Int] -> Bool
- validateMove :: Board -> MovingVector Int -> Position -> Position -> MoveValidity
- getValidSingleMovePieceMoves :: Board -> Position -> [MovingVector Int] -> [Position]
- generate :: Board -> Position -> [Board]
- allMoves :: Board -> [Board]
- movesTree :: Board -> Int -> GameTree
- generateSuggestion :: Board -> Int -> Board
Documentation
apVector :: MovingVector Int -> Position -> [(MovingVector Int, Position)] #
Given a
and a starting MovingVector
Int
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.
:: 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
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.MovingVector
Int
getValidMoves :: Board -> [MovingVector Int] -> Position -> [Position] #
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.
:: Board | The current game state |
-> MovingVector Int | The |
-> Position | The originating position |
-> Position | The new |
-> 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] #
generateSuggestion :: Board -> Int -> Board #