Game/GameManager.cs
/// <summary>
/// Unique rule checking for king castling 
/// </summary>
/// <param name="king"></param>
/// <returns>returns king positions when castling is possible</returns>
Unique rule checking for king castling
Unique rule checking for king castling
private List<Coords> GetKingCastlingCoords(King king)
        {
            List<Coords> castling = new List<Coords>();
            if (king.HasMoved || king.Checks.Count > 0)
                return castling;
            List<Coords> availableAttacks = GetAllAvailableCoords(king.Side == PieceColor.White ? PieceColor.Black : PieceColor.White, true);
            King enemyKing = king.Side == PieceColor.White ? Board.BlackKing : Board.WhiteKing;
            if (!availableAttacks.Contains(king.Coords + 2) 
                && !enemyKing.AvailableCoords(Board.Tiles).Contains(king.Coords + 2)
                && !availableAttacks.Contains(king.Coords + 1)
                && Board.Tiles[(int)king.Coords + 4].Piece?.EPiece == EPiece.Rook
                && !((Rook)Board.Tiles[(int)king.Coords + 4].Piece).HasMoved)
                castling.Add(king.Coords + 2);
            if (!availableAttacks.Contains(king.Coords - 2) 
                && !enemyKing.AvailableCoords(Board.Tiles).Contains(king.Coords - 2)
                && !availableAttacks.Contains(king.Coords - 1)
                && Board.Tiles[(int)king.Coords - 3].Piece?.EPiece == EPiece.Rook
                && !((Rook)Board.Tiles[(int)king.Coords - 3].Piece).HasMoved)
                castling.Add(king.Coords - 2);
            return castling;
        }
private List < Coords > GetKingCastlingCoords ( King king ) { List < Coords > castling = new List < Coords > ( ) ; if ( king . HasMoved || king . Checks . Count > 0 ) return castling ; List < Coords > availableAttacks = GetAllAvailableCoords ( king . Side == PieceColor . White ? PieceColor . Black : PieceColor . White , true ) ; King enemyKing = king . Side == PieceColor . White ? Board . BlackKing : Board . WhiteKing ; if ( ! availableAttacks . Contains ( king . Coords + 2 ) && ! enemyKing . AvailableCoords ( Board . Tiles ) . Contains ( king . Coords + 2 ) && ! availableAttacks . Contains ( king . Coords + 1 ) && Board . Tiles [ ( int ) king . Coords + 4 ] . Piece ? . EPiece == EPiece . Rook && ! ( ( Rook ) Board . Tiles [ ( int ) king . Coords + 4 ] . Piece ) . HasMoved ) castling . Add ( king . Coords + 2 ) ; if ( ! availableAttacks . Contains ( king . Coords - 2 ) && ! enemyKing . AvailableCoords ( Board . Tiles ) . Contains ( king . Coords - 2 ) && ! availableAttacks . Contains ( king . Coords - 1 ) && Board . Tiles [ ( int ) king . Coords - 3 ] . Piece ? . EPiece == EPiece . Rook && ! ( ( Rook ) Board . Tiles [ ( int ) king . Coords - 3 ] . Piece ) . HasMoved ) castling . Add ( king . Coords - 2 ) ; return castling ; }
Unique rule checking for king castling
Unique rule checking for king castling
returns king positions when castling is possible
returns king positions when castling is possible
king
King
None