changes in win check algorithm by Youw