Working script. Wins game correctly