diff --git a/applications/fpchess/chessgame.pas b/applications/fpchess/chessgame.pas index 0407d1b56..3d8c49621 100644 --- a/applications/fpchess/chessgame.pas +++ b/applications/fpchess/chessgame.pas @@ -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(); diff --git a/applications/fpchess/engines/kcchess/MOVES.PAS b/applications/fpchess/engines/kcchess/MOVES.PAS index 2a8f4a098..2b2bb2ae5 100644 --- a/applications/fpchess/engines/kcchess/MOVES.PAS +++ b/applications/fpchess/engines/kcchess/MOVES.PAS @@ -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 diff --git a/applications/fpchess/engines/kcchess/PLAY.PAS b/applications/fpchess/engines/kcchess/PLAY.PAS index d8c7350ad..f4a880ff4 100644 --- a/applications/fpchess/engines/kcchess/PLAY.PAS +++ b/applications/fpchess/engines/kcchess/PLAY.PAS @@ -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} diff --git a/applications/fpchess/engines/kcchess/mod_kcchess.pas b/applications/fpchess/engines/kcchess/mod_kcchess.pas index 7c50ea6b9..7e20af7bf 100644 --- a/applications/fpchess/engines/kcchess/mod_kcchess.pas +++ b/applications/fpchess/engines/kcchess/mod_kcchess.pas @@ -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