bool Board::findSimplePath(int x1, int y1, int x2, int y2) { bool r = FALSE; // find direct line if(canMakePath(x1, y1, x2, y2)) { history[0].x = x1; history[0].y = y1; history[1].x = x2; history[1].y = y2; r = TRUE; } else { if(!(x1 == x2 || y1 == y2)) // requires complex path if(getField(x2, y1) == EMPTY && canMakePath(x1, y1, x2, y1) && canMakePath(x2, y1, x2, y2)) { history[0].x = x1; history[0].y = y1; history[1].x = x2; history[1].y = y1; history[2].x = x2; history[2].y = y2; r = TRUE; } else if(getField(x1, y2) == EMPTY && canMakePath(x1, y1, x1, y2) && canMakePath(x1, y2, x2, y2)) { history[0].x = x1; history[0].y = y1; history[1].x = x1; history[1].y = y2; history[2].x = x2; history[2].y = y2; r = TRUE; } } return r; }
// Find a path of 1 or 2 segments between tiles. Returns whether // a path was found, and if so, the path is returned via 'p'. bool Board::findSimplePath(int x1, int y1, int x2, int y2, Path& p) const { // Find direct line (path of 1 segment) if(canMakePath(x1, y1, x2, y2)) { p.push_back(Position(x1, y1)); p.push_back(Position(x2, y2)); return true; } // If the tiles are in the same row or column, then a // a 'simple path' cannot be found between them if(x1 == x2 || y1 == y2) return false; // Find path of 2 segments (route A) if(getField(x2, y1) == EMPTY && canMakePath(x1, y1, x2, y1) && canMakePath(x2, y1, x2, y2)) { p.push_back(Position(x1, y1)); p.push_back(Position(x2, y1)); p.push_back(Position(x2, y2)); return true; } // Find path of 2 segments (route B) if(getField(x1, y2) == EMPTY && canMakePath(x1, y1, x1, y2) && canMakePath(x1, y2, x2, y2)) { p.push_back(Position(x1, y1)); p.push_back(Position(x1, y2)); p.push_back(Position(x2, y2)); return true; } return false; }