You've already forked lazarus-ccr
fpchess: FICS playing now works =)
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1906 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -94,9 +94,12 @@ var
|
||||
X, Y, SourceX, SourceY, DestX, DestY: integer;
|
||||
dx, dy: Integer;
|
||||
t: Double;
|
||||
lTile: TChessTile;
|
||||
begin
|
||||
// Draw the moving tile
|
||||
lTileBmp := vChessDrawer.GetChessTileImage(vChessGame.Board[AFrom.X][AFrom.Y]);
|
||||
//WriteLn(Format('[TChessMoveAnimation.DrawToIntfImg] Afrom=%d,%d', [AFrom.X, AFrom.Y]));
|
||||
lTile := vChessGame.Board[AFrom.X][AFrom.Y];
|
||||
lTileBmp := vChessDrawer.GetChessTileImage(lTile);
|
||||
if lTileBmp = nil then Exit;
|
||||
|
||||
SourceX := (AFrom.X - 1) * INT_CHESSTILE_SIZE;
|
||||
|
@ -96,6 +96,7 @@ type
|
||||
Dragging: Boolean;
|
||||
DragStart, MouseMovePos: TPoint;
|
||||
UseTimer: Boolean;
|
||||
Enabled: Boolean;
|
||||
WhitePlayerTime: Integer; // milisseconds
|
||||
BlackPlayerTime: Integer; // milisseconds
|
||||
MoveStartTime: TDateTime;
|
||||
@ -119,7 +120,7 @@ type
|
||||
function ClientToBoardCoords(AClientCoords: TPoint): TPoint;
|
||||
class function BoardPosToChessCoords(APos: TPoint): string;
|
||||
class function ChessCoordsToBoardPos(AStr: string): TPoint;
|
||||
class procedure ChessMoveCoordsToBoardPos(AMoveStr: string; AFrom, ATo: TPoint);
|
||||
class procedure ChessMoveCoordsToBoardPos(AMoveStr: string; var AFrom, ATo: TPoint);
|
||||
class function ColumnNumToLetter(ACol: Integer): string;
|
||||
function CheckStartMove(AFrom: TPoint): Boolean;
|
||||
function CheckEndMove(ATo: TPoint): Boolean;
|
||||
@ -156,6 +157,7 @@ var
|
||||
i: Integer;
|
||||
j: Integer;
|
||||
begin
|
||||
Enabled := True;
|
||||
UseTimer := AUseTimer;
|
||||
FirstPlayerIsWhite := APlayAsWhite;
|
||||
IsWhitePlayerTurn := True;
|
||||
@ -169,21 +171,11 @@ begin
|
||||
IsBlackLeftRoquePossible := True;
|
||||
IsBlackRightRoquePossible := True;
|
||||
|
||||
//
|
||||
if APlayAsWhite then
|
||||
begin
|
||||
lWPawnRow := 2;
|
||||
lWMainRow := 1;
|
||||
lBPawnRow := 7;
|
||||
lBMainRow := 8;
|
||||
end
|
||||
else
|
||||
begin
|
||||
lWPawnRow := 7;
|
||||
lWMainRow := 8;
|
||||
lBPawnRow := 2;
|
||||
lBMainRow := 1;
|
||||
end;
|
||||
// Don't invert these, instead invert only in the drawer
|
||||
lWPawnRow := 2;
|
||||
lWMainRow := 1;
|
||||
lBPawnRow := 7;
|
||||
lBMainRow := 8;
|
||||
|
||||
// First, clear the board
|
||||
for i := 1 to 8 do
|
||||
@ -758,15 +750,19 @@ begin
|
||||
Result.Y := StrToInt(lStr);
|
||||
end;
|
||||
|
||||
class procedure TChessGame.ChessMoveCoordsToBoardPos(AMoveStr: string; AFrom,
|
||||
ATo: TPoint);
|
||||
class procedure TChessGame.ChessMoveCoordsToBoardPos(AMoveStr: string;
|
||||
var AFrom, ATo: TPoint);
|
||||
var
|
||||
lStr: String;
|
||||
begin
|
||||
WriteLn('[TChessGame.ChessMoveCoordsToBoardPos] ' + AMoveStr);
|
||||
lStr := Copy(AMoveStr, 1, 2);
|
||||
///WriteLn('[TChessGame.ChessMoveCoordsToBoardPos] ' + lStr);
|
||||
AFrom := TChessGame.ChessCoordsToBoardPos(lStr);
|
||||
lStr := Copy(AMoveStr, 3, 2);
|
||||
lStr := Copy(AMoveStr, 4, 2);
|
||||
//WriteLn('[TChessGame.ChessMoveCoordsToBoardPos] ' + lStr);
|
||||
ATo := TChessGame.ChessCoordsToBoardPos(lStr);
|
||||
WriteLn(Format('[TChessGame.ChessMoveCoordsToBoardPos] AFrom.X=%d,%d ATo=%d,%d', [AFrom.X, AFrom.Y, ATo.X, ATo.Y]));
|
||||
end;
|
||||
|
||||
class function TChessGame.ColumnNumToLetter(ACol: Integer): string;
|
||||
|
@ -116,7 +116,8 @@ end;
|
||||
|
||||
function TChessModule.IsMovingAllowedNow: Boolean;
|
||||
begin
|
||||
Result := not (vChessGame.IsWhitePlayerTurn xor vChessGame.FirstPlayerIsWhite);
|
||||
Result := (not (vChessGame.IsWhitePlayerTurn xor vChessGame.FirstPlayerIsWhite))
|
||||
and (vChessGame.Enabled);
|
||||
end;
|
||||
|
||||
procedure TChessModule.HandleOnTimer;
|
||||
|
@ -57,7 +57,8 @@ begin
|
||||
if (FirstMatch = '') and (SecondMatch = '') then Exit;
|
||||
|
||||
repeat
|
||||
if GetMessage(lMsg) > 0 then if Assigned(OnDebugOut) then OnDebugOut(lMsg);
|
||||
if GetMessage(lMsg) > 0 then
|
||||
if Assigned(OnDebugOut) then OnDebugOut(lMsg);
|
||||
|
||||
LastMsg := lMsg;
|
||||
|
||||
|
@ -45,17 +45,17 @@ object formChess: TformChess
|
||||
end
|
||||
object Label6: TLabel
|
||||
Left = 28
|
||||
Height = 17
|
||||
Height = 18
|
||||
Top = 128
|
||||
Width = 52
|
||||
Width = 56
|
||||
Caption = 'Start as:'
|
||||
ParentColor = False
|
||||
end
|
||||
object Label7: TLabel
|
||||
Left = 80
|
||||
Height = 17
|
||||
Height = 18
|
||||
Top = 175
|
||||
Width = 150
|
||||
Width = 152
|
||||
Caption = 'minutes for each player'
|
||||
ParentColor = False
|
||||
end
|
||||
@ -70,7 +70,7 @@ object formChess: TformChess
|
||||
end
|
||||
object editPlayerName: TLabeledEdit
|
||||
Left = 88
|
||||
Height = 22
|
||||
Height = 25
|
||||
Top = 104
|
||||
Width = 120
|
||||
EditLabel.AnchorSideLeft.Control = editPlayerName
|
||||
@ -78,10 +78,10 @@ object formChess: TformChess
|
||||
EditLabel.AnchorSideTop.Side = asrCenter
|
||||
EditLabel.AnchorSideRight.Control = editPlayerName
|
||||
EditLabel.AnchorSideBottom.Control = editPlayerName
|
||||
EditLabel.Left = 6
|
||||
EditLabel.Height = 17
|
||||
EditLabel.Left = 2
|
||||
EditLabel.Height = 18
|
||||
EditLabel.Top = 107
|
||||
EditLabel.Width = 79
|
||||
EditLabel.Width = 83
|
||||
EditLabel.Caption = 'Player Name'
|
||||
EditLabel.ParentColor = False
|
||||
LabelPosition = lpLeft
|
||||
@ -89,7 +89,7 @@ object formChess: TformChess
|
||||
end
|
||||
object comboStartColor: TComboBox
|
||||
Left = 88
|
||||
Height = 21
|
||||
Height = 27
|
||||
Top = 128
|
||||
Width = 120
|
||||
ItemHeight = 0
|
||||
@ -103,9 +103,9 @@ object formChess: TformChess
|
||||
end
|
||||
object checkTimer: TCheckBox
|
||||
Left = 24
|
||||
Height = 18
|
||||
Height = 21
|
||||
Top = 152
|
||||
Width = 212
|
||||
Width = 220
|
||||
Caption = 'Set a time limit for each Player'
|
||||
Checked = True
|
||||
State = cbChecked
|
||||
@ -113,7 +113,7 @@ object formChess: TformChess
|
||||
end
|
||||
object spinPlayerTime: TSpinEdit
|
||||
Left = 21
|
||||
Height = 16
|
||||
Height = 25
|
||||
Top = 176
|
||||
Width = 50
|
||||
TabOrder = 4
|
||||
@ -121,7 +121,7 @@ object formChess: TformChess
|
||||
end
|
||||
object comboGameMode: TComboBox
|
||||
Left = 8
|
||||
Height = 21
|
||||
Height = 27
|
||||
Top = 74
|
||||
Width = 346
|
||||
ItemHeight = 0
|
||||
@ -140,7 +140,7 @@ object formChess: TformChess
|
||||
end
|
||||
object editLocalIP: TLabeledEdit
|
||||
Left = 120
|
||||
Height = 22
|
||||
Height = 25
|
||||
Top = 200
|
||||
Width = 120
|
||||
EditLabel.AnchorSideLeft.Control = editLocalIP
|
||||
@ -148,10 +148,10 @@ object formChess: TformChess
|
||||
EditLabel.AnchorSideTop.Side = asrCenter
|
||||
EditLabel.AnchorSideRight.Control = editLocalIP
|
||||
EditLabel.AnchorSideBottom.Control = editLocalIP
|
||||
EditLabel.Left = 12
|
||||
EditLabel.Height = 17
|
||||
EditLabel.Left = 15
|
||||
EditLabel.Height = 18
|
||||
EditLabel.Top = 203
|
||||
EditLabel.Width = 105
|
||||
EditLabel.Width = 102
|
||||
EditLabel.Caption = 'Your IP Address:'
|
||||
EditLabel.ParentColor = False
|
||||
LabelPosition = lpLeft
|
||||
@ -169,8 +169,8 @@ object formChess: TformChess
|
||||
end
|
||||
end
|
||||
object pageGame: TPage
|
||||
ClientWidth = 720
|
||||
ClientHeight = 1000
|
||||
ClientWidth = 1440
|
||||
ClientHeight = 2000
|
||||
object labelPos: TLabel
|
||||
Left = 8
|
||||
Height = 18
|
||||
@ -238,8 +238,8 @@ object formChess: TformChess
|
||||
end
|
||||
end
|
||||
object pageWebservice: TPage
|
||||
ClientWidth = 11520
|
||||
ClientHeight = 13856
|
||||
ClientWidth = 23040
|
||||
ClientHeight = 27712
|
||||
object Label8: TLabel
|
||||
Left = 0
|
||||
Height = 32
|
||||
|
@ -241,6 +241,7 @@ var
|
||||
lModule: TChessModule;
|
||||
begin
|
||||
InitializeGameModel();
|
||||
vChessGame.Enabled := False;
|
||||
|
||||
notebookMain.PageIndex := INT_PAGE_GAME;
|
||||
|
||||
@ -249,6 +250,8 @@ begin
|
||||
vChessGame.PlayerName := editPlayerName.Text;
|
||||
lModule.PrepareForGame();
|
||||
|
||||
// Make sure this is done after lModule.PrepareForGame()
|
||||
vChessGame.Enabled := True;
|
||||
timerChessTimer.Enabled := True;
|
||||
end;
|
||||
|
||||
|
@ -97,6 +97,7 @@ begin
|
||||
radioConnectionType.Caption := 'FICS Connection Type';
|
||||
radioConnectionType.Items.Add('Wait for a friend to connect to me');
|
||||
radioConnectionType.Items.Add('Connect to a friend (he needs to be waiting for the connection)');
|
||||
radioConnectionType.ItemIndex := 0;
|
||||
|
||||
textPassword := TStaticText.Create(nil);
|
||||
textPassword.SetBounds(10, 110, 180, 20);
|
||||
@ -112,7 +113,7 @@ begin
|
||||
|
||||
editSecondPlayerName := TEdit.Create(nil);
|
||||
editSecondPlayerName.SetBounds(200, 130, 150, 40);
|
||||
editSecondPlayerName.Text := '';
|
||||
editSecondPlayerName.Text := 'fpchesse';
|
||||
end;
|
||||
|
||||
procedure TFICSChessModule.ShowUserInterface(AParent: TWinControl);
|
||||
@ -195,6 +196,7 @@ begin
|
||||
|
||||
// ... and we send our username once prompted.
|
||||
//ChessModuleDebugLn('Found the login!!!');
|
||||
ChessModuleDebugLn('Sending: ' + FICS_USER);
|
||||
TelnetComm.SendMessage(FICS_USER + FICS_LineEnding);
|
||||
|
||||
// Now we read obtained lines scanning for some patterns.
|
||||
@ -244,6 +246,7 @@ begin
|
||||
'.*fics%.*',
|
||||
'',
|
||||
OPEN_TIMEOUT);
|
||||
ChessModuleDebugLn('Sending: set seek 0');
|
||||
TelnetComm.SendMessage('set seek 0' + FICS_LineEnding);
|
||||
|
||||
// Set the style
|
||||
@ -251,18 +254,22 @@ begin
|
||||
'.*fics%.*',
|
||||
'',
|
||||
OPEN_TIMEOUT);
|
||||
ChessModuleDebugLn('Sending: set style 11');
|
||||
TelnetComm.SendMessage('set style 11' + FICS_LineEnding);
|
||||
|
||||
// Wait for a match
|
||||
if radioConnectionType.ItemIndex = 0 then
|
||||
begin
|
||||
vChessGame.FirstPlayerIsWhite := False;
|
||||
|
||||
// Challenge: GuestZMYL (----) fpchess (----) unrated blitz 2 12.
|
||||
// You can "accept" or "decline", or propose different parameters.
|
||||
TelnetComm.WaitFor(
|
||||
'.*You can "accept" or "decline", or propose different parameters*',
|
||||
'',
|
||||
OPEN_TIMEOUT);
|
||||
TelnetComm.SendMessage('accept ' + FICS_LineEnding);
|
||||
ChessModuleDebugLn('Sending: accept');
|
||||
TelnetComm.SendMessage('accept' + FICS_LineEnding);
|
||||
|
||||
// You accept the match offer from GuestZMYL.
|
||||
TelnetComm.WaitFor(
|
||||
@ -277,7 +284,9 @@ begin
|
||||
'.*fics%.*',
|
||||
'',
|
||||
OPEN_TIMEOUT);
|
||||
TelnetComm.SendMessage('match ' + editSecondPlayerName.Text + FICS_LineEnding);
|
||||
lMsg := 'match ' + editSecondPlayerName.Text + ' 60 White';
|
||||
ChessModuleDebugLn('Sending: ' + lMsg);
|
||||
TelnetComm.SendMessage(lMsg + FICS_LineEnding);
|
||||
|
||||
// fpchess accepts the match offer.
|
||||
TelnetComm.WaitFor(
|
||||
@ -299,11 +308,14 @@ var
|
||||
lMsg: String;
|
||||
begin
|
||||
lMsg := Format('%s-%s', [TChessGame.BoardPosToChessCoords(AFrom), TChessGame.BoardPosToChessCoords(ATo)]);
|
||||
ChessModuleDebugLn('Sending: ' + lMsg);
|
||||
TelnetComm.SendMessage(lMsg + FICS_LineEnding);
|
||||
|
||||
// Wait until it shows our move
|
||||
TelnetComm.WaitFor(
|
||||
'.*fics%.*',
|
||||
'.*[PRNBQK]/[abcdefgh][0123456789]-[abcdefgh][0123456789].*',
|
||||
'',
|
||||
OPEN_TIMEOUT);
|
||||
TelnetComm.SendMessage(lMsg + FICS_LineEnding);
|
||||
end;
|
||||
|
||||
// listen for moves
|
||||
@ -321,6 +333,8 @@ begin
|
||||
'.*[PRNBQK]/[abcdefgh][0123456789]-[abcdefgh][0123456789].*',
|
||||
'',
|
||||
0);
|
||||
// if TelnetComm.LastMsg <> '' then
|
||||
// lIndex := lIndex;
|
||||
if lIndex = 0 then
|
||||
begin
|
||||
lMoveStr := Copy(TelnetComm.LastMsg, Pos('/', TelnetComm.LastMsg)+1, 5);
|
||||
|
Reference in New Issue
Block a user