Пример #1
0
        public override bool[,] PossibleMovements()
        {
            bool[,] matrix = new bool[Board.Rows, Board.Columns];

            Position pos = new Position(0, 0);

            //Above
            pos.DefineValues(Position.Row - 1, Position.Column);
            while (Board.PositionIsValid(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Column] = true;
                if (Board.piece(pos) != null && Board.piece(pos).Color != Color)
                {
                    break;
                }
                pos.Row = pos.Row - 1;
            }


            //Below
            pos.DefineValues(Position.Row + 1, Position.Column);
            while (Board.PositionIsValid(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Column] = true;
                if (Board.piece(pos) != null && Board.piece(pos).Color != Color)
                {
                    break;
                }
                pos.Row = pos.Row + 1;
            }


            //Right
            pos.DefineValues(Position.Row, Position.Column - 1);
            while (Board.PositionIsValid(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Column] = true;
                if (Board.piece(pos) != null && Board.piece(pos).Color != Color)
                {
                    break;
                }
                pos.Column = pos.Column - 1;
            }

            //Left
            pos.DefineValues(Position.Row, Position.Column + 1);
            while (Board.PositionIsValid(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Column] = true;
                if (Board.piece(pos) != null && Board.piece(pos).Color != Color)
                {
                    break;
                }
                pos.Column = pos.Column + 1;
            }



            return(matrix);
        }
Пример #2
0
        public override bool[,] PossibleMoves()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];
            Position pos = new Position(0, 0);

            //Ne
            pos.DefineValues(Position.Line - 1, Position.Column - 1);
            while (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (Board.Piece(pos) != null && Board.Piece(pos).Color != Color)
                {
                    break;
                }

                pos.Line   = pos.Line - 1;
                pos.Column = pos.Column - 1;
            }
            //Se
            pos.DefineValues(Position.Line + 1, Position.Column + 1);
            while (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (Board.Piece(pos) != null && Board.Piece(pos).Color != Color)
                {
                    break;
                }

                pos.Line   = pos.Line + 1;
                pos.Column = pos.Column + 1;
            }
            //Nw
            pos.DefineValues(Position.Line - 1, Position.Column + 1);
            while (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (Board.Piece(pos) != null && Board.Piece(pos).Color != Color)
                {
                    break;
                }

                pos.Line   = pos.Line - 1;
                pos.Column = pos.Column + 1;
            }
            //Ne
            pos.DefineValues(Position.Line + 1, Position.Column - 1);
            while (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (Board.Piece(pos) != null && Board.Piece(pos).Color != Color)
                {
                    break;
                }

                pos.Line   = pos.Line + 1;
                pos.Column = pos.Column - 1;
            }

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

            Position pos = new Position(0, 0);

            // above
            pos.DefineValues(Position.Line - 1, Position.Column);
            while (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                // found an enemy piece
                if (Board.Piece(pos) != null && Board.Piece(pos).Color != Color)
                {
                    break;
                }
                pos.Line = pos.Line - 1;
            }

            // below
            pos.DefineValues(Position.Line + 1, Position.Column);
            while (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                // found an enemy piece
                if (Board.Piece(pos) != null && Board.Piece(pos).Color != Color)
                {
                    break;
                }
                pos.Line = pos.Line + 1;
            }

            // right
            pos.DefineValues(Position.Line, Position.Column + 1);
            while (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                // found an enemy piece
                if (Board.Piece(pos) != null && Board.Piece(pos).Color != Color)
                {
                    break;
                }
                pos.Column = pos.Column + 1;
            }

            // left
            pos.DefineValues(Position.Line, Position.Column - 1);
            while (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                // found an enemy piece
                if (Board.Piece(pos) != null && Board.Piece(pos).Color != Color)
                {
                    break;
                }
                pos.Column = pos.Column - 1;
            }

            return(mat);
        }
