Exemple #1
0
        public Board Move(FigureMoving figureMoving)
        {
            Board next = new Board(fen);

            next.SetFigureAt(figureMoving.from, Figure.none);

            if (figureMoving.promotion == Figure.none)
            {
                next.SetFigureAt(figureMoving.to, figureMoving.figure);
            }
            else
            {
                next.SetFigureAt(figureMoving.to, figureMoving.promotion);
            }

            if (moveColor == Color.black)
            {
                next.moveNumber++;
            }

            next.moveColor = moveColor.FlipColor();
            next.GenereteFen();

            return(next);
        }
Exemple #2
0
        /// <summary>
        ///
        /// метод который описывает:
        /// движения ЛЮБОЙ фигуры
        ///
        /// </summary>
        /// <param name="figureMoving"> фигура которая совершает движение </param>
        /// <returns>
        ///
        /// возвращает логическое значение
        /// может ли ДАННАЯ фигура совершать ход
        ///
        /// </returns>
        public bool IsCanMove(FigureMoving figureMoving)
        {
            this.figureMoving = figureMoving;
            bool canMove = CanMoveFrom() &&
                           CanMoveTo() &&
                           CanFigureMove();

            return(canMove);
        }
Exemple #3
0
        private bool CanEatKing()
        {
            bool myBool = false;

            Square enemyKing = FindEnemyKing();
            Moves  moves     = new Moves(this);

            foreach (FigureOnSquare figureOnSquare in YieldFigure())
            {
                FigureMoving figureMoving = new FigureMoving(figureOnSquare, enemyKing);

                if (moves.IsCanMove(figureMoving))
                {
                    myBool = true;
                }
            }

            return(myBool);
        }
Exemple #4
0
        public Chess Move(string move)
        {
            FigureMoving figureMoving = new FigureMoving(move);

            if (!moves.IsCanMove(figureMoving))
            {
                Console.WriteLine("Данный ход не возможен!!");
                return(this);
            }
            if (board.IsChekAfterMove(figureMoving))
            {
                Console.WriteLine("Данный ход не возможен!!");
                return(this);
            }

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

            return(nextChess);
        }
Exemple #5
0
        private void FindAllMoves()
        {
            allMoves = new List <FigureMoving>();

            foreach (FigureOnSquare figureOnSquare in board.YieldFigure())
            {
                foreach (Square to in Square.YieldSquares())
                {
                    FigureMoving figureMoving = new FigureMoving(figureOnSquare, to);

                    if (moves.IsCanMove(figureMoving))
                    {
                        if (!board.IsChekAfterMove(figureMoving))
                        {
                            allMoves.Add(figureMoving);
                        }
                    }
                }
            }
        }
Exemple #6
0
        public bool IsChekAfterMove(FigureMoving figureMoving)
        {
            Board after = Move(figureMoving);

            return(after.CanEatKing());
        }