예제 #1
0
bool board::network_dfs(int index, int & total, int color) {
	if (index) {	// index >0 表示有棋子
		int x = index % array_size;
		int y = index / array_size;

		

		// m_visited[x][y]=1 表示网络里面已经有这个棋子了
		if (!judge_border(x, y) || m_visited[x][y])return 0;
		//	if (m_visited[x][y])return 0;
		// isfind =1 表示已经找到一个成功网络,可以直接返回
		bool isfind(0);
		// (x,y)位置上的棋子是不同色的
		if ((m_curr_color[x][y] % 2) != color)return 0;

		if (color == BLACK) {// 黑棋
			// y==1 有重复的棋子在特区,
			if (total&&y == 1)return 0;
			//if ((m_curr_color[x][y] % 2) == WHITE)return 0;
			if (y == board_size) {
				if (total >= chess_need_to_win - 1) {
					isfind = 1;
				}
				else return 0;
			}
		}
		else {
			if (total&&x == 1)return 0;
		//	if ((m_curr_color[x][y] % 2) == BLACK)return 0;
			if (x == board_size) {
				if (total >= chess_need_to_win - 1) {
					isfind = 1;
				}
				else return 0;
			}
		}
		m_visited[x][y] = 1;
		total++;
		m_success.push(index);
		if (isfind)return 1;

		for (int i(0); i < 4; ++i) {
			// 注意判断指针非空,
			// change by dyy 8 10
			//if (m_network[x][y][i].m_pioneer != NULL)
				isfind = network_dfs(m_network[x][y][i].m_pioneer->m_index, total, color);
			if (isfind)return 1;
			// 注意判断指针非空,
			if (m_network[x][y][i].m_next != NULL)
				isfind = network_dfs(m_network[x][y][i].m_next->m_index, total, color);
			if (isfind)return 1;
		}
		m_visited[x][y] = 0;
		total--;
		m_success.pop();
		return 0;
	}
	else return 0;
}
예제 #2
0
void board::init_line_head(int x, int y, int direction) {
	int count(0);	// 记录是第几个结点
	//由于棋盘扩大了,把周边没有用的结点作为一些链表的空头结点,增加结点的利用率,不用动态结点,方便初始化
	node* head = &m_network[x][y][direction];
	while (1) {
		//根据方向数组,计算链表的下一个结点的位置,
		x += m_surround[direction][0];
		y += m_surround[direction][1];
		if (judge_border(x, y)) {
			m_head[x][y][direction] = head;
			m_network[x][y][direction].m_num = ++count;
		}
		else break;
	}
}
예제 #3
0
bool board::feasible(int color, int x, int y) {
	// judge_border 表示是否越界
	//  m_curr_color 不为0 ,表示有棋子,或为禁区
	if (!judge_border(x, y) || m_curr_color[x][y] || m_limit[color][x][y] >= m_inf)return false;

	//附近有2个棋子
	if (m_limit[color][x][y] >= 2)return 0;

	int count = 0;//记录周围有几个同色棋子

	int near_x, near_y;
	for (int i(0); i < dir_count; ++i)
	{
		near_x = x + m_surround[i][0];
		near_y = y + m_surround[i][1];
		// 表示周围有一个同色棋子,而且这个棋子周围也有一个同色棋子
		if (m_limit[color][near_x][near_y] >= m_inf2 + 1)return false;
	}
	return true;
}
예제 #4
0
bool board::feasible(CHESS_COLOR color, int x, int y) {
	if (!judge_border(x, y) || m_curr_color[x][y] || m_limit[color][x][y] >= m_inf)return false;

	//附近有2个棋子
	if (m_limit[color][x][y] >= 2)return 0;

	int count = 0;//记录周围有几个同色棋子

	int near_x, near_y;
	for (int i(0); i < dir_count; ++i)
	{
		near_x = x + m_surround[i][0];
		near_y = y + m_surround[i][1];
		//if (m_situation[near_x][near_y] > 0 && m_situation[near_x][near_y] < m_inf&&m_situation[near_x][near_y] % 2 == color&&m_limit[color][near_x][near_y] == 2)return 0;

		// change by dyy at 8 7 10:36
		if (m_limit[color][near_x][near_y] == m_inf2 + 1)return false;
	}
	return true;
}