Game/Pieces/Bishop.cs
/// <summary>
/// Reusable method for calculating valid position within the board
/// </summary>
/// <param name="board"></param>
/// <param name="corner"></param>
/// <param name="op"></param>
/// <param name="xRay"></param>
/// <param name="updateBlockingPieces"></param>
/// <returns></returns>
Reusable method for calculating valid position within the board
Reusable method for calculating valid position within the board
private List<Coords> HandleCoords(Tile[] board, int corner, Func<int, int, int> op, bool xRay, bool updateBlockingPieces)
        {
            List<Coords> coordsList = new List<Coords>();
            bool finished = false;
            int rotation = 1;
            while (!finished)
            {
                Coords coordinate = (Coords) op((int) Coords, rotation);
                if(!ValidCoordinate(board, coordinate, corner, true))
                    break;
                if (board[(int) coordinate].Piece?.Side == Side)
                {
                    if(!xRay)
                        break;
                    finished = true;
                }
                if (board.HasPawnOnTile(coordinate) && board[(int) coordinate].Piece.Side != Side)
                {
                    if (updateBlockingPieces)
                    {
                        if(coordinate.Column() != corner)
                            HandleBlocking(board, board[(int) coordinate].Piece, op, corner, rotation + 1);
                        HandleTargetKing(board, op, corner, rotation);
                    }
                    finished = true;
                }
                coordsList.Add(coordinate);
                if (coordinate.Column() == corner)
                    finished = true;
                rotation++;
            }
            return FilterKingProtectionCoords(coordsList);
        }
private List < Coords > HandleCoords ( Tile [ ] board , int corner , Func < int , int , int > op , bool xRay , bool updateBlockingPieces ) { List < Coords > coordsList = new List < Coords > ( ) ; bool finished = false ; int rotation = 1 ; while ( ! finished ) { Coords coordinate = ( Coords ) op ( ( int ) Coords , rotation ) ; if ( ! ValidCoordinate ( board , coordinate , corner , true ) ) break ; if ( board [ ( int ) coordinate ] . Piece ? . Side == Side ) { if ( ! xRay ) break ; finished = true ; } if ( board . HasPawnOnTile ( coordinate ) && board [ ( int ) coordinate ] . Piece . Side != Side ) { if ( updateBlockingPieces ) { if ( coordinate . Column ( ) != corner ) HandleBlocking ( board , board [ ( int ) coordinate ] . Piece , op , corner , rotation + 1 ) ; HandleTargetKing ( board , op , corner , rotation ) ; } finished = true ; } coordsList . Add ( coordinate ) ; if ( coordinate . Column ( ) == corner ) finished = true ; rotation ++ ; } return FilterKingProtectionCoords ( coordsList ) ; }
Reusable method for calculating valid position within the board
Reusable method for calculating valid position within the board
None
board
Tile[]
None
corner
int
None
op
Func<int, int, int>
None
xRay
bool
None
updateBlockingPieces
bool
None