Пример #1
0
        public override bool[,] PossibleMoves()
        {
            bool[,] possibleMoves = new bool[Board.Lines, Board.Columns];
            Position virtualPosition = new Position(0, 0);

            //North-east
            virtualPosition.ChangeToPosition(Position.Line - 1, Position.Column + 1);
            while (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
                if (Board.GetPiece(virtualPosition) != null && Board.GetPiece(virtualPosition).Color != Color)
                {
                    break;
                }
                virtualPosition.Line   = virtualPosition.Line - 1;
                virtualPosition.Column = virtualPosition.Column + 1;
            }

            //South-east
            virtualPosition.ChangeToPosition(Position.Line + 1, Position.Column + 1);
            while (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
                if (Board.GetPiece(virtualPosition) != null && Board.GetPiece(virtualPosition).Color != Color)
                {
                    break;
                }
                virtualPosition.Line   = virtualPosition.Line + 1;
                virtualPosition.Column = virtualPosition.Column + 1;
            }

            //North-West
            virtualPosition.ChangeToPosition(Position.Line - 1, Position.Column - 1);
            while (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
                if (Board.GetPiece(virtualPosition) != null && Board.GetPiece(virtualPosition).Color != Color)
                {
                    break;
                }
                virtualPosition.Line   = virtualPosition.Line - 1;
                virtualPosition.Column = virtualPosition.Column - 1;
            }

            //South-west
            virtualPosition.ChangeToPosition(Position.Line + 1, Position.Column - 1);
            while (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
                if (Board.GetPiece(virtualPosition) != null && Board.GetPiece(virtualPosition).Color != Color)
                {
                    break;
                }
                virtualPosition.Line   = virtualPosition.Line + 1;
                virtualPosition.Column = virtualPosition.Column - 1;
            }
            return(possibleMoves);
        }
Пример #2
0
        public override bool[,] PossibleMoves()
        {
            bool[,] possibleMoves = new bool[Board.Lines, Board.Columns];
            Position virtualPosition = new Position(0, 0);

            //Check white pieces - only move North
            if (Color == Color.White)
            {
                //Inital move allow 2 squares
                virtualPosition.ChangeToPosition(Position.Line - 2, Position.Column);
                if (Board.CheckBoardLimits(virtualPosition) && QtyMovement == 0 && IsEmpty(virtualPosition))
                {
                    possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
                }

                //Regular move allow 1 square
                virtualPosition.ChangeToPosition(Position.Line - 1, Position.Column);
                if (Board.CheckBoardLimits(virtualPosition) && IsEmpty(virtualPosition))
                {
                    possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
                }

                //Diagonal capture - North-east
                virtualPosition.ChangeToPosition(Position.Line - 1, Position.Column + 1);
                if (Board.CheckBoardLimits(virtualPosition) && HasEnemy(virtualPosition))
                {
                    possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
                }

                //Diagonal capture - North-west
                virtualPosition.ChangeToPosition(Position.Line - 1, Position.Column - 1);
                if (Board.CheckBoardLimits(virtualPosition) && HasEnemy(virtualPosition))
                {
                    possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
                }


                //Special move: En passant
                if (Position.Line == 3)
                {
                    Position left = new Position(Position.Line, Position.Column - 1);
                    if (Board.CheckBoardLimits(left) && HasEnemy(left) && Board.GetPiece(left) == Game.VulnerableToEnPassant)
                    {
                        possibleMoves[Position.Line - 1, Position.Column - 1] = true;
                    }

                    Position right = new Position(Position.Line, Position.Column + 1);
                    if (Board.CheckBoardLimits(right) && HasEnemy(right) && Board.GetPiece(right) == Game.VulnerableToEnPassant)
                    {
                        possibleMoves[Position.Line - 1, Position.Column + 1] = true;
                    }
                }
            }

            //Check black pieces - only move South
            if (Color == Color.Black)
            {
                //Inital move allow 2 squares
                virtualPosition.ChangeToPosition(Position.Line + 2, Position.Column);
                if (Board.CheckBoardLimits(virtualPosition) && QtyMovement == 0 && IsEmpty(virtualPosition))
                {
                    possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
                }

                //Regular move allow 1 square
                virtualPosition.ChangeToPosition(Position.Line + 1, Position.Column);
                if (Board.CheckBoardLimits(virtualPosition) && IsEmpty(virtualPosition))
                {
                    possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
                }

                //Diagonal capture - South-east
                virtualPosition.ChangeToPosition(Position.Line + 1, Position.Column + 1);
                if (Board.CheckBoardLimits(virtualPosition) && HasEnemy(virtualPosition))
                {
                    possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
                }

                //Diagonal capture - South-west
                virtualPosition.ChangeToPosition(Position.Line + 1, Position.Column - 1);
                if (Board.CheckBoardLimits(virtualPosition) && HasEnemy(virtualPosition))
                {
                    possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
                }

                //Special move: En passant
                if (Position.Line == 4)
                {
                    Position left = new Position(Position.Line, Position.Column - 1);
                    if (Board.CheckBoardLimits(left) && HasEnemy(left) && Board.GetPiece(left) == Game.VulnerableToEnPassant)
                    {
                        possibleMoves[Position.Line + 1, Position.Column - 1] = true;
                    }

                    Position right = new Position(Position.Line, Position.Column + 1);
                    if (Board.CheckBoardLimits(right) && HasEnemy(right) && Board.GetPiece(right) == Game.VulnerableToEnPassant)
                    {
                        possibleMoves[Position.Line + 1, Position.Column + 1] = true;
                    }
                }
            }



            return(possibleMoves);
        }
