detecting winning state