Пример #4
0
        public override bool[,] PossibleMovements()
        {
            bool[,] matrix = new bool[Board.Rows, Board.Columns];

            Position position = new Position(0, 0);

            //North
            position.DefineValues(Position.Row - 1, Position.Column);
            while (Board.IsValid(position) && AllowedToMove(position))
            {
                matrix[position.Row, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.Row--;
            }

            //South
            position.DefineValues(Position.Row + 1, Position.Column);
            while (Board.IsValid(position) && AllowedToMove(position))
            {
                matrix[position.Row, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.Row++;
            }

            //East
            position.DefineValues(Position.Row, Position.Column + 1);
            while (Board.IsValid(position) && AllowedToMove(position))
            {
                matrix[position.Row, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.Column++;
            }

            //West
            position.DefineValues(Position.Row, Position.Column - 1);
            while (Board.IsValid(position) && AllowedToMove(position))
            {
                matrix[position.Row, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.Column--;
            }

            return(matrix);
        }
Пример #5
0
        public override bool[,] PossibleMovements()
        {
            bool[,] mat = new bool[Gameboard.Rows, Gameboard.Columns];

            Position pos = new Position(0, 0);

            // north
            pos.DefineValues(Position.Row - 1, Position.Column);
            while (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
                if (Gameboard.Piece(pos) != null && Gameboard.Piece(pos).Color != Color)
                {
                    break;
                }
                pos.Row = pos.Row - 1;
            }

            // south
            pos.DefineValues(Position.Row + 1, Position.Column);
            while (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
                if (Gameboard.Piece(pos) != null && Gameboard.Piece(pos).Color != Color)
                {
                    break;
                }
                pos.Row = pos.Row + 1;
            }

            // east
            pos.DefineValues(Position.Row, Position.Column + 1);
            while (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
                if (Gameboard.Piece(pos) != null && Gameboard.Piece(pos).Color != Color)
                {
                    break;
                }
                pos.Column = pos.Column + 1;
            }

            // west
            pos.DefineValues(Position.Row, Position.Column - 1);
            while (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
                if (Gameboard.Piece(pos) != null && Gameboard.Piece(pos).Color != Color)
                {
                    break;
                }
                pos.Column = pos.Column - 1;
            }

            return(mat);
        }
Пример #6
0
        public override bool[,] PossibleMovements()
        {
            bool[,] movementPossibilitiesMatrix = new bool[Board.Lines, Board.Columns];
            // Instantiate a new position with placeholder values
            Position position = new Position(0, 0);

            // North of the piece
            position.DefineValues(Position.Line - 1, Position.Column);
            while (Board.ValidPosition(position) && CanMoveToPosition(position))
            {
                movementPossibilitiesMatrix[position.Line, position.Column] = true;
                // Forced stop when the Rook meets an adversary Piece
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.Line = position.Line - 1;
            }
            // East of the piece
            position.DefineValues(Position.Line, Position.Column + 1);
            while (Board.ValidPosition(position) && CanMoveToPosition(position))
            {
                movementPossibilitiesMatrix[position.Line, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.Column = position.Column + 1;
            }
            // South of the piece
            position.DefineValues(Position.Line + 1, Position.Column);
            while (Board.ValidPosition(position) && CanMoveToPosition(position))
            {
                movementPossibilitiesMatrix[position.Line, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.Line = position.Line + 1;
            }
            // West of the piece
            position.DefineValues(Position.Line, Position.Column - 1);
            while (Board.ValidPosition(position) && CanMoveToPosition(position))
            {
                movementPossibilitiesMatrix[position.Line, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.Column = position.Column - 1;
            }

            return(movementPossibilitiesMatrix);
        }
Пример #7
0
        public override bool[,] PossibleMovements()
        {
            bool[,] matrix = new bool[Board.Rows, Board.Columns];

            Position pos = new Position(0, 0);

            //Above
            pos.DefineValues(Position.Row - 1, Position.Column);
            if (Board.PositionIsValid(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Column] = true;
            }
            //Above right
            pos.DefineValues(Position.Row - 1, Position.Column + 1);
            if (Board.PositionIsValid(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Column] = true;
            }
            //right
            pos.DefineValues(Position.Row, Position.Column + 1);
            if (Board.PositionIsValid(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Column] = true;
            }
            //below right
            pos.DefineValues(Position.Row + 1, Position.Column + 1);
            if (Board.PositionIsValid(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Column] = true;
            }
            //below
            pos.DefineValues(Position.Row + 1, Position.Column);
            if (Board.PositionIsValid(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Column] = true;
            }
            //below left
            pos.DefineValues(Position.Row + 1, Position.Column - 1);
            if (Board.PositionIsValid(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Column] = true;
            }
            //left
            pos.DefineValues(Position.Row, Position.Column - 1);
            if (Board.PositionIsValid(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Column] = true;
            }
            //above right
            pos.DefineValues(Position.Row - 1, Position.Column - 1);
            if (Board.PositionIsValid(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Column] = true;
            }
            return(matrix);
        }
Пример #8
0
        public override bool[,] PossibleMoves()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];

            Position pos = new Position(0, 0);

            pos.DefineValues(Position.Line - 1, Position.Column - 2);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line - 2, Position.Column - 1);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line - 2, Position.Column + 1);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line - 1, Position.Column + 2);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line + 1, Position.Column + 2);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line + 2, Position.Column + 1);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line + 2, Position.Column - 1);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line + 1, Position.Column - 2);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            return(mat);
        }
