Skip to content

Instantly share code, notes, and snippets.

@evancz evancz/chess.elm
Created Sep 8, 2016

Embed
What would you like to do?
import Dict exposing (Dict)
import Html exposing (..)
type Rank = King | Queen | Bishop | Knight | Rook | Pawn
type Color = Black | White
type alias Piece =
{ rank : Rank
, color : Color
}
type alias Board =
Dict (Int, Int) Piece
view : Board -> Html msg
view board =
div [] (List.map (viewSquare board) [0..7])
viewRow : Board -> Int -> Html msg
viewRow board row =
div [] (List.map (viewSquare board row) [0..7])
viewSquare : Board -> Int -> Int -> Html msg
viewSquare board row column =
let
content =
case Dict.get (row, column) board of
Nothing ->
text ""
Just piece ->
viewPiece piece
div
[ style
[ ("color", "black")
, ("width", "100px")
, ("height", "100px")
]
]
[ content
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.