Vicarious trial and error1, the ability to evaluate futures by mental time travel, is a hallmark of intelligence. To do this, agents need to learn mental models, or “cognitive maps”2,3, from a stream of sensor