endgame code