public bool isLegal(PatternId from_, Dir4 dir, PatternId to_) { int i = from_.asIndex; int j = to_.asIndex; if (i > j) { // swap the the patterns so that i <= j i = i + j; // a + b j = i - j; // (a + b) - b (=a) i = i - j; // (a + b) - a (=b) // and invert the direction dir = dir.opposite(); } return(this[i, (int)dir, j]); }