-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuci.pas
82 lines (71 loc) · 1.64 KB
/
uci.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
unit Uci;
interface
uses
Classes;
type
TUciCommand =
(
cmdUci,
cmdQuit,
cmdNewGame,
cmdPositionFen,
cmdPositionStartPos,
cmdGo,
cmdIsReady,
cmdStop,
cmdUnknown
);
TUciCommandParser = class
private
FMoves: TStringList;
FPosition: string;
public
constructor Create;
destructor Destroy; override;
function ParseCommand(const ACommand: string): TUciCommand;
property Moves: TStringList read FMoves;
property Position: string read FPosition;
end;
implementation
uses
Expressions;
constructor TUciCommandParser.Create;
begin
FMoves := Expressions.LMoveList;
end;
destructor TUciCommandParser.Destroy;
begin
inherited Destroy;
end;
function TUciCommandParser.ParseCommand(const ACommand: string): TUciCommand;
begin
if ACommand = 'uci' then
result := cmdUci
else
if ACommand = 'quit' then
result := cmdQuit
else
if ACommand = 'ucinewgame' then
result := cmdNewGame
else
if (Pos('position fen', ACommand) = 1)
and ExtractFen(ACommand, FPosition) then
result := cmdPositionFen
else
if (Pos('position startpos', ACommand) = 1) then
begin
result := cmdPositionStartPos;
ExtractMoves(ACommand);
end else
if Pos('go', ACommand) = 1 then
result := cmdGo
else
if ACommand = 'isready' then
result := cmdIsReady
else
if ACommand = 'stop' then
result := cmdStop
else
result := cmdUnknown;
end;
end.