I bet most of you in here have seen the old movie "Wargames"

Im wondering how would you go about programming an AI like WOPR that learns from itself?

Lets take an example in chess *Which he loved* He would make simulations of a chess game, if he lost he would learn from the mistake and improve from that the next time.

Machine Learning is the field of AI that studies this.

An AI agent that learns from past mistakes and successes is in the branch called reinforcement learning.

There are many approaches to this problem. Most notably, you have Q-learning algorithms, and Genetic algorithms (or evolutionary algorithms). The algorithms themselves are pretty easy to implement, but the hard part is to formulate the problem correctly in terms of what actions the agent can take and how the rewards are calculated.

A while ago, I implemented a number of these algorithms to get a bunch of virtual mice to learn how to feed off a pile of cheese without being caught by a cat that was guarding the food. It was, to some extent, pretty successful. In this case, the genetic algorithm worked the best.