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