Subgame-perfect equilibria of finite- and infinite-horizon games