Subgame-Perfect Equilibria of Finite and Infinite Horizon Games