Пример #3
0
        public override bool[,] PossibleMoves()
        {
            bool[,] possibleMoves = new bool[Board.Lines, Board.Columns];
            Position virtualPosition = new Position(0, 0);

            //North

            virtualPosition.ChangeToPosition(Position.Line - 1, Position.Column);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //South

            virtualPosition.ChangeToPosition(Position.Line + 1, Position.Column);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //East

            virtualPosition.ChangeToPosition(Position.Line, Position.Column + 1);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //West
            virtualPosition.ChangeToPosition(Position.Line, Position.Column - 1);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //NW

            virtualPosition.ChangeToPosition(Position.Line - 1, Position.Column - 1);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //NE

            virtualPosition.ChangeToPosition(Position.Line - 1, Position.Column + 1);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //SE

            virtualPosition.ChangeToPosition(Position.Line + 1, Position.Column + 1);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //SW

            virtualPosition.ChangeToPosition(Position.Line + 1, Position.Column - 1);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //Special move: Castling
            if (QtyMovement == 0 && !Game.PlayerInCheck)
            {
                //Short Castling
                Position RookPosition = new Position(Position.Line, Position.Column + 3);
                if (CastlingCheck(RookPosition))
                {
                    Position pos1 = new Position(Position.Line, Position.Column + 1);
                    Position pos2 = new Position(Position.Line, Position.Column + 2);
                    if (Board.GetPiece(pos1) == null && Board.GetPiece(pos2) == null)
                    {
                        possibleMoves[Position.Line, Position.Column + 2] = true;
                    }
                }

                //Long Castling
                RookPosition = new Position(Position.Line, Position.Column - 4);
                if (CastlingCheck(RookPosition))
                {
                    Position pos1 = new Position(Position.Line, Position.Column - 1);
                    Position pos2 = new Position(Position.Line, Position.Column - 2);
                    Position pos3 = new Position(Position.Line, Position.Column - 3);
                    if (Board.GetPiece(pos1) == null && Board.GetPiece(pos2) == null && Board.GetPiece(pos3) == null)
                    {
                        possibleMoves[Position.Line, Position.Column - 2] = true;
                    }
                }
            }


            return(possibleMoves);
        }
        public override bool[,] PossibleMoves()
        {
            bool[,] possibleMoves = new bool[Board.Lines, Board.Columns];
            Position virtualPosition = new Position(0, 0);

            //North-right

            virtualPosition.ChangeToPosition(Position.Line - 2, Position.Column + 1);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //North-left

            virtualPosition.ChangeToPosition(Position.Line - 2, Position.Column - 1);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //East-up

            virtualPosition.ChangeToPosition(Position.Line - 1, Position.Column + 2);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //East-down
            virtualPosition.ChangeToPosition(Position.Line + 1, Position.Column + 2);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //South-right

            virtualPosition.ChangeToPosition(Position.Line + 2, Position.Column + 1);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //South-left

            virtualPosition.ChangeToPosition(Position.Line + 2, Position.Column - 1);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //West-down

            virtualPosition.ChangeToPosition(Position.Line + 1, Position.Column - 2);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }

            //West-up

            virtualPosition.ChangeToPosition(Position.Line - 1, Position.Column - 2);
            if (Board.CheckBoardLimits(virtualPosition) && EmptyOrEnemy(virtualPosition))
            {
                possibleMoves[virtualPosition.Line, virtualPosition.Column] = true;
            }
            return(possibleMoves);
        }