Пример #1
0
        public override bool AreMovePositionsPossible(NormalMovePositions move)
        {
            Rook   rook   = new Rook(Colors.Black);
            Bishop bishop = new Bishop(Colors.Black);

            return(rook.AreMovePositionsPossible(move) || bishop.AreMovePositionsPossible(move));
        }
Пример #2
0
        public List <PositionOnTheBoard> GetPositionsInTheWayOfMove(NormalMovePositions normalMove)
        {
            if (this.AreMovePositionsPossible(normalMove) == false)
            {
                throw new InvalidMoveException("InvalidMove");
            }

            List <PositionOnTheBoard> positionsOnTheBoard = new List <PositionOnTheBoard>();

            if (normalMove.InitialPosition.Horizontal == normalMove.TargetPosition.Horizontal)
            {
                for (int i = Math.Min(normalMove.InitialPosition.Vertical, normalMove.TargetPosition.Vertical) + 1;
                     i < Math.Max(normalMove.InitialPosition.Vertical, normalMove.TargetPosition.Vertical); i++)
                {
                    positionsOnTheBoard.Add(new PositionOnTheBoard(normalMove.InitialPosition.Horizontal, i));
                }
            }

            if (normalMove.InitialPosition.Vertical == normalMove.TargetPosition.Vertical)
            {
                for (int i = Math.Min(normalMove.InitialPosition.Horizontal, normalMove.TargetPosition.Horizontal) + 1;
                     i < Math.Max(normalMove.InitialPosition.Horizontal, normalMove.TargetPosition.Horizontal); i++)
                {
                    positionsOnTheBoard.Add(new PositionOnTheBoard((char)i, normalMove.InitialPosition.Vertical));
                }
            }

            return(positionsOnTheBoard);
        }
Пример #3
0
        public List <PositionOnTheBoard> GetPositionsInTheWayOfMove(NormalMovePositions normalMove)
        {
            if (this.AreMovePositionsPossible(normalMove) == false && this.IsAttackingMovePossible(normalMove) == false)
            {
                throw new InvalidMoveException("");
            }
            if (this.IsAttackingMovePossible(normalMove))
            {
                return(new List <PositionOnTheBoard>());
            }
            int differenceInHorizontal = Math.Abs(normalMove.InitialPosition.Horizontal - normalMove.TargetPosition.Horizontal);
            int differenceInVertical   = Math.Abs(normalMove.InitialPosition.Vertical - normalMove.TargetPosition.Vertical);


            if (this.color == Colors.White && normalMove.InitialPosition.Vertical == 2 && normalMove.TargetPosition.Vertical == 4)
            {
                return(new List <PositionOnTheBoard>()
                {
                    new PositionOnTheBoard(normalMove.InitialPosition.Horizontal, 3)
                });
            }

            if (this.color == Colors.Black && normalMove.InitialPosition.Vertical == 7 && normalMove.TargetPosition.Vertical == 5)
            {
                return(new List <PositionOnTheBoard>()
                {
                    new PositionOnTheBoard(normalMove.InitialPosition.Horizontal, 6)
                });
            }



            return(new List <PositionOnTheBoard>());
        }
