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


C++ GoBoard::liberty_count方法代码示例

本文整理汇总了C++中GoBoard::liberty_count方法的典型用法代码示例。如果您正苦于以下问题:C++ GoBoard::liberty_count方法的具体用法?C++ GoBoard::liberty_count怎么用?C++ GoBoard::liberty_count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GoBoard的用法示例。


在下文中一共展示了GoBoard::liberty_count方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: write_features

void write_features(filtering_ostream& features_out, GoBoard& board, Player perspective_player) {
	uint8_t feature_buffer[BOARD_SIZE * BOARD_SIZE * FEATURE_COUNT] = {};
	for (int y = 0; y < BOARD_SIZE; y++) {
		for (int x = 0; x < BOARD_SIZE; x++) {
			Cell piece = piece_at(board, {x, y});
			assert(piece == 0 or piece == 1 or piece == 2);

#define FEATURE(k) (feature_buffer[(BOARD_SIZE * BOARD_SIZE * (k)) + (x) + (y) * BOARD_SIZE])
			FEATURE(FEAT_ONES_PLANE)            = 1;
			FEATURE(FEAT_EMPTY_LOCATIONS_PLANE) = piece == 0;
			FEATURE(FEAT_P1_STONES)             = piece == (int)perspective_player;
			FEATURE(FEAT_P2_STONES)             = piece == (int)opponent_of(perspective_player);

			// If the piece is non-zero then lookup the liberty count, and  write out feature maps.
			int liberties = (piece != 0) ? board.liberty_count({x, y}) : 0;
			if (piece == (int)perspective_player) {
				FEATURE(FEAT_P1_LIBERTY1)           = liberties == 1;
				FEATURE(FEAT_P1_LIBERTY2)           = liberties == 2;
				FEATURE(FEAT_P1_LIBERTY3)           = liberties == 3;
				FEATURE(FEAT_P1_LIBERTY4PLUS)       = liberties >= 4;
			} else {
				FEATURE(FEAT_P2_LIBERTY1)           = liberties == 1;
				FEATURE(FEAT_P2_LIBERTY2)           = liberties == 2;
				FEATURE(FEAT_P2_LIBERTY3)           = liberties == 3;
				FEATURE(FEAT_P2_LIBERTY4PLUS)       = liberties >= 4;
			}

			for (auto layer_and_player : {
				pair<FeatureKind, Player>{FEAT_P1_PLAY_CAUSES_CAPTURE1, perspective_player},
				                         {FEAT_P2_PLAY_CAUSES_CAPTURE1, opponent_of(perspective_player)},
			}) {
				FeatureKind feature_layer = layer_and_player.first;
				Player player = layer_and_player.second;
				FEATURE(feature_layer) = 0;
				// Check for a neighbor we might capture.
				if (piece_at(board, {x, y}) == 0) {
					Coord left  {x - 1, y};
					Coord right {x + 1, y};
					Coord above {x, y - 1};
					Coord below {x, y + 1};
					// Look for an adjacent group owned by the other player with exactly one liberty.
					// If such a group exists, then playing here causes a capture.
					int total_captured_stones = 0;
					for (auto direction : {left, right, above, below}) {
						if (coord_in_bounds(direction) and piece_at(board, direction) == (int)opponent_of(player)) {
							if (board.liberty_count(direction) == 1) {
								total_captured_stones += board.group_size(direction);
							}
						}
					}
					if (total_captured_stones > 2)
						total_captured_stones = 2;
					if (total_captured_stones > 0)
						FEATURE(feature_layer + (total_captured_stones - 1)) = 1;
				}
			}

			FEATURE(FEAT_IS_WHITE) = perspective_player == Player::WHITE;
#undef FEATURE
		}
	}
	features_out.write(reinterpret_cast<const char*>(feature_buffer), BOARD_SIZE * BOARD_SIZE * FEATURE_COUNT);
}
开发者ID:petersn,项目名称:snpgo,代码行数:63,代码来源:scan_directory.cpp


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