Fix missing capture type for en-passant
This commit is contained in:
parent
c5f13b9001
commit
29caae5b56
4 changed files with 15 additions and 6 deletions
|
@ -36,7 +36,7 @@ namespace ChessChallenge.API
|
|||
{
|
||||
Chess.Move move = boardSource.AllGameMoves[i];
|
||||
int movePieceType = PieceHelper.PieceType(board.Square[move.StartSquareIndex]);
|
||||
int capturePieceType = PieceHelper.PieceType(board.Square[move.TargetSquareIndex]);
|
||||
int capturePieceType = move.IsEnPassant ? PieceHelper.Pawn : PieceHelper.PieceType(board.Square[move.TargetSquareIndex]);
|
||||
GameMoveHistory[i] = new Move(move, movePieceType, capturePieceType);
|
||||
board.MakeMove(move, false);
|
||||
}
|
||||
|
|
|
@ -109,14 +109,16 @@ namespace ChessChallenge.Application.APIHelpers
|
|||
API.Move CreateAPIMove(int startSquare, int targetSquare, int flag)
|
||||
{
|
||||
int movePieceType = PieceHelper.PieceType(board.Square[startSquare]);
|
||||
int capturePieceType = PieceHelper.PieceType(board.Square[targetSquare]);
|
||||
API.Move apiMove = new(new Move(startSquare, targetSquare, flag), movePieceType, capturePieceType);
|
||||
return apiMove;
|
||||
return CreateAPIMove(startSquare, targetSquare, flag, movePieceType);
|
||||
}
|
||||
|
||||
API.Move CreateAPIMove(int startSquare, int targetSquare, int flag, int movePieceType)
|
||||
{
|
||||
int capturePieceType = PieceHelper.PieceType(board.Square[targetSquare]);
|
||||
if (flag == Move.EnPassantCaptureFlag)
|
||||
{
|
||||
capturePieceType = PieceHelper.Pawn;
|
||||
}
|
||||
API.Move apiMove = new(new Move(startSquare, targetSquare, flag), movePieceType, capturePieceType);
|
||||
return apiMove;
|
||||
}
|
||||
|
|
|
@ -324,7 +324,7 @@ namespace ChessChallenge.Application
|
|||
Assert(boardAPI.GameStartFenString == startPos, "Wrong game start fen");
|
||||
Assert(boardAPI.GetFenString() == "r1bqkbnr/pppppppp/8/4n3/8/8/PPPP1PPP/RNBQKBNR w KQkq - 0 3", "Wrong game fen");
|
||||
|
||||
// Invalid target piece in capture when en passant is available
|
||||
// Test for bug: Invalid target piece in capture when en passant is available
|
||||
string[] invalidCaptureFens =
|
||||
{
|
||||
"r1b1r1k1/ppp2pp1/7p/2Pp4/4q3/PQ6/4PPPP/3RKB1R w K d6 0 16", // c5d6
|
||||
|
@ -332,7 +332,6 @@ namespace ChessChallenge.Application
|
|||
};
|
||||
foreach (var fen in invalidCaptureFens)
|
||||
{
|
||||
Console.WriteLine($"Checking captures for FEN: {fen}");
|
||||
board.LoadPosition(fen);
|
||||
boardAPI = new(board);
|
||||
captures = boardAPI.GetLegalMoves(true);
|
||||
|
@ -342,6 +341,13 @@ namespace ChessChallenge.Application
|
|||
Assert(c.CapturePieceType != PieceType.None, $"Capture piece type wrong for move {c}");
|
||||
}
|
||||
}
|
||||
|
||||
board.LoadPosition(invalidCaptureFens[0]);
|
||||
board.MakeMove(MoveUtility.GetMoveFromUCIName("c5d6", board), false);
|
||||
boardAPI = new(board);
|
||||
Assert(boardAPI.GameMoveHistory[0].CapturePieceType == PieceType.Pawn, "Wrong capture type: game history");
|
||||
Assert(boardAPI.GameMoveHistory[0].IsEnPassant, "Wrong move flag: move history");
|
||||
|
||||
}
|
||||
|
||||
static void MoveGenTest()
|
||||
|
|
|
@ -50,6 +50,7 @@ namespace ChessChallenge.Chess
|
|||
public int StartSquareIndex => moveValue & startSquareMask;
|
||||
public int TargetSquareIndex => (moveValue & targetSquareMask) >> 6;
|
||||
public bool IsPromotion => MoveFlag >= PromoteToQueenFlag;
|
||||
public bool IsEnPassant => MoveFlag == EnPassantCaptureFlag;
|
||||
public int MoveFlag => moveValue >> 12;
|
||||
|
||||
public int PromotionPieceType
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue