{ 13_search_strategies.pas -- picking and using a move-selection
  strategy. Pascal translation of ../examples/13_search_strategies.c.

  Functions/globals demonstrated:
    ssv[c_w], ssv[c_b] -- which strategy is active for each color
    SANSelect()        -- ask the active strategy to choose a move
                          for the side to move, storing it in
                          select_m
    SANPlayMove(@select_m) -- play the chosen move

  select_m (sankit.pas) is a real, typed TMove global -- the same
  record type curr_g.g_base[] uses in 04_move_generation.pas --
  taken by address and handed to SANEncode()/SANPlayMove() the same
  way a pointer into curr_g.g_base would be. }

program search_strategies;

uses
  SanKit;

function PadRight(const s: string; Width: Integer): string;
begin
  PadRight := s;
  while Length(PadRight) < Width do
    PadRight := PadRight + ' ';
end;

var
  i: Integer;
  san: TSanBuf;

begin
  SANInit;
  optnv[optn_nabd] := 1;
  optnv[optn_namd] := 1;

  { let the "eat" strategy (its own default) play White, and the
    "random" strategy play Black }
  ssv[c_w] := ss_eat;
  ssv[c_b] := ss_ran;

  WriteLn('White: ', ssstrv[ssv[c_w]], '   Black: ', ssstrv[ssv[c_b]]);
  WriteLn;

  for i := 0 to 9 do
    begin
      SANSelect;                          { fills in select_m }
      FillChar(san, SizeOf(san), 0);
      SANEncode(PMove(@select_m), SanBufPtr(san));   { look at it first }
      SANPlayMove(PMove(@select_m));                 { then commit to it }
      WriteLn(i + 1: 2, '. ', PadRight(SanBufPtr(san), 8),
              ' (chosen by ', ssstrv[ssv[curr_e.e_pasc]], ')');
    end;

  WriteLn;
  WriteLn('Final position: ', SANFENGen);
end.
