FPChess: Fix in mod_winboard and apply animation to the engine moves

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4105 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
brian-ch
2015-05-01 15:21:22 +00:00
parent e66caefbe0
commit 5d7cc4210a
2 changed files with 42 additions and 13 deletions

View File

@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils,
StdCtrls, Forms, Controls,
chessmodules, chessgame;
chessmodules, chessgame, chessdrawer;
type
@ -17,7 +17,6 @@ type
private
textEnginePatch : TStaticText;
editEnginePatch : TEdit;
EngineStringList: TStringList;
public
constructor Create; override;
procedure CreateUserInterface(); override;
@ -25,6 +24,7 @@ type
procedure HideUserInterface(); override;
procedure FreeUserInterface(); override;
procedure PrepareForGame(); override;
function GetSecondPlayerName(): ansistring; override;
procedure HandleOnMove(AFrom, ATo: TPoint); override;
procedure HandleOnTimer(); override;
end;
@ -72,10 +72,14 @@ begin
editEnginePatch.Free;
end;
function TWinboardChessModule.GetSecondPlayerName(): ansistring;
begin
Result := editEnginePatch.text;
end;
procedure TWinboardChessModule.HandleOnMove(AFrom, ATo: TPoint);
var
moveStr : String;
CompMove: moveInCoord;
begin
moveStr:=vwinboardConn.coordToString(AFrom,ATo,vChessGame.PreviousMove.PieceMoved,vChessGame.PreviousMove.PieceEaten);
vwinboardConn.tellMove(moveStr);
@ -84,23 +88,34 @@ end;
procedure TWinboardChessModule.HandleOnTimer;
var
CompMove: moveInCoord;
lAnimation: TChessMoveAnimation;
begin
CompMove[1]:=Point(1,1);
CompMove[2]:=Point(1,1);
CompMove:=vwinboardConn.engineMove;
vChessGame.MovePiece(CompMove[1],CompMove[2]);
if (CompMove <> nilCoord) then
begin
lAnimation := TChessMoveAnimation.Create;
lAnimation.AFrom := CompMove[1];
lAnimation.ATo := CompMove[2];
vChessDrawer.AddAnimation(lAnimation);
end;
end;
procedure TWinboardChessModule.PrepareForGame;
var i: integer;
CompMove: moveInCoord;
var
CompMove: moveInCoord;
lAnimation: TChessMoveAnimation;
begin
vwinboardConn.startEngine(editEnginePatch.text);
if not vChessGame.FirstPlayerIsWhite then
begin
vwinboardConn.tellMove('go');
compMove:=vwinboardConn.engineMove;
vChessGame.MovePiece(CompMove[1],CompMove[2]);
lAnimation := TChessMoveAnimation.Create;
lAnimation.AFrom := CompMove[1];
lAnimation.ATo := CompMove[2];
vChessDrawer.AddAnimation(lAnimation);
end;
end;

View File

@ -33,6 +33,9 @@ type
//procedure detectEngine(path : String);
end;
const
nilCoord : moveInCoord = ((X:-1; Y:-1), (X:-1; Y:-1));
var
engineProcess : TProcess;
outputText : String;
@ -40,8 +43,16 @@ var
algebraicInput: boolean;
engineRegExpression: TRegExpr;
operator=(A, B: moveInCoord): Boolean;
implementation
operator=(A, B: moveInCoord): Boolean;
begin
Result := (A[1].X = B[1].X) and (A[1].Y = B[1].Y) and
(A[2].X = B[2].X) and (A[2].Y = B[2].Y);
end;
destructor TWinboardConn.Destroy;
begin
stopEngine(True);
@ -62,9 +73,11 @@ begin
engineProcess.Options := engineProcess.Options + [poUsePipes];
engineProcess.Execute;
extraCommands:='xboard'+#13+#10;
extraCommands:='xboard' + #13 + #10;
EngineProcess.Input.Write(extraCommands[1], length(extraCommands));
extraCommands:='level 60 0.5 3'+#13+#10;
extraCommands:='level 60 0.5 3' + #13 + #10;
EngineProcess.Input.Write(extraCommands[1], length(extraCommands));
extraCommands:='easy' + #13 + #10;
EngineProcess.Input.Write(extraCommands[1], length(extraCommands));
outputText:='';
@ -95,14 +108,15 @@ function TWinboardConn.engineMove : moveInCoord;
var move : String;
points: moveInCoord;
begin
points := nilCoord;
engineRegExpression.Expression:='(?m)^(My move|my move|move)( is|)(: | : | )';
readFromPipe;
if engineRegExpression.Exec(outputText) then
begin
move := extractMove;
points := stringToCoord(move);
result:=points;
end;
result := points;
end;
function TWinboardConn.coordToString(AFrom, ATo : TPoint; pieceFrom, pieceTo : TChessTile) : String;
@ -110,7 +124,7 @@ var
move : String;
begin
move:= move + numberToLetter(AFrom.X);
move:= numberToLetter(AFrom.X);
move:= move + intToStr(AFrom.Y);
move:= move + numberToLetter(ATo.X);