Exemple #1
0
        public override bool[,] PossibleMoves()
        {
            bool[,] mat = new bool[Board.Lines, Board.Colunms];

            Position pos = new Position(0, 0);

            if (Color == Color.White)
            {
                pos.DefineValues(Position.Line - 2, Position.Colunm);
                if (Board.ValidPosition(pos) && MoveCounter == 0 && freeCell(pos))
                {
                    mat[pos.Line, pos.Colunm] = true;
                }

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

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

            return(mat);
        }
Exemple #2
0
        public override bool[,] PossibleMovements()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];

            Position position = new Position(0, 0);

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

                position.SetValues(position.Line - 1, position.Column + 1);
            }

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

                position.SetValues(position.Line + 1, position.Column + 1);
            }

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

                position.SetValues(position.Line + 1, position.Column - 1);
            }

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

            return(mat);
        }
        public override bool[,] AvailableMoviments()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];

            Position positionBoard = new Position(0, 0);

            positionBoard.SetValues(Position.Line - 1, Position.Column - 2);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }
            positionBoard.SetValues(Position.Line - 2, Position.Column - 1);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }
            positionBoard.SetValues(Position.Line - 2, Position.Column + 1);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }
            positionBoard.SetValues(Position.Line - 1, Position.Column + 2);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }
            positionBoard.SetValues(Position.Line + 1, Position.Column + 2);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }
            positionBoard.SetValues(Position.Line + 2, Position.Column + 1);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }
            positionBoard.SetValues(Position.Line + 2, Position.Column - 1);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }
            positionBoard.SetValues(Position.Line + 1, Position.Column - 2);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }

            return(mat);
        }
