public bool IsLocationBlocked(int row, int col) { var boardItem = ChessBoard.GetPiece(row, col); RaiseCapture(row, col, boardItem); return(boardItem != null && boardItem.PieceColor != OpposingColor); }
public void _01_white_pawn_capture_black_pawn_at_row_5_col_2() { _chessBoard.AddReplace(_pawn2, 5, 2); _chessBoard.AddReplace(_pawn1, 6, 1); _pawn1.Move(5, 2); Assert.That(_pawn1.Row, Is.EqualTo(5)); Assert.That(_pawn1.Column, Is.EqualTo(2)); Assert.That(_chessBoard.GetPiece(5, 2), Is.EqualTo(_pawn1)); }
public IEnumerable <Tuple <int, int> > PawnCaptureMoves() { var isDiagRightCapturable = ChessBoard.GetPiece(DiagonalRight.Item1, DiagonalRight.Item2) != null && ChessBoard.GetPiece(DiagonalRight.Item1, DiagonalRight.Item2).PieceColor == OpposingColor; var isDiagLeftCapturable = ChessBoard.GetPiece(DiagonalLeft.Item1, DiagonalLeft.Item2) != null && ChessBoard.GetPiece(DiagonalLeft.Item1, DiagonalLeft.Item2).PieceColor == OpposingColor; var leftAdjacent = ChessBoard.GetPiece(CurrentRow, CurrentColumn - 1); var isDiagLeftPassantable = DeterminePassantable(DiagonalLeft, leftAdjacent); var rightAdjacent = ChessBoard.GetPiece(CurrentRow, CurrentColumn + 1); var isDiagRightPassantable = DeterminePassantable(DiagonalRight, rightAdjacent); if (isDiagRightCapturable || isDiagRightPassantable) { yield return(DiagonalRight); } if (isDiagLeftCapturable || isDiagLeftPassantable) { yield return(DiagonalLeft); } }
/// <summary> /// Specifically For en-passant /// (need to remove the pawn which is currently in the opposite direction) /// </summary> /// <param name="destination"></param> public override void HandleCapture(Tuple <int, int> destination) { if ((destination.Equals((MoveStrategy as PawnAdapterStrategy).DiagonalLeft) || destination.Equals((MoveStrategy as PawnAdapterStrategy).DiagonalRight)) && ChessBoard.GetPiece(destination.Item1, destination.Item2) == null) { ChessBoard.Remove(destination.Item1 + (Direction * -1), destination.Item2); } }
private bool DeterminePassantable(Tuple <int, int> attackDirection, ChessPiece adjacentEnemy) { var coercedEnemyPawn = (adjacentEnemy as Pawn); var isPassantable = coercedEnemyPawn != null && ChessBoard.GetPiece(attackDirection.Item1, attackDirection.Item2) == null && adjacentEnemy.PieceColor == OpposingColor && coercedEnemyPawn.MoveCount == 1 && coercedEnemyPawn.HasMovedDouble; return(isPassantable); }
public IEnumerable <Tuple <int, int> > PawnAdvanceMoves() { var isNextRowOccupied = ChessBoard.GetPiece(CurrentRow + Direction, CurrentColumn) != null; var isNextNextRowOccupied = ChessBoard.GetPiece(DoubleForward.Item1, CurrentColumn) != null; if (!isNextRowOccupied) { yield return(new Tuple <int, int>(CurrentRow + Direction, CurrentColumn)); } if (MoveCount == 0 && !isNextRowOccupied && !isNextNextRowOccupied) { yield return(new Tuple <int, int>(DoubleForward.Item1, CurrentColumn)); } }