Deep reinforcement learning. In scikit-learn. In less than 50 effective lines.
Dive-in button:
Currently both demos are vanilla crossentropy(CE) method for policy approximated by a neural network. For RL, it boild down to Repeat:
The CE is a very general approach for approximate estimation and maximization tasks, you can read about it here. For reinforcement learning, we use the optimization version, basically trying to fit agent to generating games where reward is high. More on that here.
While this approach falls flat in some cases and it takes black magic to make it work with infinite MDPs or long session lengths, it still works unreasonably well in most cases. One more awesome trait is that it extendds effortlessly to policy approximation (e.g. deep RL), partially observable MDPs and all kinds of weird stuff you see in the wild.
If you want something heavier, take a look at agentnet.