Exemple #4
0
        public override bool[,] AvailableMoviments()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];

            Position positionBoard = new Position(0, 0);

            //north position
            positionBoard.SetValues(Position.Line - 1, Position.Column);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }

            //northeast position
            positionBoard.SetValues(Position.Line - 1, Position.Column + 1);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }

            //right position
            positionBoard.SetValues(Position.Line, Position.Column + 1);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }

            //southeast position
            positionBoard.SetValues(Position.Line + 1, Position.Column + 1);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }

            //south position
            positionBoard.SetValues(Position.Line + 1, Position.Column);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }

            //southwest position
            positionBoard.SetValues(Position.Line + 1, Position.Column - 1);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }

            //left position
            positionBoard.SetValues(Position.Line, Position.Column - 1);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }

            //northwest position
            positionBoard.SetValues(Position.Line - 1, Position.Column - 1);
            if (Board.ValidPosition(positionBoard) && CanMove(positionBoard))
            {
                mat[positionBoard.Line, positionBoard.Column] = true;
            }

            // #Castle move
            if (MovementQuantity == 0 && !match.CheckMate)
            {
                // #Castle Kingside
                Position posT1 = new Position(Position.Line, Position.Column + 3);
                if (TestTowerForCastleMove(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;
                    }
                }
                // #Castle Queenside
                Position posT2 = new Position(Position.Line, Position.Column - 4);
                if (TestTowerForCastleMove(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);
        }
Exemple #5
0
        public override bool[,] PossibleMoves()
        {
            bool[,] mat = new bool[Board.Rows, Board.Columns];

            Position pos = new Position(0, 0);

            // up
            pos.setValues(Position.Row - 1, Position.Column);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

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

            // right
            pos.setValues(Position.Row, Position.Column + 1);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // downright
            pos.setValues(Position.Row + 1, Position.Column + 1);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // down
            pos.setValues(Position.Row + 1, Position.Column);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

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

            // left
            pos.setValues(Position.Row, Position.Column - 1);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // upleft
            pos.setValues(Position.Row - 1, Position.Column - 1);
            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // #specialMove Castling
            if (MoveCount == 0 && !Match.Check)
            {
                // #specialMove kingside rook
                Position posR1 = new Position(Position.Row, Position.Column + 3);
                if (TestRookCastling(posR1))
                {
                    Position p1 = new Position(Position.Row, Position.Column + 1);
                    Position p2 = new Position(Position.Row, Position.Column + 2);
                    if (Board.Piece(p1) == null && Board.Piece(p2) == null)
                    {
                        mat[Position.Row, Position.Column + 2] = true;
                    }
                }
                // #specialMove queenside rook
                Position posR2 = new Position(Position.Row, Position.Column - 4);
                if (TestRookCastling(posR2))
                {
                    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 (Board.Piece(p1) == null && Board.Piece(p2) == null && Board.Piece(p3) == null)
                    {
                        mat[Position.Row, Position.Column - 2] = true;
                    }
                }
            }

            return(mat);
        }
Exemple #6
0
        public override bool[,] AvailableMoviments()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];

            Position positionBoard = new Position(0, 0);


            if (Color == Color.White)
            {
                positionBoard.SetValues(Position.Line - 1, Position.Column);
                if (Board.ValidPosition(positionBoard) && Free(positionBoard))
                {
                    mat[positionBoard.Line, positionBoard.Column] = true;
                }
                positionBoard.SetValues(Position.Line - 2, Position.Column);
                Position p2 = new Position(Position.Line - 1, Position.Column);
                if (Board.ValidPosition(p2) && Free(p2) && Board.ValidPosition(positionBoard) && Free(positionBoard) && MovementQuantity == 0)
                {
                    mat[positionBoard.Line, positionBoard.Column] = true;
                }
                positionBoard.SetValues(Position.Line - 1, Position.Column - 1);
                if (Board.ValidPosition(positionBoard) && ExistsOpponent(positionBoard))
                {
                    mat[positionBoard.Line, positionBoard.Column] = true;
                }
                positionBoard.SetValues(Position.Line - 1, Position.Column + 1);
                if (Board.ValidPosition(positionBoard) && ExistsOpponent(positionBoard))
                {
                    mat[positionBoard.Line, positionBoard.Column] = true;
                }

                // #en passant
                if (Position.Line == 3)
                {
                    Position left = new Position(Position.Line, Position.Column - 1);
                    if (Board.ValidPosition(left) && ExistsOpponent(left) && Board.piece(left) == match.VulnerableEnPassant)
                    {
                        mat[left.Line - 1, left.Column] = true;
                    }
                    Position right = new Position(Position.Line, Position.Column + 1);
                    if (Board.ValidPosition(right) && ExistsOpponent(right) && Board.piece(right) == match.VulnerableEnPassant)
                    {
                        mat[right.Line - 1, right.Column] = true;
                    }
                }
            }
            else
            {
                positionBoard.SetValues(Position.Line + 1, Position.Column);
                if (Board.ValidPosition(positionBoard) && Free(positionBoard))
                {
                    mat[positionBoard.Line, positionBoard.Column] = true;
                }
                positionBoard.SetValues(Position.Line + 2, Position.Column);
                Position p2 = new Position(Position.Line + 1, Position.Column);
                if (Board.ValidPosition(p2) && Free(p2) && Board.ValidPosition(positionBoard) && Free(positionBoard) && MovementQuantity == 0)
                {
                    mat[positionBoard.Line, positionBoard.Column] = true;
                }
                positionBoard.SetValues(Position.Line + 1, Position.Column - 1);
                if (Board.ValidPosition(positionBoard) && ExistsOpponent(positionBoard))
                {
                    mat[positionBoard.Line, positionBoard.Column] = true;
                }
                positionBoard.SetValues(Position.Line + 1, Position.Column + 1);
                if (Board.ValidPosition(positionBoard) && ExistsOpponent(positionBoard))
                {
                    mat[positionBoard.Line, positionBoard.Column] = true;
                }

                // #en passant
                if (Position.Line == 4)
                {
                    Position left = new Position(Position.Line, Position.Column - 1);
                    if (Board.ValidPosition(left) && ExistsOpponent(left) && Board.piece(left) == match.VulnerableEnPassant)
                    {
                        mat[left.Line + 1, left.Column] = true;
                    }
                    Position right = new Position(Position.Line, Position.Column + 1);
                    if (Board.ValidPosition(right) && ExistsOpponent(right) && Board.piece(right) == match.VulnerableEnPassant)
                    {
                        mat[right.Line + 1, right.Column] = true;
                    }
                }
            }

            return(mat);
        }
Exemple #7
0
        public override bool[,] PossibleMovements()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];

            Position position = new Position(0, 0);

            //Up
            position.SetValues(Position.Line - 1, Position.Column);
            if (Board.ValidPosition(position) && CanMove(position))
            {
                mat[position.Line, position.Column] = true;
            }

            //Northeast
            position.SetValues(Position.Line - 1, Position.Column + 1);
            if (Board.ValidPosition(position) && CanMove(position))
            {
                mat[position.Line, position.Column] = true;
            }
            //Right
            position.SetValues(Position.Line, Position.Column + 1);
            if (Board.ValidPosition(position) && CanMove(position))
            {
                mat[position.Line, position.Column] = true;
            }

            //Southeast
            position.SetValues(Position.Line + 1, Position.Column + 1);
            if (Board.ValidPosition(position) && CanMove(position))
            {
                mat[position.Line, position.Column] = true;
            }

            //Down
            position.SetValues(Position.Line + 1, Position.Column);
            if (Board.ValidPosition(position) && CanMove(position))
            {
                mat[position.Line, position.Column] = true;
            }

            //South-west
            position.SetValues(Position.Line + 1, Position.Column - 1);
            if (Board.ValidPosition(position) && CanMove(position))
            {
                mat[position.Line, position.Column] = true;
            }

            //Left
            position.SetValues(Position.Line, Position.Column - 1);
            if (Board.ValidPosition(position) && CanMove(position))
            {
                mat[position.Line, position.Column] = true;
            }

            //Northwest
            position.SetValues(Position.Line - 1, Position.Column - 1);
            if (Board.ValidPosition(position) && CanMove(position))
            {
                mat[position.Line, position.Column] = true;
            }


            //#Special play Castling
            if (NumberOfMovements == 0 && !Match.Check)
            {
                //#Special play castling short
                Position positionRook = new Position(Position.Line, Position.Column + 3);
                if (TestRookToCastling(positionRook))
                {
                    Position kingMoreOne = new Position(Position.Line, Position.Column + 1);
                    Position kingMoreTwo = new Position(Position.Line, Position.Column + 2);

                    if (Board.Piece(kingMoreOne) == null && Board.Piece(kingMoreTwo) == null)
                    {
                        mat[Position.Line, Position.Column + 2] = true;
                    }
                }

                //#Special play castling long
                Position positionRook2 = new Position(Position.Line, Position.Column + 3);
                if (TestRookToCastling(positionRook))
                {
                    Position kingOneLess   = new Position(Position.Line, Position.Column - 1);
                    Position kingTwoLess   = new Position(Position.Line, Position.Column - 2);
                    Position kingThreeLess = new Position(Position.Line, Position.Column - 3);

                    if (Board.Piece(kingOneLess) == null && Board.Piece(kingTwoLess) == null && Board.Piece(kingThreeLess) == null)
                    {
                        mat[Position.Line, Position.Column - 2] = true;
                    }
                }
            }

            return(mat);
        }
