当前位置: 首页>>代码示例>>C++>>正文


C++ Neighborhood::get方法代码示例

本文整理汇总了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);
	}
开发者ID:rogergriff,项目名称:assignment-02,代码行数:31,代码来源:shape.cpp

示例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); 
}
开发者ID:areeveNoS,项目名称:assignment-02,代码行数:35,代码来源:shape.cpp


注:本文中的Neighborhood::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。