Skip to content

Instantly share code, notes, and snippets.

@evancz
Created September 8, 2016 04:58
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 evancz/c18fe62d42b16b80132426b36f9d1349 to your computer and use it in GitHub Desktop.
Save evancz/c18fe62d42b16b80132426b36f9d1349 to your computer and use it in GitHub Desktop.
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