Reinforcement learning with a dynamic world model. It's a pretty standard approach to training agents, although there are a lot of problems with this technique as well. People have used it to create agents for Minecraft, racing games, Nethack, lots of old arcade games and so forth.