Ejemplo n.º 1
0
 void UpdateCheckFlags()
 {
     IsCheck     = boardController.isCheck();
     IsCheckMate = false;
     IsStalemate = false;
     foreach (string moves in YieldValidMoves())
     {
         return;
     }
     if (IsCheck)
     {
         IsCheckMate = true;
     }
     else
     {
         IsStalemate = true;
     }
 }
Ejemplo n.º 2
0
        private bool CheckCanCastling()
        {
            if (moveController.CurrentFigure == Figure.whiteKing)
            {
                Cell whiteKingStartPosition       = new Cell(Constants.WHITE_KING_START_POSITION);
                Cell whiteCastlingPositionToRight = new Cell(whiteKingStartPosition.x +
                                                             Constants.DIF_POSITION_KING_X_AFTER_CASTLING, whiteKingStartPosition.y);
                Cell whiteCastlingPositionToLeft = new Cell(whiteKingStartPosition.x -
                                                            Constants.DIF_POSITION_KING_X_AFTER_CASTLING, whiteKingStartPosition.y);

                if (moveController.CurrentCell == whiteKingStartPosition && //check can castling to right (white)
                    moveController.NewCell == whiteCastlingPositionToRight)
                {
                    if (boardController.CanCastlingH1 && boardController.GetFigureAtCell(
                            new Cell(Constants.COUNT_SQUARES - 1, 0)) == Figure.whiteRook)
                    {
                        if (checkCellsForEmpty(whiteKingStartPosition, whiteCastlingPositionToRight))
                        {
                            if (!boardController.isCheck())
                            {
                                if (!boardController.isCheckAfter(new MoveController(new FigureOnCell(
                                                                                         Figure.whiteKing, whiteKingStartPosition), new Cell(whiteKingStartPosition.x + 1, 0))))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }

                if (moveController.CurrentCell == whiteKingStartPosition && //check can castling to left (white)
                    moveController.NewCell == whiteCastlingPositionToLeft)
                {
                    if (boardController.CanCastlingA1 && boardController.GetFigureAtCell(
                            new Cell(0, 0)) == Figure.whiteRook)
                    {
                        if (checkCellsForEmpty(whiteKingStartPosition, whiteCastlingPositionToLeft))
                        {
                            if (!boardController.isCheck())
                            {
                                if (!boardController.isCheckAfter(new MoveController(new FigureOnCell(
                                                                                         Figure.whiteKing, whiteKingStartPosition), new Cell(whiteKingStartPosition.x - 1, 0))))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            else if (moveController.CurrentFigure == Figure.blackKing)
            {
                Cell blackKingStartPosition       = new Cell(Constants.BLACK_KING_START_POSITION);
                Cell blackCastlingPositionToRight = new Cell(blackKingStartPosition.x +
                                                             Constants.DIF_POSITION_KING_X_AFTER_CASTLING, blackKingStartPosition.y);
                Cell blackCastlingPositionToLeft = new Cell(blackKingStartPosition.x -
                                                            Constants.DIF_POSITION_KING_X_AFTER_CASTLING, blackKingStartPosition.y);

                if (moveController.CurrentCell == blackKingStartPosition && //check can castling to right (black)
                    moveController.NewCell == blackCastlingPositionToRight)
                {
                    if (boardController.CanCastlingH8 && boardController.GetFigureAtCell(
                            new Cell(Constants.COUNT_SQUARES - 1, Constants.COUNT_SQUARES - 1)) == Figure.blackRook)
                    {
                        if (checkCellsForEmpty(blackKingStartPosition, blackCastlingPositionToRight))
                        {
                            if (!boardController.isCheck())
                            {
                                if (!boardController.isCheckAfter(new MoveController(new FigureOnCell(
                                                                                         Figure.blackKing, blackKingStartPosition), new Cell(blackKingStartPosition.x + 1, Constants.COUNT_SQUARES - 1))))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }

                if (moveController.CurrentCell == blackKingStartPosition && //check can castling to left (black)
                    moveController.NewCell == blackCastlingPositionToLeft)
                {
                    if (boardController.CanCastlingA8 && boardController.GetFigureAtCell(
                            new Cell(0, Constants.COUNT_SQUARES - 1)) == Figure.blackRook)
                    {
                        if (checkCellsForEmpty(blackKingStartPosition, blackCastlingPositionToLeft))
                        {
                            if (!boardController.isCheck())
                            {
                                if (!boardController.isCheckAfter(new MoveController(new FigureOnCell(
                                                                                         Figure.blackKing, blackKingStartPosition), new Cell(blackKingStartPosition.x - 1, Constants.COUNT_SQUARES - 1))))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }