pilatch / elm-chess / PieceColor

This module defines the PieceColor type and related functions.

Types


type alias PieceColor =
Internal.PieceColor

Type representing the color of a chess piece, or one of the two players.

Useful Constants

white : PieceColor

The color of a white piece.

black : PieceColor

The color of a black piece.

all : List PieceColor

List of all piece colors.

all == [ white, black ]

Inverting a Color

opposite : PieceColor -> PieceColor

The opposite of a color.

opposite white == black

opposite black == white

Converting to Strings and Characters

fromChar : Char -> Maybe PieceColor

Tries to convert a character to a PieceColor, using Forsyth-Edwards encoding. fromChar 'w' == Just white fromChar 'b' == Just black fromChar ch == Nothing -- for all ch not equal to 'w' or 'b'

fromString : String -> Maybe PieceColor

Tries to convert a string to a PieceColor, using Forsyth-Edwards encoding. fromString "w" == Just white fromString "b" == Just black fromString str == Nothing -- for all str not starting with "w" or "b"

toChar : PieceColor -> Char

Convert a PieceColor to a Char of the form used when representing a board in Forsyth-Edwards notation.

toChar white == 'w'

toChar black == 'b'

toString : PieceColor -> String

Convert a PieceColor to a single-character String containing a Char of the form used when representing a board in Forsyth-Edwards notation.

toChar white == "w"

toChar black == "b"