Generalized move pattern algorithm