Advertisement
WarPie90

Untitled

Aug 1st, 2023
2,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.47 KB | None | 0 0
  1. function GenerateFEN(Engine: TEngine): string;
  2. var
  3.   count, i: Int32;
  4.   tmp: string;
  5.   anycc: Boolean;
  6. begin
  7.   SetLength(tmp, 64);
  8.   for i in BOARD_INDICES do
  9.     tmp[ConvertFromDeep(i)+1] := Engine.State[i];
  10.   tmp += ' '; // padding
  11.  
  12.   Result := '';
  13.   i := 1;
  14.   while i <= 64 do
  15.   begin
  16.     if tmp[i] = '.' then
  17.     begin
  18.       count := 0;
  19.       while (tmp[i] = '.')  do
  20.       begin
  21.         Inc(count);
  22.         Inc(i);
  23.         if (i-1) mod 8 = 0 then
  24.           break;
  25.       end;
  26.       Result += IntToStr(count);
  27.     end else
  28.     begin
  29.       while IsAlpha(tmp[i]) do
  30.       begin
  31.         Result += tmp[i];
  32.         Inc(i);
  33.         if (i-1) mod 8 = 0 then
  34.           break;
  35.       end;
  36.     end;
  37.     if (i-1) mod 8 = 0 then
  38.       Result += '/';
  39.   end;
  40.  
  41.   Result[Length(Result)] := ' ';
  42.  
  43.   if Engine.Wtm then Result += 'w'
  44.   else               Result += 'b';
  45.   Result += ' ';
  46.  
  47.   anycc := False;
  48.   if Engine.Wcc.KSide then begin Result += 'K'; anycc := True; end;
  49.   if Engine.Wcc.QSide then begin Result += 'Q'; anycc := True; end;
  50.   if Engine.Bcc.KSide then begin Result += 'k'; anycc := True; end;
  51.   if Engine.Bcc.KSide then begin Result += 'q'; anycc := True; end;
  52.  
  53.   if not anycc then Result += '-';
  54.  
  55.   Result += ' ';
  56.  
  57.   if Engine.ep <> 0 then Result += Engine.Coords(Engine.ep)
  58.   else                   Result += '-';
  59.   Result += ' ';
  60.  
  61.   // half moves
  62.   Result += '0 ';
  63.  
  64.   // whole moves
  65.   Result += IntToStr(Engine.History.Len() div 2);
  66. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement