本文整理汇总了C++中Neighborhood::get方法的典型用法代码示例。如果您正苦于以下问题:C++ Neighborhood::get方法的具体用法?C++ Neighborhood::get怎么用?C++ Neighborhood::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Neighborhood
的用法示例。
在下文中一共展示了Neighborhood::get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isHappy
bool Shape::isHappy(const Neighborhood & n, unsigned int pos_x, unsigned int pos_y) const {
if (n.get(pos_x, pos_y).getType() == "Empty")
return true;
unsigned int x_min = (pos_x == 0) ? pos_x : pos_x - 1;
unsigned int y_min = (pos_y == 0) ? pos_y : pos_y - 1;
unsigned int x_max = (pos_x == n.size_x - 1) ? pos_x : pos_x + 1;
unsigned int y_max = (pos_y == n.size_y - 1) ? pos_y : pos_y + 1;
double alike = 0;
double different = 0;
for (int x = x_min; x <= x_max; x++) {
for (int y = y_min; y <= y_max; y++) {
if (x == pos_x && y == pos_y)
continue;
else if (n.get(x, y).getType() == "Empty")
continue;
else if (n.get(x, y).getType() == n.get(pos_x, pos_y).getType())
alike++;
else
different++;
}
}
return (different || alike)
&& (different == 0 || alike / different >= RATIO_ALIKE_HAPPY)
&& (alike == 0 || different / alike >= RATIO_DIFFERENT_HAPPY);
}
示例2: isHappy
bool Shape::isHappy( const Neighborhood &n,
unsigned int pos_x,
unsigned int pos_y) const{
if (n.get(pos_x, pos_y).getType() == "empty")
return true;
// find the min and max coordinates of possible neighbors
unsigned int x_min = (pos_x == 0) ? pos_x : pos_x - 1;
unsigned int y_min = (pos_y == 0) ? pos_y : pos_y - 1;
unsigned int x_max = (pos_x == n.size_x-1) ? pos_x : pos_x + 1;
unsigned int y_max = (pos_y == n.size_y-1) ? pos_y : pos_y + 1;
double alike = 0;
double different = 0;
// evaluate each neighbor to deteremine likeness
for (int x=x_min; x <= x_max; x++) {
for (int y=y_min; y <= y_max; y++) {
if (x == pos_x && y == pos_y)
continue;
else if (n.get(x, y).getType() == "empty")
continue;
else if (n.get(x, y).getType() == n.get(pos_x, pos_y).getType())
alike++;
else
different++;
}
}
// returns true if the shape is happy
return ( different || alike )
&& ( different == 0 || alike / different >= RATIO_ALIKE_HAPPY )
&& ( alike == 0 || different / alike >= RATIO_DIFFERENT_HAPPY);
}