cant figure out winning/endgame function