The Square
data type and related functions and definitions.
Internal.Square
Type representing one of the 64 squares of the board.
make : SquareFile -> SquareRank -> Square
Create a square from a SquareFile
and a SquareRank
.
file : Square -> SquareFile
The file of a square.
rank : Square -> SquareRank
The rank of a square.
fromString : String -> Maybe Square
Tries to convert a String
to a Square
, by looking at the first two
characters of the string. If the two first characters are not a valid square
string, returns Nothing
.
fromString "g8" == Just g8
fromString "b1d3" == Just b1
fromString "Donald Trump" == Nothing
toString : Square -> String
Converts a Square
to a String
in standard algebraic notation
toString e4 == "e4"
fromInt : Basics.Int -> Maybe Square
Tries to convert an Int
to a Square
, using the mapping a1 <-> 0,
b1 <-> 1, ..., h8 <-> 63.
fromInt 0 == Just a1
fromInt 1 == Just b1
fromInt 63 == Just h8
fromInt -1 == Nothing
fromInt 100 == Nothing
toInt : Square -> Basics.Int
Converts a Square
to an Int
in the 0..63 range, using the mapping
a1 <-> 0, b1 <-> 1, ..., h8 <-> 63.
toInt a1 == 0
toInt b1 == 1
toInt a2 == 8
toInt h8 == 63
fileDistance : Square -> Square -> Basics.Int
The horizontal distance between two squares.
fileDistance a1 d3 == 3
fileDistance c1 c7 == 0
fileDistance h8 a3 == 7
rankDistance : Square -> Square -> Basics.Int
The vertical distance between two squares.
rankDistance a1 b4 == 3
rankDistance c2 h2 == 0
rankDistance a8 c1 == 7
distance : Square -> Square -> Basics.Int
The distance between two squares, measured as the maximum of the vertical and horizontal distances, or the number of king moves required to get from one square to the other on an empty board.
distance a1 b4 == 3
distance h8 b1 == 7
distance f3 e4 == 1
all : List Square
A list of all squares on the board.
a1 : Square
The a1 square.
b1 : Square
The b1 square.
c1 : Square
The c1 square.
d1 : Square
The d1 square.
e1 : Square
The e1 square.
f1 : Square
The f1 square.
g1 : Square
The g1 square.
h1 : Square
The h1 square.
a2 : Square
The a2 square.
b2 : Square
The b2 square.
c2 : Square
The c2 square.
d2 : Square
The d2 square.
e2 : Square
The e2 square.
f2 : Square
The f2 square.
g2 : Square
The g2 square.
h2 : Square
The h2 square.
a3 : Square
The a3 square.
b3 : Square
The b3 square.
c3 : Square
The c3 square.
d3 : Square
The d3 square.
e3 : Square
The e3 square.
f3 : Square
The f3 square.
g3 : Square
The g3 square.
h3 : Square
The h3 square.
a4 : Square
The a4 square.
b4 : Square
The b4 square.
c4 : Square
The c4 square.
d4 : Square
The d4 square.
e4 : Square
The e4 square.
f4 : Square
The f4 square.
g4 : Square
The g4 square.
h4 : Square
The h4 square.
a5 : Square
The a5 square.
b5 : Square
The b5 square.
c5 : Square
The c5 square.
d5 : Square
The d5 square.
e5 : Square
The e5 square.
f5 : Square
The f5 square.
g5 : Square
The g5 square.
h5 : Square
The h5 square.
a6 : Square
The a6 square.
b6 : Square
The b6 square.
c6 : Square
The c6 square.
d6 : Square
The d6 square.
e6 : Square
The e6 square.
f6 : Square
The f6 square.
g6 : Square
The g6 square.
h6 : Square
The h6 square.
a7 : Square
The a7 square.
b7 : Square
The b7 square.
c7 : Square
The c7 square.
d7 : Square
The d7 square.
e7 : Square
The e7 square.
f7 : Square
The f7 square.
g7 : Square
The g7 square.
h7 : Square
The h7 square.
a8 : Square
The a8 square.
b8 : Square
The b8 square.
c8 : Square
The c8 square.
d8 : Square
The d8 square.
e8 : Square
The e8 square.
f8 : Square
The f8 square.
g8 : Square
The g8 square.
h8 : Square
The h8 square.