Exemple #8
0
        public override bool[,] PossiblesMoviments()
        {
            bool[,] mat = new bool[Board.Rows, Board.Columns];

            Position pos = new Position(0, 0);

            if (Color == Color.White)
            {
                pos.SetPosition(Position.Row - 1, Position.Column);
                if (Board.ValidPosition(pos) && FreePosition(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.SetPosition(Position.Row - 2, Position.Column);
                if (Board.ValidPosition(pos) && FreePosition(pos) && AmtMoviments == 0)
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.SetPosition(Position.Row - 1, Position.Column - 1);
                if (Board.ValidPosition(pos) && ThereIsAdversary(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.SetPosition(Position.Row - 1, Position.Column + 1);
                if (Board.ValidPosition(pos) && ThereIsAdversary(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }

                //#special moviment
                if (Position.Row == 3)
                {
                    Position left = new Position(Position.Row, Position.Column - 1);

                    if (Board.ValidPosition(left) && ThereIsAdversary(left) && Board.GetPiece(left) == Match.CanPassant)
                    {
                        mat[left.Row - 1, left.Column] = true;
                    }

                    Position right = new Position(Position.Row, Position.Column + 1);

                    if (Board.ValidPosition(right) && ThereIsAdversary(right) && Board.GetPiece(right) == Match.CanPassant)
                    {
                        mat[right.Row - 1, right.Column] = true;
                    }
                }
            }
            else
            {
                pos.SetPosition(Position.Row + 1, Position.Column);
                if (Board.ValidPosition(pos) && FreePosition(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.SetPosition(Position.Row + 2, Position.Column);
                if (Board.ValidPosition(pos) && FreePosition(pos) && AmtMoviments == 0)
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.SetPosition(Position.Row + 1, Position.Column - 1);
                if (Board.ValidPosition(pos) && ThereIsAdversary(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.SetPosition(Position.Row + 1, Position.Column + 1);
                if (Board.ValidPosition(pos) && ThereIsAdversary(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }

                //#special moviment
                if (Position.Row == 4)
                {
                    Position left = new Position(Position.Row, Position.Column - 1);

                    if (Board.ValidPosition(left) && ThereIsAdversary(left) && Board.GetPiece(left) == Match.CanPassant)
                    {
                        mat[left.Row + 1, left.Column] = true;
                    }

                    Position right = new Position(Position.Row, Position.Column + 1);

                    if (Board.ValidPosition(right) && ThereIsAdversary(right) && Board.GetPiece(right) == Match.CanPassant)
                    {
                        mat[right.Row + 1, right.Column] = true;
                    }
                }
            }


            return(mat);
        }
        public override bool[,] PossibleMoves()
        {
            bool[,] mat = new bool[Board.Rows, Board.Columns];

            Position pos = new Position(0, 0);

            // up
            pos.setValues(Position.Row - 1, Position.Column - 2);

            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // upright
            pos.setValues(Position.Row - 2, Position.Column - 1);

            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // right
            pos.setValues(Position.Row - 2, Position.Column + 1);

            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // downright
            pos.setValues(Position.Row - 1, Position.Column + 2);

            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // down
            pos.setValues(Position.Row + 1, Position.Column + 2);

            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // downleft
            pos.setValues(Position.Row + 2, Position.Column + 1);

            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // left
            pos.setValues(Position.Row + 2, Position.Column - 1);

            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }

            // upleft
            pos.setValues(Position.Row + 1, Position.Column - 2);

            if (Board.ValidPosition(pos) && CanMove(pos))
            {
                mat[pos.Row, pos.Column] = true;
            }
            return(mat);
        }