Created
February 28, 2014 18:43
-
-
Save Wilfred/9277045 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Array | |
data Piece = | |
Pawn | Rook | Knight | Bishop | Queen | King | Empty | |
deriving Show | |
type Board = [[Piece]] | |
emptyRow = [Empty | x <- [0..7]] | |
emptyBoard = [emptyRow | x <- [0..7]] | |
pieceAt :: Board -> Int -> Int -> Piece | |
pieceAt board row column = (board !! row) !! column | |
replace :: [a] -> a -> Int -> [a] | |
replace (x:xs) el 0 = (el:xs) | |
replace (x:xs) el index = replace xs el (index-1) | |
putPieceAt :: Board -> Piece -> Int -> Int -> Board | |
putPieceAt board piece rowIndex column = | |
let oldRow = board !! rowIndex | |
newRow = replace oldRow piece column | |
in | |
replace board newRow rowIndex | |
rowIsEmpty :: [Piece] -> Bool | |
rowIsEmpty [] = True | |
rowIsEmpty (p:ps) = | |
case p of | |
Empty -> rowIsEmpty ps | |
_ -> False | |
-- the moves possible for the piece at row, column | |
nextMoves board row column = | |
case pieceAt board row column of | |
Rook -> [] | |
Empty -> [] | |
_ -> error "Not implemented yet!" | |
main = putStrLn "hello world" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment