我如何解决这个战争游戏问题? [英] How do I solve this war game question?

查看:147
本文介绍了我如何解决这个战争游戏问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张战争游戏地图。它代表这样

。##

#..

#.a

假设'#'是山,'。'是空地,小写字母是军队。军队无法在被山脉包围的地区之间旅行。并且军队只能向上,向下,向左和向右移动。

以上示例显示军队'拥有'该区域,但是当我换成

时。##

#b。

#。a

军队'a'不拥有该地区,因为该地区有军队'b'。

如何检测军队'a'和军队'b'在同一地区?

我使用矩阵来映射该地图。但我仍然没有办法检查'a'和'b'在同一地区。

任何帮助将是apreciate。



谢谢!



我的尝试:



我我试图解决使用矩阵,但它没有给我一个答案。看起来我需要这么多变量来保存那片空地的状态(由谁自己)

I have a map of a war game. It represent like this
.##
#..
#.a
Assuming '#' is mountain, '.' is empty land, and lowercase alphabet is an armies. Armies could not travel between region that enclosed by mountains. And armies can only move up, down, left and right.
Above example shows that armies 'a' own that region, but when I change into
.##
#b.
#.a
Armies 'a' doesn't own that region because there is armies 'b' in that region.
How to detect that armies 'a' and armies 'b' is in same region?
I use matrix to map that map. But I still don't get a way to check 'a' and 'b' is in same region.
Any help will be apreciate.

Thanks!

What I have tried:

I have tried to solve using matrix, but it doesn't give me an answer. Looks like i need so much variable here to save the status of that empty land (own by who)

推荐答案

首先,确定不同的区域。这些是由。组成的空格。或垂直或水平触摸的字母字符。因此,确定区域,然后找到军队,找出他们所在的区域。



由于您的地区不规则,有两种方式存储区域:

1)为每个区域创建一个新地图,并用山填充。然后在找到它时将空地划出来。看看两个军队是否在同一个地区是很简单的:他们是否在同一张地图上?

2)Cleverer版本:当你识别一个区域时,将'。'字符改为一个数字指示地区号码。两支军队在同一地区吗?是的 - 它们是否在同一地区号码旁边...



但这是你的作业,所以我不会给你任何代码!
First, identify the separate regions. These are spaces that are made up of "." or alphabetic characters that touch either vertically or horizontally. So identify the regions, then locate the armies and find out which region they are in.

Since your regions are irregular, there are two ways to store the regions:
1) Create a new map for each region, and fill it with mountains. Then draw the empty land into that as you locate it. It's pretty simple to see if two armies are in the same region: are they on the same map?
2) Cleverer version: as you identify a region, change the '.' character to a number indicating the region number. Are two armies in the same region? Yes - is they are next to the same region number...

But this is your homework, so I'll give you no code!


这是HomeWork,所以没有代码,只是提示。

您需要机械思考。

如何手动操作:

1)绘制地图

2)找一支军队

3)着色可用的邻居单元格并传播着色,直到区域内没有更多可用单元格或者直到你遇到了另一支军队。

4)与另一支军队的相遇给你答案。

5)重复2)直到你对每个地区都有答案。 />


我们不做你的HomeWork。

HomeWork不会测试你的技能,乞求别人做你的工作,它设置为让您思考并帮助您的老师检查您对所学课程的理解以及您应用这些课程时遇到的问题。

你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。

你的任何失败都会帮助你了解什么有效,什么无效,被称为'试错'学习。

所以,试一试,重读课程并开始工作。如果您遇到特定问题,请展示您的代码并解释这个问题,我们可能会提供帮助。
This is HomeWork, so no code, just hint.
You need to think mechanically.
How you do manually:
1) Draw the map
2) Find an army
3) colorize neighbor cells that available and propagate the colorizing until there is no more available cells in region or until you encounter the other army.
4) The encounter with another army gives you the answer.
5) repeat at 2) until you have answer for every region.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.


这篇关于我如何解决这个战争游戏问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