private static void TryAnimateEnPassantCapture(Move move) { Position enPassantPosition; if (move.getPiece().side == Side.Black) { enPassantPosition = new Position(move.getPosition().GetColumn(), move.getPosition().GetRow() + 1); } else { enPassantPosition = new Position(move.getPosition().GetColumn(), move.getPosition().GetRow() - 1); } AbstractPiece pieceAtEnPassantPosition = GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>().chessBoard.GetPieceAtPosition(enPassantPosition); Pawn dyingPawn = null; if (pieceAtEnPassantPosition != null && pieceAtEnPassantPosition.GetType().Name == Constants.PieceClassNames.Pawn && pieceAtEnPassantPosition.side != move.getPiece().side&& ((Pawn)pieceAtEnPassantPosition).allowEnPassantCapture) { dyingPawn = (Pawn)pieceAtEnPassantPosition; } if (dyingPawn != null) { GameObject.Find(Constants.ActionCameraObject).GetComponent <ActionCamera>().EnableActionCamera(move.getPiece(), dyingPawn); GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>().DestroyPiece(GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>().GetGameObjectFromPiece(dyingPawn).GetComponent <PieceBehaviour>()); } }
public static void TriggerNextStartAnimation(AbstractPiece piece) { if (piece.GetType().Name == Constants.PieceClassNames.Pawn) { EventManager.TriggerEvent(Constants.EventNames.PawnsLanded); } else if (piece.GetType().Name == Constants.PieceClassNames.Bishop) { EventManager.TriggerEvent(Constants.EventNames.BishopsLanded); } else if (piece.GetType().Name == Constants.PieceClassNames.Knight) { EventManager.TriggerEvent(Constants.EventNames.KnightsLanded); } else if (piece.GetType().Name == Constants.PieceClassNames.Rook) { EventManager.TriggerEvent(Constants.EventNames.RooksLanded); } }
private static Type isMoveAnOpponentCapture(Move move) { Type capturedPieceType = typeof(AbstractPiece); Chessboard gameState = move.getPiece().GetChessboard(); AbstractPiece pieceAtMovePosition = gameState.GetPieceAtPosition(move.getPosition()); //TODO: Make it easier to get en passant positions Position enPassantPosition; AbstractPiece pieceAtEnPassantPosition = null; if (move.getPiece().GetType() == typeof(Pawn)) { if (move.getPiece().side == Side.Black) { enPassantPosition = new Position(move.getPosition().GetColumn(), move.getPosition().GetRow() + 1); } else { enPassantPosition = new Position(move.getPosition().GetColumn(), move.getPosition().GetRow() - 1); } pieceAtEnPassantPosition = gameState.GetPieceAtPosition(enPassantPosition); if (pieceAtEnPassantPosition != null && (pieceAtEnPassantPosition.GetType() != typeof(Pawn) || pieceAtEnPassantPosition.side == move.getPiece().side)) { pieceAtEnPassantPosition = null; } } // Normal captures if (pieceAtMovePosition != null && pieceAtMovePosition.side != move.getPiece().side) { capturedPieceType = pieceAtMovePosition.GetType(); } //En passant capture else if (pieceAtEnPassantPosition != null && ((Pawn)pieceAtEnPassantPosition).allowEnPassantCapture) { capturedPieceType = pieceAtEnPassantPosition.GetType(); } return(capturedPieceType); }
public static bool isSpaceship(AbstractPiece piece) { // The pieces that are represented as spaceships will have different animations, sound effects, etc. List <string> spaceshipPieceClassNames = new List <string> { Constants.PieceClassNames.Pawn, Constants.PieceClassNames.Rook, Constants.PieceClassNames.Bishop, Constants.PieceClassNames.Knight }; if (spaceshipPieceClassNames.Contains(piece.GetType().Name)) { return(true); } else { return(false); } }
public override void PostMoveActions() { // If the pawn has moved two steps this turn, it is allowed to be captured via the en passant rule if (this.side == Side.Black) { if (this.GetCurrentPosition().Equals(new Position(this.initialPosition.GetColumn(), this.initialPosition.GetRow() - 2))) { this.allowEnPassantCapture = true; } // The attacking pawn can check behind it to see if it passed an en passant-flagged pawn AbstractPiece passedPiece = this.chessBoard.GetPieceAtPosition(new Position(this.GetCurrentPosition().GetColumn(), this.GetCurrentPosition().GetRow() + 1)); if (passedPiece != null && passedPiece.GetType().Name.CompareTo(this.GetType().Name) == 0 && ((Pawn)passedPiece).allowEnPassantCapture) { this.chessBoard.KillPieceAtPosition(passedPiece.GetCurrentPosition(), this); } } else { if (this.GetCurrentPosition().Equals(new Position(this.initialPosition.GetColumn(), this.initialPosition.GetRow() + 2))) { this.allowEnPassantCapture = true; } AbstractPiece passedPiece = this.chessBoard.GetPieceAtPosition(new Position(this.GetCurrentPosition().GetColumn(), this.GetCurrentPosition().GetRow() - 1)); if (passedPiece != null && passedPiece.GetType().Name.CompareTo(this.GetType().Name) == 0 && ((Pawn)passedPiece).allowEnPassantCapture) { this.chessBoard.KillPieceAtPosition(passedPiece.GetCurrentPosition(), this); } } // Pawn Promotion if (this.side == Side.Black && this.GetCurrentPosition().GetRow() == Position.min || this.side == Side.White && this.GetCurrentPosition().GetRow() == Position.max) { Queen spawnedQueen = new Queen(this.currentPosition); spawnedQueen.side = this.side; spawnedQueen.SetChessboard(this.chessBoard); this.chessBoard.AddPiece(spawnedQueen); } }
protected override Bitboard AdditionalMoveProcessing(Bitboard movesForCurrentPosition) { // For pawns, extra moves would constitute: // 1. Normal attack // 2. En passant // Normal attack // Check the row ahead for opponent locations int rowToCheck; Side sideToCheck; if (this.side == Side.Black) { rowToCheck = this.GetCurrentPosition().GetRow() - 1; sideToCheck = Side.White; } else { rowToCheck = this.GetCurrentPosition().GetRow() + 1; sideToCheck = Side.Black; } Bitboard friendlyLocations = this.chessBoard.GetPieceLocations(this.side); Bitboard opponentLocations = this.chessBoard.GetPieceLocations(sideToCheck); // First, remove any moves that go through friendly or opponent movesForCurrentPosition = movesForCurrentPosition.ComputeRayIntersections(friendlyLocations, this.GetCurrentPosition(), false); movesForCurrentPosition = movesForCurrentPosition.ComputeRayIntersections(opponentLocations, this.GetCurrentPosition(), false); if (this.GetCurrentPosition().GetColumn() > Position.min) { if (opponentLocations.ValueAtPosition(new Position(this.GetCurrentPosition().GetColumn() - 1, rowToCheck)) > 0) { movesForCurrentPosition.FlipPosition(new Position(this.GetCurrentPosition().GetColumn() - 1, rowToCheck)); } } if (this.GetCurrentPosition().GetColumn() < Position.max) { if (opponentLocations.ValueAtPosition(new Position(this.GetCurrentPosition().GetColumn() + 1, rowToCheck)) > 0) { movesForCurrentPosition.FlipPosition(new Position(this.GetCurrentPosition().GetColumn() + 1, rowToCheck)); } } // En passant rowToCheck = this.GetCurrentPosition().GetRow(); if (this.GetCurrentPosition().GetColumn() > Position.min) { if (opponentLocations.ValueAtPosition(new Position(this.GetCurrentPosition().GetColumn() - 1, rowToCheck)) > 0) { // Also check if the piece at this location is a pawn which has just performed a double jump AbstractPiece passedPiece = this.chessBoard.GetPieceAtPosition(new Position(this.GetCurrentPosition().GetColumn() - 1, rowToCheck)); if (passedPiece != null && passedPiece.GetType().Name.CompareTo(this.GetType().Name) == 0 && ((Pawn)passedPiece).allowEnPassantCapture) { int attackPoint = rowToCheck; if (this.side == Side.Black) { attackPoint--; } else { attackPoint++; } movesForCurrentPosition.FlipPosition(new Position(this.GetCurrentPosition().GetColumn() - 1, attackPoint)); } } } if (this.GetCurrentPosition().GetColumn() < Position.max) { if (opponentLocations.ValueAtPosition(new Position(this.GetCurrentPosition().GetColumn() + 1, rowToCheck)) > 0) { AbstractPiece passedPiece = this.chessBoard.GetPieceAtPosition(new Position(this.GetCurrentPosition().GetColumn() + 1, rowToCheck)); if (passedPiece != null && passedPiece.GetType().Name.CompareTo(this.GetType().Name) == 0 && ((Pawn)passedPiece).allowEnPassantCapture) { int attackPoint = rowToCheck; if (this.side == Side.Black) { attackPoint--; } else { attackPoint++; } movesForCurrentPosition.FlipPosition(new Position(this.GetCurrentPosition().GetColumn() + 1, attackPoint)); } } } return(movesForCurrentPosition); }