2011-09-07 18:02:31 +00:00
|
|
|
unit mod_winboard;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils,
|
|
|
|
StdCtrls, Forms, Controls,
|
|
|
|
chessmodules, chessgame;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TWinboardChessModule }
|
|
|
|
|
|
|
|
TWinboardChessModule = class(TChessModule)
|
|
|
|
private
|
|
|
|
textEnginePatch : TStaticText;
|
|
|
|
editEnginePatch : TEdit;
|
|
|
|
EngineStringList: TStringList;
|
|
|
|
side : boolean; //Side to move true=human.
|
|
|
|
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;
|
|
|
|
procedure HandleOnMove(AFrom, ATo: TPoint); override;
|
|
|
|
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;
|
|
|
|
|
|
|
|
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);
|
|
|
|
compMove:=vwinboardConn.engineMove;
|
|
|
|
vChessGame.MovePiece(CompMove[1],CompMove[2]);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TWinboardChessModule.PrepareForGame;
|
|
|
|
var i: integer;
|
|
|
|
CompMove: moveInCoord;
|
|
|
|
begin
|
|
|
|
vwinboardConn.startEngine(editEnginePatch.text);
|
|
|
|
if not vChessGame.FirstPlayerIsWhite then
|
|
|
|
begin
|
|
|
|
vwinboardConn.tellMove('go');
|
|
|
|
compMove:=vwinboardConn.engineMove;
|
|
|
|
vChessGame.MovePiece(CompMove[1],CompMove[2]);
|
|
|
|
end;
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
initialization
|
|
|
|
RegisterChessModule(TWinboardChessModule.Create);
|
2011-11-27 16:13:27 +00:00
|
|
|
finalization
|
|
|
|
vwinboardConn.stopEngine;
|
2011-09-07 18:02:31 +00:00
|
|
|
end.
|