add alg to determine win state