You've already forked lazarus-ccr
fpchess: AI playing actually works now =D
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1874 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -261,6 +261,9 @@ begin
|
||||
|
||||
// Change player
|
||||
IsWhitePlayerTurn := not IsWhitePlayerTurn;
|
||||
|
||||
// Notify of the move
|
||||
if Assigned(OnMove) then OnMove(AFrom, ATo);
|
||||
end;
|
||||
|
||||
{ Really moves the piece without doing any check }
|
||||
@ -273,9 +276,6 @@ begin
|
||||
// If Enpassant, clear the remaining pawn
|
||||
if AEnpassantToClear.X <> -1 then
|
||||
Board[AEnpassantToClear.X][AEnpassantToClear.Y] := ctEmpty;
|
||||
|
||||
// Notify of the move
|
||||
if Assigned(OnMove) then OnMove(AFrom, ATo);
|
||||
end;
|
||||
|
||||
procedure TChessGame.DoCastle();
|
||||
|
@ -304,7 +304,11 @@
|
||||
var Row: RowColType;
|
||||
Attacked, _Protected : integer;
|
||||
|
||||
begin
|
||||
begin
|
||||
{$ifdef KCCHESS_VERBOSE}
|
||||
//WriteLn(Format('[Moves.pas.MakeMove] Movement.PieceTaken.image=%d', [Integer(Movement.PieceTaken.image)]));
|
||||
{$endif}
|
||||
|
||||
Score := 0;
|
||||
{*** update board for most moves ***}
|
||||
with Movement do begin
|
||||
|
@ -59,6 +59,10 @@
|
||||
Attacked, _Protected: integer;
|
||||
NoMoves, TakingPiece: boolean;
|
||||
begin
|
||||
{$ifdef KCCHESS_VERBOSE}
|
||||
//WriteLn('[Play.pas.GetComputerMove.Search]');
|
||||
{$endif}
|
||||
|
||||
{*** get the player's move list ***}
|
||||
GenMoveList (Turn, MoveList);
|
||||
NoMoves := true;
|
||||
@ -287,6 +291,9 @@
|
||||
|
||||
{----------------------------------------------------------------------------}
|
||||
begin {GetComputerMove}
|
||||
{$ifdef KCCHESS_VERBOSE}
|
||||
WriteLn('[Play.pas.GetComputerMove]');
|
||||
{$endif}
|
||||
{*** initialize ***}
|
||||
PosEvalOn := Player[Turn].PosEval;
|
||||
MaxDepth := Player[Turn].LookAhead;
|
||||
@ -321,9 +328,15 @@
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
{$ifdef KCCHESS_VERBOSE}
|
||||
WriteLn(Format('[Play.pas.GetComputerMove] MaxDepth=%d Loop i=%d', [MaxDepth, i]));
|
||||
{$endif}
|
||||
{*** check each possible move - same method as in Search ***}
|
||||
while (i > 0) do
|
||||
begin
|
||||
{$ifdef KCCHESS_VERBOSE}
|
||||
WriteLn(Format('[Play.pas.GetComputerMove] Loop i=%d MoveList.NumMoves=%d', [i, MoveList.NumMoves]));
|
||||
{$endif}
|
||||
{$ifdef FPCHESS_DISPLAY_ON}
|
||||
UpDateTime (Turn); {*** player's elapsed time ***}
|
||||
{$endif}
|
||||
|
@ -1,3 +1,8 @@
|
||||
{
|
||||
Chess Engine licensed under public domain obtained from:
|
||||
|
||||
http://www.csbruce.com/~csbruce/chess/
|
||||
}
|
||||
unit mod_kcchess;
|
||||
|
||||
{$mode objfpc}
|
||||
@ -172,6 +177,8 @@ procedure GetComputerMove (Turn : PieceColorType; Display : boolean;
|
||||
|
||||
implementation
|
||||
|
||||
{$define KCCHESS_VERBOSE}
|
||||
|
||||
{*** include files ***}
|
||||
|
||||
//{$I MISC.PAS} {*** miscellaneous functions ***}
|
||||
@ -271,6 +278,10 @@ var
|
||||
Escape: boolean;
|
||||
Score: Integer;
|
||||
begin
|
||||
// If we are getting notified by a computer move, exit immediately
|
||||
if IsMovingAllowedNow() then Exit;
|
||||
|
||||
// initialization
|
||||
Escape := False;
|
||||
Score := 0;
|
||||
|
||||
@ -296,10 +307,9 @@ begin
|
||||
|
||||
{ And write it to our board }
|
||||
|
||||
vChessGame.DoMovePiece(
|
||||
Point(UserMovement.FromRow, UserMovement.FromCol),
|
||||
Point(UserMovement.ToRow, UserMovement.ToCol),
|
||||
Point(-1, -1));
|
||||
vChessGame.MovePiece(
|
||||
Point(AIMovement.FromCol, AIMovement.FromRow),
|
||||
Point(AIMovement.ToCol, AIMovement.ToRow));
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
Reference in New Issue
Block a user