Current section
Files
Jump to
Current section
Files
src/piece.erl
-module(piece).
-compile([no_auto_import, nowarn_unused_vars]).
-export([to_string/1]).
-export_type([piece/0, kind/0]).
-type piece() :: {piece, color:color(), kind()}.
-type kind() :: pawn | knight | bishop | rook | queen | king.
-spec to_string(piece()) -> binary().
to_string(Piece) ->
Kind = case erlang:element(3, Piece) of
pawn ->
<<"Pawn"/utf8>>;
knight ->
<<"Knight"/utf8>>;
bishop ->
<<"Bishop"/utf8>>;
rook ->
<<"Rook"/utf8>>;
queen ->
<<"Queen"/utf8>>;
king ->
<<"King"/utf8>>
end,
Color = case erlang:element(2, Piece) of
white ->
color:to_string(white);
black ->
color:to_string(black)
end,
<<<<Color/binary, " "/utf8>>/binary, Kind/binary>>.