Add code to check for endgame.

Since it's impossible to merge right now, the code is practically
untested...