Пример #9
0
        public override bool[,] PossibleMovements()
        {
            bool[,] mat = new bool[Gameboard.Rows, Gameboard.Columns];

            Position pos = new Position(0, 0);

            pos.DefineValues(Position.Row - 1, Position.Column - 2);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }
            pos.DefineValues(Position.Row - 2, Position.Column - 1);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }
            pos.DefineValues(Position.Row - 2, Position.Column + 1);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }
            pos.DefineValues(Position.Row - 1, Position.Column + 2);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }
            pos.DefineValues(Position.Row + 1, Position.Column + 2);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }
            pos.DefineValues(Position.Row + 2, Position.Column + 1);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }
            pos.DefineValues(Position.Row + 2, Position.Column - 1);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }
            pos.DefineValues(Position.Row + 1, Position.Column - 2);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

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

            if (Color == Colors.White)
            {
                pos.DefineValues(Position.Line - 1, Position.Column);
                if (Board.ValidPosition(pos) && Clear(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line - 2, Position.Column);
                if (Board.ValidPosition(pos) && Clear(pos) && AmountMovement == 0)
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line - 1, Position.Column - 1);
                if (Board.ValidPosition(pos) && ExistAdversary(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line - 1, Position.Column + 1);
                if (Board.ValidPosition(pos) && ExistAdversary(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                //#En Passant
                if (Position.Line == 3)
                {
                    Position left = new Position(Position.Line, Position.Column - 1);
                    if (Board.ValidPosition(left) && ExistAdversary(left) && Board.Piece(left) == _chessMatch.VulnerableEnPassant)
                    {
                        mat[left.Line - 1, left.Column] = true;
                    }

                    Position right = new Position(Position.Line, Position.Column + 1);
                    if (Board.ValidPosition(right) && ExistAdversary(right) && Board.Piece(right) == _chessMatch.VulnerableEnPassant)
                    {
                        mat[right.Line - 1, right.Column] = true;
                    }
                }
            }
            else
            {
                pos.DefineValues(Position.Line + 1, Position.Column);
                if (Board.ValidPosition(pos) && Clear(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line + 2, Position.Column);
                if (Board.ValidPosition(pos) && Clear(pos) && AmountMovement == 0)
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line + 1, Position.Column + 1);
                if (Board.ValidPosition(pos) && ExistAdversary(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line + 1, Position.Column - 1);
                if (Board.ValidPosition(pos) && ExistAdversary(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                if (Position.Line == 4)
                {
                    Position left = new Position(Position.Line, Position.Column - 1);
                    if (Board.ValidPosition(left) && ExistAdversary(left) && Board.Piece(left) == _chessMatch.VulnerableEnPassant)
                    {
                        mat[left.Line + 1, left.Column] = true;
                    }

                    Position right = new Position(Position.Line, Position.Column + 1);
                    if (Board.ValidPosition(right) && ExistAdversary(right) && Board.Piece(right) == _chessMatch.VulnerableEnPassant)
                    {
                        mat[right.Line + 1, right.Column] = true;
                    }
                }
            }

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

            Position pos = new Position(0, 0);

            if (Color == Color.White)
            {
                pos.DefineValues(Position.Line - 1, Position.Column);
                if (Board.IsValidPosition(pos) && IsFree(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line - 2, Position.Column);
                Position pos2 = new Position(Position.Line - 1, Position.Column);
                if (Board.IsValidPosition(pos2) && IsFree(pos2) && Board.IsValidPosition(pos) && IsFree(pos) && MoveCount == 0)
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line - 1, Position.Column - 1);
                if (Board.IsValidPosition(pos) && HasEnemy(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line - 1, Position.Column + 1);
                if (Board.IsValidPosition(pos) && HasEnemy(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                //#SpecialMove En Passant
                if (Position.Line == 3)
                {
                    Position left = new Position(Position.Line, Position.Column - 1);
                    if (Board.IsValidPosition(left) && HasEnemy(left) && Board.Piece(left) == Match.VulnerableEnPassant)
                    {
                        mat[left.Line - 1, left.Column] = true;
                    }

                    Position right = new Position(Position.Line, Position.Column + 1);
                    if (Board.IsValidPosition(right) && HasEnemy(right) && Board.Piece(right) == Match.VulnerableEnPassant)
                    {
                        mat[right.Line - 1, right.Column] = true;
                    }
                }
            }
            else
            {
                pos.DefineValues(Position.Line + 1, Position.Column);
                if (Board.IsValidPosition(pos) && IsFree(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line + 2, Position.Column);
                Position pos2 = new Position(Position.Line + 1, Position.Column);

                if (Board.IsValidPosition(pos2) && IsFree(pos2) && Board.IsValidPosition(pos) && IsFree(pos) && MoveCount == 0)

                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line + 1, Position.Column - 1);
                if (Board.IsValidPosition(pos) && HasEnemy(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line + 1, Position.Column + 1);
                if (Board.IsValidPosition(pos) && HasEnemy(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                //#SpecialMove En Passant
                if (Position.Line == 4)
                {
                    Position left = new Position(Position.Line, Position.Column - 1);
                    if (Board.IsValidPosition(left) && HasEnemy(left) && Board.Piece(left) == Match.VulnerableEnPassant)
                    {
                        mat[left.Line + 1, left.Column] = true;
                    }

                    Position right = new Position(Position.Line, Position.Column + 1);
                    if (Board.IsValidPosition(right) && HasEnemy(right) && Board.Piece(right) == Match.VulnerableEnPassant)
                    {
                        mat[right.Line + 1, right.Column] = true;
                    }
                }
            }

            return(mat);
        }
Пример #12
0
        public override bool[,] PossibleMovements()
        {
            bool[,] mat = new bool[Gameboard.Rows, Gameboard.Columns];

            Position pos = new Position(0, 0);

            // north
            pos.DefineValues(Position.Row - 1, Position.Column);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // northeast
            pos.DefineValues(Position.Row - 1, Position.Column + 1);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // east
            pos.DefineValues(Position.Row, Position.Column + 1);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // southeast
            pos.DefineValues(Position.Row + 1, Position.Column + 1);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // south
            pos.DefineValues(Position.Row + 1, Position.Column);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // southwest
            pos.DefineValues(Position.Row + 1, Position.Column - 1);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // west
            pos.DefineValues(Position.Row, Position.Column - 1);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // northwest
            pos.DefineValues(Position.Row - 1, Position.Column - 1);
            if (Gameboard.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // Special Movement Castling
            if (MovementsQty == 0 && !match.Check)
            {
                // Special Movement Castling Short
                Position posT1 = new Position(Position.Row, Position.Column + 3);
                if (CastlingTowerTest(posT1))
                {
                    Position p1 = new Position(Position.Row, Position.Column + 1);
                    Position p2 = new Position(Position.Row, Position.Column + 2);
                    if (Gameboard.Piece(p1) == null && Gameboard.Piece(p2) == null)
                    {
                        mat[Position.Row, Position.Column + 2] = true;
                    }
                }

                // Special Movement Castling Long
                Position posT2 = new Position(Position.Row, Position.Column - 4);
                if (CastlingTowerTest(posT2))
                {
                    Position p1 = new Position(Position.Row, Position.Column - 1);
                    Position p2 = new Position(Position.Row, Position.Column - 2);
                    Position p3 = new Position(Position.Row, Position.Column - 3);
                    if (Gameboard.Piece(p1) == null && Gameboard.Piece(p2) == null && Gameboard.Piece(p3) == null)
                    {
                        mat[Position.Row, Position.Column - 2] = true;
                    }
                }
            }


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

            Position pos = new Position(0, 0);

            // above
            pos.DefineValues(Position.Line - 1, Position.Column);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // northeast
            pos.DefineValues(Position.Line - 1, Position.Column + 1);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // right
            pos.DefineValues(Position.Line, Position.Column + 1);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // southeast
            pos.DefineValues(Position.Line + 1, Position.Column + 1);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // below
            pos.DefineValues(Position.Line + 1, Position.Column);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // southwest
            pos.DefineValues(Position.Line + 1, Position.Column - 1);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // left
            pos.DefineValues(Position.Line, Position.Column - 1);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // northwest
            pos.DefineValues(Position.Line - 1, Position.Column - 1);
            if (Board.IsValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }


            // #SpecialMove Castling
            if (MoveCount == 0 && !Match.Check)
            {
                // #SpecialMove Castling short
                Position RookPos1 = new Position(Position.Line, Position.Column + 3);
                if (RookAbleToCastle(RookPos1))
                {
                    Position p1 = new Position(Position.Line, Position.Column + 1);
                    Position p2 = new Position(Position.Line, Position.Column + 2);
                    if (Board.Piece(p1) == null && Board.Piece(p2) == null)
                    {
                        mat[Position.Line, Position.Column + 2] = true;
                    }
                }

                // #SpecialMove Castling long
                Position RookPos2 = new Position(Position.Line, Position.Column - 4);
                if (RookAbleToCastle(RookPos2))
                {
                    Position p1 = new Position(Position.Line, Position.Column - 1);
                    Position p2 = new Position(Position.Line, Position.Column - 2);
                    Position p3 = new Position(Position.Line, Position.Column - 3);

                    if (Board.Piece(p1) == null && Board.Piece(p2) == null && Board.Piece(p3) == null)
                    {
                        mat[Position.Line, Position.Column - 2] = true;
                    }
                }
            }

            return(mat);
        }
Пример #14
0
        public override bool[,] PossibleMovements()
        {
            bool[,] mat = new bool[Gameboard.Rows, Gameboard.Columns];

            Position pos = new Position(0, 0);

            if (Color == Color.White)
            {
                pos.DefineValues(Position.Row - 1, Position.Column);
                if (Gameboard.ValidPosition(pos) && Free(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.DefineValues(Position.Row - 2, Position.Column);
                if (Gameboard.ValidPosition(pos) && Free(pos) && MovementsQty == 0)
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.DefineValues(Position.Row - 1, Position.Column - 1);
                if (Gameboard.ValidPosition(pos) && EnemyExists(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.DefineValues(Position.Row - 1, Position.Column + 1);
                if (Gameboard.ValidPosition(pos) && EnemyExists(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }

                // Special Movement En Passant
                if (Position.Row == 3)
                {
                    Position left = new Position(Position.Row, Position.Column - 1);
                    if (Gameboard.ValidPosition(left) && EnemyExists(left) && Gameboard.Piece(left) == match.enPassantVulnerable)
                    {
                        mat[left.Row - 1, left.Column] = true;
                    }
                    Position right = new Position(Position.Row, Position.Column + 1);
                    if (Gameboard.ValidPosition(right) && EnemyExists(right) && Gameboard.Piece(right) == match.enPassantVulnerable)
                    {
                        mat[right.Row - 1, right.Column] = true;
                    }
                }
            }
            else
            {
                pos.DefineValues(Position.Row + 1, Position.Column);
                if (Gameboard.ValidPosition(pos) && Free(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.DefineValues(Position.Row + 2, Position.Column);
                if (Gameboard.ValidPosition(pos) && Free(pos) && MovementsQty == 0)
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.DefineValues(Position.Row + 1, Position.Column - 1);
                if (Gameboard.ValidPosition(pos) && EnemyExists(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.DefineValues(Position.Row + 1, Position.Column + 1);
                if (Gameboard.ValidPosition(pos) && EnemyExists(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }

                // Special Movement En Passant
                if (Position.Row == 4)
                {
                    Position left = new Position(Position.Row, Position.Column - 1);
                    if (Gameboard.ValidPosition(left) && EnemyExists(left) && Gameboard.Piece(left) == match.enPassantVulnerable)
                    {
                        mat[left.Row + 1, left.Column] = true;
                    }
                    Position right = new Position(Position.Row, Position.Column + 1);
                    if (Gameboard.ValidPosition(right) && EnemyExists(right) && Gameboard.Piece(right) == match.enPassantVulnerable)
                    {
                        mat[right.Row + 1, right.Column] = true;
                    }
                }
            }

            return(mat);
        }
Пример #15
0
        public override bool[,] PossibleMovements()
        {
            bool[,] movementPossibilitiesMatrix = new bool[Board.Lines, Board.Columns];
            // Instantiate a new position with placeholder values
            Position position = new Position(0, 0);

            // North of the piece
            position.DefineValues(Position.Line - 1, Position.Column);
            if (Board.ValidPosition(position) && CanMoveToPosition(position))
            {
                movementPossibilitiesMatrix[position.Line, position.Column] = true;
            }
            // Northeast of the piece
            position.DefineValues(Position.Line - 1, Position.Column + 1);
            if (Board.ValidPosition(position) && CanMoveToPosition(position))
            {
                movementPossibilitiesMatrix[position.Line, position.Column] = true;
            }
            // East of the piece
            position.DefineValues(Position.Line, Position.Column + 1);
            if (Board.ValidPosition(position) && CanMoveToPosition(position))
            {
                movementPossibilitiesMatrix[position.Line, position.Column] = true;
            }
            // Southeast of the piece
            position.DefineValues(Position.Line + 1, Position.Column + 1);
            if (Board.ValidPosition(position) && CanMoveToPosition(position))
            {
                movementPossibilitiesMatrix[position.Line, position.Column] = true;
            }
            // South of the piece
            position.DefineValues(Position.Line + 1, Position.Column);
            if (Board.ValidPosition(position) && CanMoveToPosition(position))
            {
                movementPossibilitiesMatrix[position.Line, position.Column] = true;
            }
            // Southwest of the piece
            position.DefineValues(Position.Line + 1, Position.Column - 1);
            if (Board.ValidPosition(position) && CanMoveToPosition(position))
            {
                movementPossibilitiesMatrix[position.Line, position.Column] = true;
            }
            // West of the piece
            position.DefineValues(Position.Line, Position.Column - 1);
            if (Board.ValidPosition(position) && CanMoveToPosition(position))
            {
                movementPossibilitiesMatrix[position.Line, position.Column] = true;
            }
            // Northwest of the piece
            position.DefineValues(Position.Line - 1, Position.Column - 1);
            if (Board.ValidPosition(position) && CanMoveToPosition(position))
            {
                movementPossibilitiesMatrix[position.Line, position.Column] = true;
            }
            // # Special Play - Castling
            if (MovementQuantity == 0 && !chessMatch.IsInCheck)
            {
                // Castling Short
                Position rookPosition1 = new Position(Position.Line, Position.Column + 3);
                if (CanRookParticipateInCastling(rookPosition1))
                {
                    Position position1 = new Position(Position.Line, Position.Column + 1);
                    Position position2 = new Position(Position.Line, Position.Column + 2);
                    if (Board.Piece(position1) == null && Board.Piece(position2) == null)
                    {
                        movementPossibilitiesMatrix[Position.Line, Position.Column + 2] = true;
                    }
                }
                // Castling Long
                Position rookPosition2 = new Position(Position.Line, Position.Column - 4);
                if (CanRookParticipateInCastling(rookPosition2))
                {
                    Position position1 = new Position(Position.Line, Position.Column - 1);
                    Position position2 = new Position(Position.Line, Position.Column - 2);
                    Position position3 = new Position(Position.Line, Position.Column - 3);
                    if (Board.Piece(position1) == null && Board.Piece(position2) == null && Board.Piece(position3) == null)
                    {
                        movementPossibilitiesMatrix[Position.Line, Position.Column - 2] = true;
                    }
                }
            }

            return(movementPossibilitiesMatrix);
        }
Пример #16
0
        public override bool[,] PossibleMovements()
        {
            bool[,] movementPossibilitiesMatrix = new bool[Board.Lines, Board.Columns];
            // Instantiate a new position with placeholder values
            Position position = new Position(0, 0);

            if (Color == PieceColor.White)
            {
                // North of the piece. Standard movement of a Pawn
                position.DefineValues(Position.Line - 1, Position.Column);
                if (Board.ValidPosition(position) && IsPositionFree(position))
                {
                    movementPossibilitiesMatrix[position.Line, position.Column] = true;
                }
                // North of the piece. Initial movement for a Pawn (moves two places instead of one)
                position.DefineValues(Position.Line - 2, Position.Column);
                if (Board.ValidPosition(position) && IsPositionFree(position) && IsPositionFree(new Position(Position.Line - 1, Position.Column)) && MovementQuantity == 0)
                {
                    movementPossibilitiesMatrix[position.Line, position.Column] = true;
                }
                // NW of the piece. Movement for capturing other pieces
                position.DefineValues(Position.Line - 1, Position.Column - 1);
                if (Board.ValidPosition(position) && IsEnemyAtPosition(position))
                {
                    movementPossibilitiesMatrix[position.Line, position.Column] = true;
                }
                // NE of the piece. Movement for capturing other pieces
                position.DefineValues(Position.Line - 1, Position.Column + 1);
                if (Board.ValidPosition(position) && IsEnemyAtPosition(position))
                {
                    movementPossibilitiesMatrix[position.Line, position.Column] = true;
                }
                // Special Play - En Passant
                // Move the piece to the NW direction and capture the piece at its left or move the piece to the NE direction and capture the piece at its right
                if (Position.Line == 3)
                {
                    Position positionToTheLeft = new Position(Position.Line, Position.Column - 1);
                    if (Board.ValidPosition(positionToTheLeft) && IsEnemyAtPosition(positionToTheLeft) && Board.Piece(positionToTheLeft) == chessMatch.VulnerableToEnPassant)
                    {
                        movementPossibilitiesMatrix[positionToTheLeft.Line - 1, positionToTheLeft.Column] = true;
                    }
                    Position positionToTheRight = new Position(Position.Line, Position.Column + 1);
                    if (Board.ValidPosition(positionToTheRight) && IsEnemyAtPosition(positionToTheRight) && Board.Piece(positionToTheRight) == chessMatch.VulnerableToEnPassant)
                    {
                        movementPossibilitiesMatrix[positionToTheRight.Line - 1, positionToTheRight.Column] = true;
                    }
                }
            }
            else
            {
                // South of the piece. Standard movement of a Pawn
                position.DefineValues(Position.Line + 1, Position.Column);
                if (Board.ValidPosition(position) && IsPositionFree(position))
                {
                    movementPossibilitiesMatrix[position.Line, position.Column] = true;
                }
                // South of the piece. Initial movement for a Pawn (moves two places instead of one)
                position.DefineValues(Position.Line + 2, Position.Column);
                if (Board.ValidPosition(position) && IsPositionFree(position) && IsPositionFree(new Position(Position.Line + 1, Position.Column)) && MovementQuantity == 0)
                {
                    movementPossibilitiesMatrix[position.Line, position.Column] = true;
                }
                // SW of the piece. Movement for capturing other pieces
                position.DefineValues(Position.Line + 1, Position.Column - 1);
                if (Board.ValidPosition(position) && IsEnemyAtPosition(position))
                {
                    movementPossibilitiesMatrix[position.Line, position.Column] = true;
                }
                // SE of the piece. Movement for capturing other pieces
                position.DefineValues(Position.Line + 1, Position.Column + 1);
                if (Board.ValidPosition(position) && IsEnemyAtPosition(position))
                {
                    movementPossibilitiesMatrix[position.Line, position.Column] = true;
                }
                // Special Play - En Passant
                // Move the piece to the SW direction and capture the piece at its left or move the piece to the SE direction and capture the piece at its right
                if (Position.Line == 4)
                {
                    Position positionToTheLeft = new Position(Position.Line, Position.Column - 1);
                    if (Board.ValidPosition(positionToTheLeft) && IsEnemyAtPosition(positionToTheLeft) && Board.Piece(positionToTheLeft) == chessMatch.VulnerableToEnPassant)
                    {
                        movementPossibilitiesMatrix[positionToTheLeft.Line + 1, positionToTheLeft.Column] = true;
                    }
                    Position positionToTheRight = new Position(Position.Line, Position.Column + 1);
                    if (Board.ValidPosition(positionToTheRight) && IsEnemyAtPosition(positionToTheRight) && Board.Piece(positionToTheRight) == chessMatch.VulnerableToEnPassant)
                    {
                        movementPossibilitiesMatrix[positionToTheRight.Line + 1, positionToTheRight.Column] = true;
                    }
                }
            }

            return(movementPossibilitiesMatrix);
        }
Пример #17
0
        public override bool[,] PossibleMoves()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];
            Position pos = new Position(0, 0);

            //N
            pos.DefineValues(Position.Line - 1, Position.Column);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }
            //Ne
            pos.DefineValues(Position.Line - 1, Position.Column - 1);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }
            //E
            pos.DefineValues(Position.Line, Position.Column + 1);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }
            //Se
            pos.DefineValues(Position.Line + 1, Position.Column + 1);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }
            //S
            pos.DefineValues(Position.Line + 1, Position.Column);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }
            //Sw
            pos.DefineValues(Position.Line + 1, Position.Column - 1);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }
            //W
            pos.DefineValues(Position.Line, Position.Column - 1);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }
            //Nw
            pos.DefineValues(Position.Line - 1, Position.Column + 1);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }
            //ROQUE
            if (AmountMovement == 0 && !ChessMatch.Check)
            {
                //#smallRoque
                Position posT1 = new Position(Position.Line, Position.Column + 3);
                if (CanDoRoque(posT1))
                {
                    Position p1 = new Position(Position.Line, Position.Column + 1);
                    Position p2 = new Position(Position.Line, Position.Column + 2);
                    if (Board.Piece(p1) == null && Board.Piece(p2) == null)
                    {
                        mat[Position.Line, Position.Column + 2] = true;
                    }
                }
                //#bigRoque
                Position posT2 = new Position(Position.Line, Position.Column - 4);
                if (CanDoRoque(posT2))
                {
                    Position p1 = new Position(Position.Line, Position.Column - 1);
                    Position p2 = new Position(Position.Line, Position.Column - 2);
                    Position p3 = new Position(Position.Line, Position.Column - 3);
                    if (Board.Piece(p1) == null && Board.Piece(p2) == null && Board.Piece(p3) == null)
                    {
                        mat[Position.Line, Position.Column - 2] = true;
                    }
                }
            }

            return(mat);
        }