Exemple #1
0
        /// <summary>
        ///
        /// проверка возможности следующего хода
        ///
        /// </summary>
        ///
        /// <param name="move">
        ///
        /// строковое представление хода
        ///
        /// </param>
        ///
        /// <returns>
        ///
        /// возвращаем новую доску с текущим ходом
        ///
        /// </returns>
        public Chess Move(string move)
        {
            FigureMoving figureMoving = new FigureMoving(move);

            /// <summary>
            ///
            /// если нельзя совершить указаный ход
            ///
            /// </summary>
            ///
            /// <returns>
            ///
            /// возвращаем текущее расположение шахмат
            ///
            /// </returns>
            if (!_moves.CanMove(figureMoving))
            {
                return(this); //ToDo : add new exception данный ход не возможен!!
            }
            if (_board.IsCheckAfter(figureMoving))
            {
                return(this);//ToDo : add new exception данный ход не возможен, IsCheck!!
            }

            Board nextBoard = _board.Move(figureMoving);
            Chess nextChess = new Chess(nextBoard);

            return(nextChess);
        }
Exemple #2
0
        public bool isValidMove(string move)
        {
            FigureMoving fm = new FigureMoving(move);

            if (!moves.CanMove(fm))
            {
                return(false);
            }
            if (board.IsCheckAfter(fm))
            {
                return(false);
            }
            return(true);
        }
Exemple #3
0
        /// <summary>
        ///
        /// метод который описывает алгоритм рокировки Короля
        ///
        /// </summary>
        /// <returns></returns>
        private bool CanKingCastle()
        {
            //  алгоритм рокировки белого короря
            if (_figureMoving.FigurE == Figure.whiteKing)
            {
                //  короткая рокировка белого короля
                if (_figureMoving.From == new Square("e1"))
                {
                    if (_figureMoving.To == new Square("g1"))
                    {
                        if (_board.CanCastleH1)
                        {
                            if (_board.GetFigureAt(new Square("h1")) == Figure.whiteRook)
                            {
                                if (_board.GetFigureAt(new Square("f1")) == Figure.none)
                                {
                                    if (_board.GetFigureAt(new Square("g1")) == Figure.none)
                                    {
                                        if (!_board.IsCheck())
                                        {
                                            if (!_board.IsCheckAfter(new FigureMoving("Ke1f1")))
                                            {
                                                return(true);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                //  длинная рокировка белого короря
                if (_figureMoving.From == new Square("e1"))
                {
                    if (_figureMoving.To == new Square("c1"))
                    {
                        if (_board.CanCastleA1)
                        {
                            if (_board.GetFigureAt(new Square("a1")) == Figure.whiteRook)
                            {
                                if (_board.GetFigureAt(new Square("b1")) == Figure.none)
                                {
                                    if (_board.GetFigureAt(new Square("c1")) == Figure.none)
                                    {
                                        if (_board.GetFigureAt(new Square("d1")) == Figure.none)
                                        {
                                            if (!_board.IsCheck())
                                            {
                                                if (!_board.IsCheckAfter(new FigureMoving("Ke1d1")))
                                                {
                                                    return(true);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //  алгоритм рокировки черного короля
            if (_figureMoving.FigurE == Figure.blackKing)
            {
                //  короткая рокировка черного короля
                if (_figureMoving.From == new Square("e8"))
                {
                    if (_figureMoving.To == new Square("g8"))
                    {
                        if (_board.CanCastleH8)
                        {
                            if (_board.GetFigureAt(new Square("h8")) == Figure.blackRook)
                            {
                                if (_board.GetFigureAt(new Square("f8")) == Figure.none)
                                {
                                    if (_board.GetFigureAt(new Square("g8")) == Figure.none)
                                    {
                                        if (!_board.IsCheck())
                                        {
                                            if (!_board.IsCheckAfter(new FigureMoving("ke8f8")))
                                            {
                                                return(true);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                //  длинная рокировка черного короля
                if (_figureMoving.From == new Square("e8"))
                {
                    if (_figureMoving.To == new Square("c8"))
                    {
                        if (_board.CanCastleA8)
                        {
                            if (_board.GetFigureAt(new Square("a8")) == Figure.blackRook)
                            {
                                if (_board.GetFigureAt(new Square("b8")) == Figure.none)
                                {
                                    if (_board.GetFigureAt(new Square("c8")) == Figure.none)
                                    {
                                        if (_board.GetFigureAt(new Square("d8")) == Figure.none)
                                        {
                                            if (!_board.IsCheck())
                                            {
                                                if (!_board.IsCheckAfter(new FigureMoving("ke8d8")))
                                                {
                                                    return(true);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
Exemple #4
0
        bool CanKingCastle()
        {
            if (fm.figure == Figure.whiteKing)
            {
                if (fm.from == new Square("e1"))
                {
                    if (fm.to == new Square("g1"))
                    {
                        if (board.canCastleH1)
                        {
                            if (board.GetFigureAt(new Square("h1")) == Figure.whiteRook)
                            {
                                if (board.GetFigureAt(new Square("f1")) == Figure.none)
                                {
                                    if (board.GetFigureAt(new Square("g1")) == Figure.none)
                                    {
                                        if (!board.IsCheck())
                                        {
                                            if (!board.IsCheckAfter(new FigureMoving("Ke1f1")))
                                            {
                                                return(true);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (fm.from == new Square("e1"))
                {
                    if (fm.to == new Square("c1"))
                    {
                        if (board.canCastleA1)
                        {
                            if (board.GetFigureAt(new Square("a1")) == Figure.whiteRook)
                            {
                                if (board.GetFigureAt(new Square("b1")) == Figure.none)
                                {
                                    if (board.GetFigureAt(new Square("c1")) == Figure.none)
                                    {
                                        if (board.GetFigureAt(new Square("d1")) == Figure.none)
                                        {
                                            if (!board.IsCheck())
                                            {
                                                if (!board.IsCheckAfter(new FigureMoving("Ke1d1")))
                                                {
                                                    return(true);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (fm.figure == Figure.blackKing)
            {
                if (fm.from == new Square("e8"))
                {
                    if (fm.to == new Square("g8"))
                    {
                        if (board.canCastleH8)
                        {
                            if (board.GetFigureAt(new Square("h8")) == Figure.blackRook)
                            {
                                if (board.GetFigureAt(new Square("f8")) == Figure.none)
                                {
                                    if (board.GetFigureAt(new Square("g8")) == Figure.none)
                                    {
                                        if (!board.IsCheck())
                                        {
                                            if (!board.IsCheckAfter(new FigureMoving("ke8f8")))
                                            {
                                                return(true);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (fm.figure == Figure.blackKing)
                {
                    if (fm.from == new Square("e8"))
                    {
                        if (fm.to == new Square("c8"))
                        {
                            if (board.canCastleA8)
                            {
                                if (board.GetFigureAt(new Square("a8")) == Figure.blackRook)
                                {
                                    if (board.GetFigureAt(new Square("b8")) == Figure.none)
                                    {
                                        if (board.GetFigureAt(new Square("c8")) == Figure.none)
                                        {
                                            if (board.GetFigureAt(new Square("d8")) == Figure.none)
                                            {
                                                if (!board.IsCheck())
                                                {
                                                    if (!board.IsCheckAfter(new FigureMoving("ke8d8")))
                                                    {
                                                        return(true);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
Exemple #5
0
 public bool IsValidMove(FigureMoving fm)
 {
     return(Moves.CanMove(fm) && !Board.IsCheckAfter(fm));
 }