added win algorithm