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:
sekelsenmat
2011-08-30 14:40:22 +00:00
parent 8e74329135
commit af711ad83f
4 changed files with 35 additions and 8 deletions

View File

@ -261,6 +261,9 @@ begin
// Change player // Change player
IsWhitePlayerTurn := not IsWhitePlayerTurn; IsWhitePlayerTurn := not IsWhitePlayerTurn;
// Notify of the move
if Assigned(OnMove) then OnMove(AFrom, ATo);
end; end;
{ Really moves the piece without doing any check } { Really moves the piece without doing any check }
@ -273,9 +276,6 @@ begin
// If Enpassant, clear the remaining pawn // If Enpassant, clear the remaining pawn
if AEnpassantToClear.X <> -1 then if AEnpassantToClear.X <> -1 then
Board[AEnpassantToClear.X][AEnpassantToClear.Y] := ctEmpty; Board[AEnpassantToClear.X][AEnpassantToClear.Y] := ctEmpty;
// Notify of the move
if Assigned(OnMove) then OnMove(AFrom, ATo);
end; end;
procedure TChessGame.DoCastle(); procedure TChessGame.DoCastle();

View File

@ -304,7 +304,11 @@
var Row: RowColType; var Row: RowColType;
Attacked, _Protected : integer; Attacked, _Protected : integer;
begin begin
{$ifdef KCCHESS_VERBOSE}
//WriteLn(Format('[Moves.pas.MakeMove] Movement.PieceTaken.image=%d', [Integer(Movement.PieceTaken.image)]));
{$endif}
Score := 0; Score := 0;
{*** update board for most moves ***} {*** update board for most moves ***}
with Movement do begin with Movement do begin

View File

@ -59,6 +59,10 @@
Attacked, _Protected: integer; Attacked, _Protected: integer;
NoMoves, TakingPiece: boolean; NoMoves, TakingPiece: boolean;
begin begin
{$ifdef KCCHESS_VERBOSE}
//WriteLn('[Play.pas.GetComputerMove.Search]');
{$endif}
{*** get the player's move list ***} {*** get the player's move list ***}
GenMoveList (Turn, MoveList); GenMoveList (Turn, MoveList);
NoMoves := true; NoMoves := true;
@ -287,6 +291,9 @@
{----------------------------------------------------------------------------} {----------------------------------------------------------------------------}
begin {GetComputerMove} begin {GetComputerMove}
{$ifdef KCCHESS_VERBOSE}
WriteLn('[Play.pas.GetComputerMove]');
{$endif}
{*** initialize ***} {*** initialize ***}
PosEvalOn := Player[Turn].PosEval; PosEvalOn := Player[Turn].PosEval;
MaxDepth := Player[Turn].LookAhead; MaxDepth := Player[Turn].LookAhead;
@ -321,9 +328,15 @@
end; end;
{$endif} {$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 ***} {*** check each possible move - same method as in Search ***}
while (i > 0) do while (i > 0) do
begin begin
{$ifdef KCCHESS_VERBOSE}
WriteLn(Format('[Play.pas.GetComputerMove] Loop i=%d MoveList.NumMoves=%d', [i, MoveList.NumMoves]));
{$endif}
{$ifdef FPCHESS_DISPLAY_ON} {$ifdef FPCHESS_DISPLAY_ON}
UpDateTime (Turn); {*** player's elapsed time ***} UpDateTime (Turn); {*** player's elapsed time ***}
{$endif} {$endif}

View File

@ -1,3 +1,8 @@
{
Chess Engine licensed under public domain obtained from:
http://www.csbruce.com/~csbruce/chess/
}
unit mod_kcchess; unit mod_kcchess;
{$mode objfpc} {$mode objfpc}
@ -172,6 +177,8 @@ procedure GetComputerMove (Turn : PieceColorType; Display : boolean;
implementation implementation
{$define KCCHESS_VERBOSE}
{*** include files ***} {*** include files ***}
//{$I MISC.PAS} {*** miscellaneous functions ***} //{$I MISC.PAS} {*** miscellaneous functions ***}
@ -271,6 +278,10 @@ var
Escape: boolean; Escape: boolean;
Score: Integer; Score: Integer;
begin begin
// If we are getting notified by a computer move, exit immediately
if IsMovingAllowedNow() then Exit;
// initialization
Escape := False; Escape := False;
Score := 0; Score := 0;
@ -296,10 +307,9 @@ begin
{ And write it to our board } { And write it to our board }
vChessGame.DoMovePiece( vChessGame.MovePiece(
Point(UserMovement.FromRow, UserMovement.FromCol), Point(AIMovement.FromCol, AIMovement.FromRow),
Point(UserMovement.ToRow, UserMovement.ToCol), Point(AIMovement.ToCol, AIMovement.ToRow));
Point(-1, -1));
end; end;
initialization initialization