code finally works for checking end of game