void Board::collapse(Direction dir) { dir = reversePosition(dir); int currLoc; int nextLoc = initPos(dir); for(int i = 0; i < 4; ++i) { for(int j = 0; j < 3; ++j) { currLoc = nextLoc; nextLoc = next(dir, nextLoc); if((m_state[nextLoc] != 0) && (m_state[currLoc] == m_state[nextLoc])) { m_state[nextLoc] *= 2; m_state[currLoc] = 0; } } nextLoc = nextRow(dir, next(dir, currLoc)); } }
size_t PositionComputer::delta(size_t pos, size_t originalDelta) const { assert(position(reversePosition(pos)) == pos); return position(reversePosition(pos) + originalDelta) - pos; }