Cogito, Ergo Ludo: An Agent that Learns to Play by Reasoning and Planning