{ custom_board.pas -- a board display written entirely in Pascal, in
  a different style from the library's own SANDspBoard() (a bordered
  grid with file/rank labels, one character per square, uppercase
  for White and lowercase for Black, instead of SANDspBoard()'s
  compact two-character-per-square "wPbP::" layout).

  This needs no new bindings at all beyond what 02_setup_position.pas
  already established: SANGetSq() to read a square's color-piece
  code, and accv[]/acpv[]/cv_c_cpv[]/cv_p_cpv[] to turn that code
  into a color and a piece letter. The square numbering itself
  (map_sq_rank_file(rank, file) = (rank shl 3) or file, sandef.h) is
  pure arithmetic, reproduced directly here the same way
  MapFileSq()/MapRankSq() were in position_status.pas -- nothing
  about it needs a C function of its own either.

  Note: "file" is a reserved word in Pascal (the FILE type), so the
  loop variable below is called "fl" instead, purely to avoid that
  clash -- it means exactly the same thing sandef.h's own file does. }

program custom_board;

uses
  SanKit;

procedure PrintBoard;
var
  rank, fl, sq, cp: Integer;
  ch: Char;
begin
  WriteLn('    a   b   c   d   e   f   g   h');
  WriteLn('  +---+---+---+---+---+---+---+---+');

  for rank := 7 downto 0 do
    begin
      Write(rank + 1, ' |');
      for fl := 0 to 7 do
        begin
          sq := (rank shl 3) or fl;        { map_sq_rank_file(rank, fl) }
          cp := SANGetSq(sq);

          if cp = cp_v0 then
            ch := '.'
          else
            begin
              ch := acpv[cv_p_cpv[cp]];
              if cv_c_cpv[cp] = c_b then
                ch := Chr(Ord(ch) + 32);    { lowercase for Black }
            end;

          Write(' ', ch, ' |');
        end;
      WriteLn(' ', rank + 1);
      WriteLn('  +---+---+---+---+---+---+---+---+');
    end;

  WriteLn('    a   b   c   d   e   f   g   h');
end;

begin
  SANInit;

  WriteLn('Starting position:');
  PrintBoard;

  WriteLn;
  WriteLn('After 1.e4 e5 2.Nf3 Nc6 3.Bb5 (the Ruy Lopez):');
  SANFENSet(
    'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3');
  PrintBoard;
end.
