Use flip_sq idea in endgame.cpp