Fixed win-detecting algorithm