本文整理汇总了C++中Puzzle::get_width方法的典型用法代码示例。如果您正苦于以下问题:C++ Puzzle::get_width方法的具体用法?C++ Puzzle::get_width怎么用?C++ Puzzle::get_width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Puzzle
的用法示例。
在下文中一共展示了Puzzle::get_width方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: manhattan
int manhattan(const Puzzle& state, const Puzzle& solution) {
int result = -1;
/*
* These loops compare two vectors piece by piece,
* finding the row and column indeces for corresponding
* pieces, and adding the magnitudes of the differences.
*
* This is presently O(n^2).
* TODO: investigate O(n) solution
*/
if(state.get_width() == solution.get_width()) {
size_t width = state.get_width();
int i = 0;
for(TileIt it1 = state.tiles.begin(); it1 != state.tiles.end(); it1++, i++) {
if(*it1 != 0) {
int j = 0;
for(TileIt it2 = solution.tiles.begin(); *it1 != *it2; it2++, j++);
int r1 = i / width;
int r2 = j / width;
int c1 = i % width;
int c2 = j % width;
result += abs(r2 - r1) + abs(c2 - c1);
}
}
}
return result;
}
示例2: displaced
/*
* These are the three examined heuristic functions.
* displaced(...) counts how many tiles are out of place
* manhattan(...) determines how far away each tile is from
* its correct location, as specified in the solution.
* sumdisman(...) simply sums displaced(...) and manhattan(...).
*/
int displaced(const Puzzle& state, const Puzzle& solution) {
int result = -1;
if(state.get_width() == solution.get_width()) {
result = 0;
for(TileIt it1 = state.tiles.begin(), it2 = solution.tiles.begin(); it1 != state.tiles.end(); it1++, it2++) {
if(*it1 != 0 && *it1 != *it2) {
result++;
}
}
}
return result;
}