Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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)
Posted
Updated 7-Sep-17 13:57pm
Comments
Graeme_Grant 7-Sep-17 5:30am    
Post your code, we won't write it for you.
rudy-peto 7-Sep-17 5:34am    
All I need is just a concept.
Code is just a simply iteration through 2 dimensional array.
But the checker is the problem.

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!
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900