pilatch / elm-chess / SquareFile

The SquareFile data type and related functions and definitions.

Types


type alias SquareFile =
Internal.SquareFile

SquareFile is a type representing a file on a chess board, i.e. one of the vertical columns labeled a-h.

Converting to and from Strings and Characters

fromChar : Char -> Maybe SquareFile

Tries to convert a Char to a SquareFile. Returns Nothing if the character is not a lowercase letter in the range a-h.

fromChar 'e' == Just e

List.map fromChar [ 'a', 'x', 'h' ] == [ Just a, Nothing, Just h ]

fromString : String -> Maybe SquareFile

Tries to convert a String to a SquareFile by looking at the first character of the string. Returns Nothing if the first character is not a lowercase letter in the range a-h.

fromString "e" == Just e

List.map fromChar [ "a", "x", "h" ] == [ Just a, Nothing, Just h ]

toChar : SquareFile -> Char

Converts a SquareFile to a Char in the range a-h.

toChar c == 'c'

List.map toChar all == [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' ]

toString : SquareFile -> String

Converts a SquareFile to a single-character String consisting of a letter in the range a-h.

toString c == "c"

List.map toString all == [ "a", "b", "c", "d", "e", "f", "g", "h" ]

Miscellaneous Useful Constants

all : List SquareFile

List of all files on the board.

a : SquareFile

The 'a' file, the first file from the left, from white's point of view.

b : SquareFile

The 'b' file, the second file from the left, from white's point of view.

c : SquareFile

The 'c' file, the third file from the left, from white's point of view.

d : SquareFile

The 'd' file, the fourth file from the left, from white's point of view.

e : SquareFile

The 'e' file, the fifth file from the left, from white's point of view.

f : SquareFile

The 'f' file, the sixth file from the left, from white's point of view.

g : SquareFile

The 'g' file, the seventh file from the left, from white's point of view.

h : SquareFile

The 'h' file, the eighth file from the left, from white's point of view.

Miscellaneous Functions

distance : SquareFile -> SquareFile -> Basics.Int

The horizontal distance between two files.

distance a h == 7

distance e c == 2

toIndex : SquareFile -> Basics.Int

Convert a file to an index in the range 0 (for the 'a' file) to 7 (for the 'h' file).