Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GenerateFEN(Engine: TEngine): string;
- var
- count, i: Int32;
- tmp: string;
- anycc: Boolean;
- begin
- SetLength(tmp, 64);
- for i in BOARD_INDICES do
- tmp[ConvertFromDeep(i)+1] := Engine.State[i];
- tmp += ' '; // padding
- Result := '';
- i := 1;
- while i <= 64 do
- begin
- if tmp[i] = '.' then
- begin
- count := 0;
- while (tmp[i] = '.') do
- begin
- Inc(count);
- Inc(i);
- if (i-1) mod 8 = 0 then
- break;
- end;
- Result += IntToStr(count);
- end else
- begin
- while IsAlpha(tmp[i]) do
- begin
- Result += tmp[i];
- Inc(i);
- if (i-1) mod 8 = 0 then
- break;
- end;
- end;
- if (i-1) mod 8 = 0 then
- Result += '/';
- end;
- Result[Length(Result)] := ' ';
- if Engine.Wtm then Result += 'w'
- else Result += 'b';
- Result += ' ';
- anycc := False;
- if Engine.Wcc.KSide then begin Result += 'K'; anycc := True; end;
- if Engine.Wcc.QSide then begin Result += 'Q'; anycc := True; end;
- if Engine.Bcc.KSide then begin Result += 'k'; anycc := True; end;
- if Engine.Bcc.KSide then begin Result += 'q'; anycc := True; end;
- if not anycc then Result += '-';
- Result += ' ';
- if Engine.ep <> 0 then Result += Engine.Coords(Engine.ep)
- else Result += '-';
- Result += ' ';
- // half moves
- Result += '0 ';
- // whole moves
- Result += IntToStr(Engine.History.Len() div 2);
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement