i was wondering how can an AI learn? for example:after observing 1000 people hacking,it learns to hack or in a video game,by watching that his method is not effective, based on what the opponent is doing,adds a code into itself which could be useful for defeating the enemy overall:it should be able to find patterns and develops based on the patterns and its own errors
As most of human beings, alo an AI should be taught to learn.
The big problem, here, is the definition of the environment: what is the subject, and which are the instruments to check against to acquire some knowledge?
Neuroscientists are still puzzled with such problems, because our knowledge is deeply based on assumptions that have nothing to do with the studied subject: we learn that fire is dangerous because we have an internal sensitive network that sends a message of pain when the fire is too close to our skin, while machines don't.
Even on a purely logical point of view, we often base our decisions on metalogical clues: the sentence "I will take an umbrella with myself if the weather is cloudy" considers entities like the rain, a cause-effect system based on past knowledge (both implementable on silicon) but also logical predicates like inference. As Goedel demonstrated, it is not possible to create a logical system both coherent and non-contradictory that answers all questions: the truth of some predicate is simply not decidable.
That said, you can still teach a machine to learn, but only in the closed environment you defined for it: in other words, the machine will have no clues on "what lies behind his programming", and then will not able to "infer" new algorithms.
From Hofstadter's "Goedel, Escher, Bach: an eternal golden braid", you can read the chapter about the MU game (pag. 36) on formal systems:
You have a formal system that uses only three letters: M, I and U, a starting string MI and four composition rules:
1 - If you have a string ending with I, you can add U to its end
2 - If you have Mx (where x is an undefined substringon the system), you can perform the transformation Mxx
3 - If your string has a substring III, you can substitute III with U
4 - If your string has a substring UU, you can delete it.
Try to produce the string MU using this system.
As you will soon find, such transformation is impossible in the shown formal system.
And this theorem is true and extendable to every formal system.
Back to your question, now: can we build an AI that learns? Yes, absolutely! And can we build an AI that learns from its errors? Yes, if we have taught it what an error is. Finally, can we build a machine that infers a better behaviour from its errors? Yes, but the optimization will be related to the environment apprehended by the machine (i.e. our knowledge base). Thatt0s like saying that the machine can find new ways to do old things, but will not be able to infer new "things" from its own progeammation.
What you're talking about is Machine Learning. Here's a cool course: https://class.coursera.org/ml-007
There is a story about someone who didn't know how to play checkers very well but made a computer program that could watch thousands of games and determine which moves were good or bad and then that computer program was able to beat a human in checkers.
There are different kinds of machine learning. Check out this MOOC. It's great.