Exemplo n.º 1
0
void play_chess2(int s[][10], int n, int i, int j)
{
	if (i > 9 || i < 0 || j < 0 || j > 9) {
		printf("%d %d is not permitted! please reonput.\n", i, j);
		play_chess(s,n);	
	}
	if (s[i][j] != 0) {
		printf("%d %d is not permitted! please reonput.\n", i, j);
		play_chess(s, n);
	}
	else {
		s[i][j] = n;
		chessboard(s);
	}
}
Exemplo n.º 2
0
int main(void)
{
	int a[10][10] = {0};
	int n = 1;

	chessboard(a);
	printf("You can input 4 4 to put a chess on board!\n");
	while (1) {
		if (n == 1) {
			play_chess(a, n);
			n = det_chess(a, n);
			if (n) break;
			n = 2;
		}
		if (n == 2) {
			computer(a, n);
			n = det_chess(a, n);
			if (n) {
				n++;
				break;
			}
			n = 1;
		}
	}
	if (n == 1) 
		printf("Congratulations, Play %d WIN!\n",n);
	else 
		printf("Congratulations, Computer WIN!\n");

	return 0;
}
Exemplo n.º 3
0
void play_chess(int s[][10], int n)
{
	int i, j;

	printf("Play %d:", n);
	scanf("%d %d", &i, &j);
	if (i > 9 || i < 0 || j < 0 || j > 9) {
		printf("%d %d is not permitted! please reonput.\n", i, j);
		play_chess(s,n);	
	}
	if (s[i][j] != 0) {
		printf("%d %d is not permitted! please reonput.\n", i, j);
		play_chess(s, n);
	}
	else {
		s[i][j] = n;
		chessboard(s);
	}
}
Exemplo n.º 4
0
int play_chess(int i, int j)
{
	/**/

	if (!check_pos(i, j)) {
		/* 先遍历某一行的所有列 */
		for (++j; j <= BOARD_SIZE; ++j) {
			if (check_pos(i, j))
				break;	
		}
		if (j > BOARD_SIZE) {
			/* 没有符合的列,要回溯 */	
			return 1;
		}
	}
	if (i <= BOARD_SIZE && j <= BOARD_SIZE) {
		/* 符合 */
		set_chess(i, j, HAVE_CHESS);
		ret = play_chess(i+1, 1); // 下一层
	}
	
}