Skip to content

Instantly share code, notes, and snippets.

@Wilfred
Created February 28, 2014 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wilfred/9277045 to your computer and use it in GitHub Desktop.
Save Wilfred/9277045 to your computer and use it in GitHub Desktop.
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