2011-08-27 20:53:13 +00:00
|
|
|
{
|
|
|
|
For playing through the internet via FICS - Free Internet Chess Server
|
|
|
|
|
|
|
|
Based on this article:
|
|
|
|
http://blog.mekk.waw.pl/archives/7-How-to-write-a-FICS-bot-part-I.html
|
|
|
|
|
|
|
|
FICS website:
|
|
|
|
http://www.freechess.org/
|
|
|
|
}
|
|
|
|
unit mod_fics;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils,
|
|
|
|
StdCtrls, Forms, Controls,
|
|
|
|
chessmodules, chessgame;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
2011-08-27 21:16:40 +00:00
|
|
|
{ TFICSChessModule }
|
2011-08-27 20:53:13 +00:00
|
|
|
|
2011-08-27 21:16:40 +00:00
|
|
|
TFICSChessModule = class(TChessModule)
|
2011-08-27 20:53:13 +00:00
|
|
|
public
|
|
|
|
SecondPlayerName: string;
|
|
|
|
constructor Create();
|
|
|
|
procedure CreateUserInterface(); override;
|
|
|
|
procedure ShowUserInterface(AParent: TWinControl); override;
|
|
|
|
procedure HideUserInterface(); override;
|
|
|
|
procedure FreeUserInterface(); override;
|
|
|
|
procedure PrepareForGame(); override;
|
|
|
|
function IsMovingAllowedNow(): Boolean; override;
|
|
|
|
function GetSecondPlayerName(): string; override;
|
|
|
|
procedure HandleOnMove(AFrom, ATo: TPoint); override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2011-08-27 21:16:40 +00:00
|
|
|
{ TFICSChessModule }
|
2011-08-27 20:53:13 +00:00
|
|
|
|
2011-08-27 21:16:40 +00:00
|
|
|
constructor TFICSChessModule.Create;
|
2011-08-27 20:53:13 +00:00
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
Description := 'Play online via the Free Internet Chess Server';
|
|
|
|
Kind := cmkSinglePlayer;
|
|
|
|
end;
|
|
|
|
|
2011-08-27 21:16:40 +00:00
|
|
|
procedure TFICSChessModule.CreateUserInterface;
|
2011-08-27 20:53:13 +00:00
|
|
|
begin
|
|
|
|
{ textSecondPlayerName := TStaticText.Create(nil);
|
|
|
|
textSecondPlayerName.SetBounds(20, 20, 180, 50);
|
|
|
|
textSecondPlayerName.Caption := 'Name of the second player';
|
|
|
|
|
|
|
|
editSecondPlayerName := TEdit.Create(nil);
|
|
|
|
editSecondPlayerName.SetBounds(200, 20, 150, 50);
|
|
|
|
editSecondPlayerName.Text := 'Second player';}
|
|
|
|
end;
|
|
|
|
|
2011-08-27 21:16:40 +00:00
|
|
|
procedure TFICSChessModule.ShowUserInterface(AParent: TWinControl);
|
2011-08-27 20:53:13 +00:00
|
|
|
begin
|
|
|
|
{ textSecondPlayerName.Parent := AParent;
|
|
|
|
editSecondPlayerName.Parent := AParent;}
|
|
|
|
end;
|
|
|
|
|
2011-08-27 21:16:40 +00:00
|
|
|
procedure TFICSChessModule.HideUserInterface();
|
2011-08-27 20:53:13 +00:00
|
|
|
begin
|
|
|
|
{ textSecondPlayerName.Parent := nil;
|
|
|
|
editSecondPlayerName.Parent := nil;}
|
|
|
|
end;
|
|
|
|
|
2011-08-27 21:16:40 +00:00
|
|
|
procedure TFICSChessModule.FreeUserInterface;
|
2011-08-27 20:53:13 +00:00
|
|
|
begin
|
|
|
|
{ textSecondPlayerName.Free;
|
|
|
|
editSecondPlayerName.Free;}
|
|
|
|
end;
|
|
|
|
|
2011-08-27 21:16:40 +00:00
|
|
|
procedure TFICSChessModule.PrepareForGame;
|
2011-08-27 20:53:13 +00:00
|
|
|
begin
|
|
|
|
// SecondPlayerName := editSecondPlayerName.Text;
|
2011-08-27 21:16:40 +00:00
|
|
|
ChessModuleDebugLn('[TFICSChessModule.PrepareForGame]');
|
2011-08-27 20:53:13 +00:00
|
|
|
end;
|
|
|
|
|
2011-08-27 21:16:40 +00:00
|
|
|
function TFICSChessModule.IsMovingAllowedNow: Boolean;
|
2011-08-27 20:53:13 +00:00
|
|
|
begin
|
|
|
|
Result := not (vChessGame.IsWhitePlayerTurn xor vChessGame.FirstPlayerIsWhite);
|
|
|
|
end;
|
|
|
|
|
2011-08-27 21:16:40 +00:00
|
|
|
function TFICSChessModule.GetSecondPlayerName: string;
|
2011-08-27 20:53:13 +00:00
|
|
|
begin
|
|
|
|
// Result := SecondPlayerName;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// If a move came, it is because the local player did a move
|
|
|
|
// so send this move and start listening for a move
|
2011-08-27 21:16:40 +00:00
|
|
|
procedure TFICSChessModule.HandleOnMove(AFrom, ATo: TPoint);
|
2011-08-27 20:53:13 +00:00
|
|
|
begin
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
initialization
|
2011-08-27 21:16:40 +00:00
|
|
|
RegisterChessModule(TFICSChessModule.Create);
|
2011-08-27 20:53:13 +00:00
|
|
|
end.
|
|
|
|
|