IRL implementation based on Norvig's AIMA code.