2011-09-07 18:02:31 +00:00
|
|
|
unit mod_winboard;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils,
|
|
|
|
StdCtrls, Forms, Controls,
|
2015-05-01 15:21:22 +00:00
|
|
|
chessmodules, chessgame, chessdrawer;
|
2011-09-07 18:02:31 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TWinboardChessModule }
|
|
|
|
|
|
|
|
TWinboardChessModule = class(TChessModule)
|
|
|
|
private
|
|
|
|
textEnginePatch : TStaticText;
|
|
|
|
editEnginePatch : TEdit;
|
|
|
|
public
|
2011-11-27 16:13:27 +00:00
|
|
|
constructor Create; override;
|
2011-09-07 18:02:31 +00:00
|
|
|
procedure CreateUserInterface(); override;
|
|
|
|
procedure ShowUserInterface(AParent: TWinControl); override;
|
|
|
|
procedure HideUserInterface(); override;
|
|
|
|
procedure FreeUserInterface(); override;
|
|
|
|
procedure PrepareForGame(); override;
|
2015-05-01 15:21:22 +00:00
|
|
|
function GetSecondPlayerName(): ansistring; override;
|
2011-09-07 18:02:31 +00:00
|
|
|
procedure HandleOnMove(AFrom, ATo: TPoint); override;
|
2013-11-20 01:28:33 +00:00
|
|
|
procedure HandleOnTimer(); override;
|
2011-09-07 18:02:31 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses winboardConn;
|
|
|
|
|
|
|
|
{ TSinglePlayerChessModule }
|
|
|
|
|
|
|
|
constructor TWinboardChessModule.Create;
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
SelectionDescription := 'Play against a winboard engine';
|
|
|
|
PlayingDescription := 'Play against a winboard engine';
|
|
|
|
Kind := cmkAgainstComputer;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TWinboardChessModule.CreateUserInterface;
|
|
|
|
begin
|
|
|
|
textEnginePatch := TStaticText.Create(nil);
|
|
|
|
textEnginePatch.SetBounds(20, 20, 180, 50);
|
2011-11-27 16:13:27 +00:00
|
|
|
textEnginePatch.Caption := 'Full patch to the engine';
|
2011-09-07 18:02:31 +00:00
|
|
|
|
|
|
|
editEnginePatch := TEdit.Create(nil);
|
|
|
|
editEnginePatch.SetBounds(200, 20, 150, 50);
|
2011-11-27 16:13:27 +00:00
|
|
|
editEnginePatch.Text := 'gnuchess';
|
2011-09-07 18:02:31 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TWinboardChessModule.ShowUserInterface(AParent: TWinControl);
|
|
|
|
begin
|
|
|
|
textEnginePatch.Parent := AParent;
|
|
|
|
editEnginePatch.Parent := AParent;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TWinboardChessModule.HideUserInterface();
|
|
|
|
begin
|
|
|
|
textEnginePatch.Parent := nil;
|
|
|
|
editEnginePatch.Parent := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TWinboardChessModule.FreeUserInterface();
|
|
|
|
begin
|
|
|
|
textEnginePatch.Free;
|
|
|
|
editEnginePatch.Free;
|
|
|
|
end;
|
|
|
|
|
2015-05-01 15:21:22 +00:00
|
|
|
function TWinboardChessModule.GetSecondPlayerName(): ansistring;
|
|
|
|
begin
|
|
|
|
Result := editEnginePatch.text;
|
|
|
|
end;
|
|
|
|
|
2011-09-07 18:02:31 +00:00
|
|
|
procedure TWinboardChessModule.HandleOnMove(AFrom, ATo: TPoint);
|
|
|
|
var
|
|
|
|
moveStr : String;
|
|
|
|
begin
|
2015-05-05 00:40:51 +00:00
|
|
|
moveStr:=vwinboardConn.coordToString(AFrom,ATo,vChessGame.PreviousMove.PieceMoved,vChessGame.PreviousMove.PieceCaptured);
|
2011-09-07 18:02:31 +00:00
|
|
|
vwinboardConn.tellMove(moveStr);
|
2013-11-20 01:28:33 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TWinboardChessModule.HandleOnTimer;
|
|
|
|
var
|
|
|
|
CompMove: moveInCoord;
|
2015-05-01 15:21:22 +00:00
|
|
|
lAnimation: TChessMoveAnimation;
|
2013-11-20 01:28:33 +00:00
|
|
|
begin
|
|
|
|
CompMove:=vwinboardConn.engineMove;
|
2015-05-01 15:21:22 +00:00
|
|
|
|
|
|
|
if (CompMove <> nilCoord) then
|
|
|
|
begin
|
|
|
|
lAnimation := TChessMoveAnimation.Create;
|
|
|
|
lAnimation.AFrom := CompMove[1];
|
|
|
|
lAnimation.ATo := CompMove[2];
|
|
|
|
vChessDrawer.AddAnimation(lAnimation);
|
|
|
|
end;
|
2011-09-07 18:02:31 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TWinboardChessModule.PrepareForGame;
|
|
|
|
begin
|
|
|
|
vwinboardConn.startEngine(editEnginePatch.text);
|
|
|
|
if not vChessGame.FirstPlayerIsWhite then
|
|
|
|
begin
|
|
|
|
vwinboardConn.tellMove('go');
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
initialization
|
|
|
|
RegisterChessModule(TWinboardChessModule.Create);
|
2011-11-27 16:13:27 +00:00
|
|
|
finalization
|
2013-11-20 01:28:33 +00:00
|
|
|
vwinboardConn.stopEngine(True);
|
2011-09-07 18:02:31 +00:00
|
|
|
end.
|