Пример #4
0
        public bool IsAttackingMovePossible(NormalMovePositions move)
        {
            if (this.color == Colors.White)
            {
                int differenceInHorizontal = Math.Abs(move.InitialPosition.Horizontal - move.TargetPosition.Horizontal);
                int differenceInVertical   = move.InitialPosition.Vertical - move.TargetPosition.Vertical;

                if (differenceInHorizontal == 1 && differenceInVertical == -1)
                {
                    return(true);
                }
            }
            else
            {
                int differenceInHorizontal = Math.Abs(move.InitialPosition.Horizontal - move.TargetPosition.Horizontal);
                int differenceInVertical   = move.InitialPosition.Vertical - move.TargetPosition.Vertical;

                if (differenceInHorizontal == 1 && differenceInVertical == 1)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #5
0
        public override bool AreMovePositionsPossible(NormalMovePositions move)
        {
            int differenceInHorizontal = Math.Abs(move.InitialPosition.Horizontal - move.TargetPosition.Horizontal);
            int differenceInVertical   = Math.Abs(move.InitialPosition.Vertical - move.TargetPosition.Vertical);

            if (differenceInHorizontal == 0 && (differenceInVertical == 1 || differenceInVertical == 2))
            {
                if (this.color == Colors.White && move.InitialPosition.Vertical == 2 && move.TargetPosition.Vertical == 4)
                {
                    return(true);
                }

                if (this.color == Colors.Black && move.InitialPosition.Vertical == 7 && move.TargetPosition.Vertical == 5)
                {
                    return(true);
                }

                if (this.color == Colors.White && move.InitialPosition.Vertical + 1 == move.TargetPosition.Vertical)
                {
                    return(true);
                }

                if (this.color == Colors.Black && move.InitialPosition.Vertical - 1 == move.TargetPosition.Vertical)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #6
0
        public ChessBoard GetVirtualChessBoardAfterMove(NormalMovePositions normalMove)
        {
            ChessBoard chessBoard = CopyCurrentChessBoard();
            var        figure     = chessBoard.GetFigureOnPosition(normalMove.InitialPosition);

            chessBoard.RemoveFigureOnPosition(normalMove.InitialPosition);
            chessBoard.PutFigureOnPositionWithoutMovingItActualy(normalMove.TargetPosition, figure);

            return(chessBoard);
        }
Пример #7
0
        public override bool AreMovePositionsPossible(NormalMovePositions move)
        {
            if ((move.InitialPosition.Horizontal == move.TargetPosition.Horizontal ||
                 move.InitialPosition.Vertical == move.TargetPosition.Vertical) && !move.InitialPosition.Equals(move.TargetPosition)
                )
            {
                return(true);
            }

            return(false);
        }
Пример #8
0
        public override bool AreMovePositionsPossible(NormalMovePositions move)
        {
            int differenceInHorizontal = Math.Abs(move.InitialPosition.Horizontal - move.TargetPosition.Horizontal);
            int differenceInVertical   = Math.Abs(move.InitialPosition.Vertical - move.TargetPosition.Vertical);

            if (differenceInHorizontal == differenceInVertical && differenceInVertical != 0)
            {
                return(true);
            }

            return(false);
        }
Пример #9
0
        public List <PositionOnTheBoard> GetPositionsInTheWayOfMove(NormalMovePositions normalMove)
        {
            if (this.AreMovePositionsPossible(normalMove) == false)
            {
                throw new InvalidMoveException("InvalidMove");
            }

            List <PositionOnTheBoard> positionsOnTheBoard = new List <PositionOnTheBoard>();

            int differenceInHorizontal = normalMove.InitialPosition.Horizontal - normalMove.TargetPosition.Horizontal;
            int differenceInVertical   = normalMove.InitialPosition.Vertical - normalMove.TargetPosition.Vertical;

            for (int i = 1; i < Math.Abs(differenceInHorizontal); i++)
            {
                if (differenceInHorizontal > 0 && differenceInVertical > 0)
                {
                    positionsOnTheBoard.Add(new PositionOnTheBoard((char)(normalMove.InitialPosition.Horizontal - i), normalMove.InitialPosition.Vertical - i));
                }
                if (differenceInHorizontal < 0 && differenceInVertical > 0)
                {
                    positionsOnTheBoard.Add(new PositionOnTheBoard((char)(normalMove.InitialPosition.Horizontal + i), normalMove.InitialPosition.Vertical - i));
                }
                if (differenceInHorizontal > 0 && differenceInVertical < 0)
                {
                    positionsOnTheBoard.Add(new PositionOnTheBoard((char)(normalMove.InitialPosition.Horizontal - i), normalMove.InitialPosition.Vertical + i));
                }
                if (differenceInHorizontal < 0 && differenceInVertical < 0)
                {
                    positionsOnTheBoard.Add(new PositionOnTheBoard((char)(normalMove.InitialPosition.Horizontal + i), normalMove.InitialPosition.Vertical + i));
                }
            }

            return(positionsOnTheBoard);
            //if (differenceInHorizontal > 0)
            //{
            //    for (int i = 1; i < differenceInHorizontal; i++)
            //    {
            //        positionOnTheBoard.Add(new PositionOnTheBoard((char)(normalMove.InitialPosition.Horizontal + i), normalMove.InitialPosition.Vertical + i));
            //    }
            //}
            //else
            //{
            //    for (int i = -1; i > differenceInHorizontal; i++)
            //    {
            //        positionOnTheBoard.Add(new PositionOnTheBoard((char)(normalMove.InitialPosition.Horizontal + i), normalMove.InitialPosition.Vertical + i));
            //    }
            //}
        }
Пример #10
0
        public List <PositionOnTheBoard> GetPositionsInTheWayOfMove(NormalMovePositions normalMove)
        {
            if (this.AreMovePositionsPossible(normalMove) == false)
            {
                throw new InvalidMoveException("InvalidMove");
            }

            List <PositionOnTheBoard> positionsOnTheBoard = new List <PositionOnTheBoard>();

            Rook   rook   = new Rook(Colors.Black);
            Bishop bishop = new Bishop(Colors.Black);

            if (rook.AreMovePositionsPossible(normalMove))
            {
                positionsOnTheBoard = rook.GetPositionsInTheWayOfMove(normalMove);
            }

            if (bishop.AreMovePositionsPossible(normalMove))
            {
                positionsOnTheBoard = bishop.GetPositionsInTheWayOfMove(normalMove);
            }

            return(positionsOnTheBoard);
        }
Пример #11
0
 public abstract bool AreMovePositionsPossible(NormalMovePositions move);