Ejemplo n.º 1
0
        public override bool[,] PossibleMoviments()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];
            //UP
            Position pos = new Position(0, 0);

            pos.SetValue(Position.Line - 1, Position.Column);
            while (Board.IsPositionValid(pos) && IsAbleToMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (Board.GetPiece(pos) != null && Board.GetPiece(pos).Color != Color)
                {
                    break;
                }
                pos.Line--;
            }

            //DOWN
            pos.SetValue(Position.Line + 1, Position.Column);
            while (Board.IsPositionValid(pos) && IsAbleToMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (Board.GetPiece(pos) != null && Board.GetPiece(pos).Color != Color)
                {
                    break;
                }
                pos.Line++;
            }

            //LEFT
            pos.SetValue(Position.Line, Position.Column - 1);
            while (Board.IsPositionValid(pos) && IsAbleToMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (Board.GetPiece(pos) != null && Board.GetPiece(pos).Color != Color)
                {
                    break;
                }
                pos.Column--;
            }

            //RIGHT
            pos.SetValue(Position.Line, Position.Column + 1);
            while (Board.IsPositionValid(pos) && IsAbleToMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (Board.GetPiece(pos) != null && Board.GetPiece(pos).Color != Color)
                {
                    break;
                }
                pos.Column++;
            }

            return(mat);
        }
Ejemplo n.º 2
0
        public override bool[,] PossibleMoviments()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];

            Position pos = new Position(0, 0);

            pos.SetValue(Position.Line - 1, Position.Column - 2);
            if (Board.IsPositionValid(pos) && IsAbleToMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.SetValue(Position.Line - 2, Position.Column - 1);
            if (Board.IsPositionValid(pos) && IsAbleToMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.SetValue(Position.Line - 2, Position.Column + 1);
            if (Board.IsPositionValid(pos) && IsAbleToMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.SetValue(Position.Line - 1, Position.Column + 2);
            if (Board.IsPositionValid(pos) && IsAbleToMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.SetValue(Position.Line + 1, Position.Column + 2);
            if (Board.IsPositionValid(pos) && IsAbleToMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.SetValue(Position.Line + 2, Position.Column + 1);
            if (Board.IsPositionValid(pos) && IsAbleToMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.SetValue(Position.Line + 2, Position.Column - 1);
            if (Board.IsPositionValid(pos) && IsAbleToMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.SetValue(Position.Line + 1, Position.Column - 2);
            if (Board.IsPositionValid(pos) && IsAbleToMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            return(mat);
        }
Ejemplo n.º 3
0
        public override bool[,] PossibleMoviments()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];

            Position pos = new Position(0, 0);

            if (Color == Color.White)
            {
                pos.SetValue(Position.Line - 1, Position.Column);
                if (Board.IsPositionValid(pos) && IsPositionEmpty(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.SetValue(Position.Line - 2, Position.Column);
                if (Board.IsPositionValid(pos) && IsPositionEmpty(pos) && MovimentsQuantity == 0)
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.SetValue(Position.Line - 1, Position.Column - 1);
                if (Board.IsPositionValid(pos) && ExistsEnemy(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.SetValue(Position.Line - 1, Position.Column + 1);
                if (Board.IsPositionValid(pos) && ExistsEnemy(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                // #Special Move En Passant
                if (Position.Line == 3)
                {
                    Position left = new Position(Position.Line, Position.Column - 1);
                    if (Board.IsPositionValid(left) && ExistsEnemy(left) && Board.GetPiece(left) == _match.EnPassantVulnerable)
                    {
                        mat[left.Line - 1, left.Column] = true;
                    }
                    Position right = new Position(Position.Line, Position.Column + 1);
                    if (Board.IsPositionValid(right) && ExistsEnemy(right) && Board.GetPiece(right) == _match.EnPassantVulnerable)
                    {
                        mat[right.Line - 1, right.Column] = true;
                    }
                }
            }
            else
            {
                pos.SetValue(Position.Line + 1, Position.Column);
                if (Board.IsPositionValid(pos) && IsPositionEmpty(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.SetValue(Position.Line + 2, Position.Column);
                if (Board.IsPositionValid(pos) && IsPositionEmpty(pos) && MovimentsQuantity == 0)
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.SetValue(Position.Line + 1, Position.Column - 1);
                if (Board.IsPositionValid(pos) && ExistsEnemy(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.SetValue(Position.Line + 1, Position.Column + 1);
                if (Board.IsPositionValid(pos) && ExistsEnemy(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.IsPositionValid(left) && ExistsEnemy(left) && Board.GetPiece(left) == _match.EnPassantVulnerable)
                    {
                        mat[left.Line + 1, left.Column] = true;
                    }
                    Position right = new Position(Position.Line, Position.Column + 1);
                    if (Board.IsPositionValid(right) && ExistsEnemy(right) && Board.GetPiece(right) == _match.EnPassantVulnerable)
                    {
                        mat[right.Line + 1, right.Column] = true;
                    }
                }
            }

            return(mat);
        }