chess960 in OCaml — Printing Positions
let string_of_piece = function
| R -> "R" | N -> "N" | B -> "B" | Q -> "Q" | K -> "K"
let string_of_position = (String.concat "") & map string_of_piece
let print = iter (print_endline & string_of_position)
Converting Pieces to Strings
# let string_of_piece = function
| R -> "R" | N -> "N" | B -> "B" | Q -> "Q" | K -> "K";;
val string_of_piece : piece -> string = <fun>
# string_of_piece B;;
- : string = "B"
# string_of_piece K;;
- : string = "K"
Converting Positions to Strings
# let string_of_position = (String.concat "") & map string_of_piece;;
val string_of_position : piece list -> string = <fun>
# map string_of_piece [R; N; B; Q; K; B; N; R];;
- : string list = ["R"; "N"; "B"; "Q"; "K"; "B"; "N"; "R"]
# ((String.concat "") & map string_of_piece) [R; N; B; Q; K; B; N; R];;
- : string = "RNBQKBNR"
# string_of_position [R; N; B; Q; K; B; N; R];;
- : string = "RNBQKBNR"
Printing Positions
# let print = iter (print_endline & string_of_position);;
val print : piece list list -> unit = <fun>
# (print_endline & string_of_position) [R; N; B; Q; K; B; N; R];;
RNBQKBNR
- : unit = ()
# print [[R; N; B; Q; K; B; N; R]];;
RNBQKBNR
- : unit = ()
# print [[R; N; B; Q; K; B; N; R]; [N; R; B; Q; K; B; N; R]];;
RNBQKBNR
NRBQKBNR
- : unit = ()
#