ZOJ-1862 Mine Sweeper

本文深入探讨了Unity3D和Unreal Engine两大游戏引擎的使用技巧,从基础概念到高级特性,全面解析游戏开发流程。通过实际案例,展示如何利用这些引擎创建高质量的游戏体验,包括动画、特效、物理模拟、音效处理等关键环节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mine Sweeper


Time Limit: 2 Seconds      MemoryLimit: 65536 KB


The gameMinesweeper is played on an n by n grid. In this grid are hidden m mines, eachat a distinct grid location. The player repeatedly touches grid positions. If aposition with a mine is touched, the mine explodes and the player loses. If apositon not containing a mine is touched, an integer between 0 and 8 appearsdenoting the number of adjacent or diagonally adjacent grid positions thatcontain a mine. A sequence of moves in a partially played game is illustratedbelow.

  

Here, n is 8, m is10, blank squares represent the integer 0, raised squares represent unplayedpositions, and the figures resembling asterisks represent mines. The leftmostimage represents the partially played game. From the first image to the second,the player has played two moves, each time choosing a safe grid position. Fromthe second image to the third, the player is not so lucky; he chooses aposition with a mine and therefore loses. The player wins if he continues tomake safe moves until only m unplayed positions remain; these must necessarilycontain the mines.

Your job is toread the information for a partially played game and to print the correspondingboard.


Input

The first line of input contains a single postitive integer n <= 10. Thenext n lines represent the positions of the mines. Each line represents thecontents of a row using n characters: a period indicates an unmined positonwhile an asterisk indicates a mined position. The next n lines are each ncharacters long: touched positions are denoted by an x, and untouched positionsby a period. The sample input corresponds to the middle figure above.

Input containsmultiple test cases. Process to the end of file.


Output

Your output should represent the board, with each position filled inappropriately. Positions that have been touched and do not contain a mineshould contain an integer between 0 and 8. If a mine has been touched, allpositions with a mine should contain an asterisk. All other positions shouldcontain a period.

Separate outputfor subsequent test cases with a single blank line.


Sample Input

8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
xxx.....
xxxx....
xxxx....
xxxxx...
xxxxx...
xxxxx...
xxx.....
xxxxx...


Sample Output

001.....
0013....
0001....
00011...
00001...
00123...
001.....
00123...


————————————————————————————————————————————————————————————————

如果点到了地雷,需要在最后的结果中将是地雷的点都表示出来。


————————————————————————————————————————————————————————————————

#include <stdio.h>
#include <string.h>
char calculate(int r, int l);
char map[10][10];
int n;
int main()
{
      int i, j, m, count;
      char touch[10][10];
      char str[11];
      char res[10][10];
      count = 0;
      while(scanf("%d", &n) != EOF) {
	    if(count) {
		  printf("\n");
	    } else {
		  count = 1;
	    }
	    for(i = 0; i < n; i++) {
		  scanf("%s", str);
		  for(j = 0; j < n; j++) {
			map[i][j] = str[j];
		  }
	    }
	    for(i = 0; i < n; i++) {
		  scanf("%s", str);
		  for(j = 0; j < n; j++) {
			touch[i][j] = str[j];
			res[i][j] = '.';
		  }
	    }
	    m = 0;
	    for(i = 0; i < n; i++) {
		  for(j = 0; j < n; j++) {
			if(touch[i][j] == 'x') {
			      if(map[i][j] == '*') {
				    m = 1;
			      } else {
				    res[i][j] = calculate(i, j);
			      }
			}
		  }
	    }
	    if(m) {
		  for(i = 0; i < n; i++) {
			for(j = 0; j < n; j++) {
			      if(map[i][j] == '*') {
				    res[i][j] = '*';
			      }
			}
		  }
	    }
	    for(i = 0; i < n; i++) {
		  for(j = 0; j < n; j++) {
			printf("%c", res[i][j]);
		  }
		  printf("\n");
	    }
      }
      return 0;
}
char calculate(int r, int l)
{
      char count = '0';
      if(r-1 >= 0 && map[r-1][l] == '*') {
	    count++;
      }
      if(r-1 >= 0 && l-1 >= 0 && map[r-1][l-1] == '*') {
	    count++;
      }
      if(l-1 >= 0 && map[r][l-1] == '*') {
	    count++;
      }
      if(r+1 < n && l-1 >= 0 && map[r+1][l-1] == '*') {
	    count++;
      }
      if(r+1 < n && map[r+1][l] == '*') {
	    count++;
      }
      if(r+1 < n && l+1 < n && map[r+1][l+1] == '*') {
	    count++;
      }
      if(l+1 < n && map[r][l+1] == '*') {
	    count++;
      }
      if(r-1 >= 0 && l+1 < n && map[r-1][l+1] == '*') {
	    count++;
      }
      return count;
}





                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值