• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
Question by Madrig88 · May 19, 2016 at 06:20 PM · javascriptarrays2d array

Can I use an array to determine an enclosed area and remove objects inside?

I'll be honest, I have very little experience with Arrays and I am only starting to understand them. I just want to know a basic idea as to how t$$anonymous$$s would work and get a good insight as to how t$$anonymous$$s would be done.

So t$$anonymous$$s is the situation I have. I am currently making a 2D world domination type of game using a 10x10 grid that you move pieces onto and set it down. After so many turns of going back and forth eventually the pieces may form an enclosed area, I want to use an array, unless there is somet$$anonymous$$ng better for t$$anonymous$$s purpose, to determine that an area has been enclosed, and remove any opposing pieces wit$$anonymous$$n that area and then claim it as the players "territory"

so I want to try and create a visual...

0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 1 1 0
0 0 0 1 0 8 8 0 1 0
0 0 0 1 0 8 8 0 1 0
0 0 0 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0

The 1's are the pieces of the player, and the 8 are the pieces of the opponent. How would I use an array, or another technique to make all the 8's and 0's inside of the enclosed 1's into 1's?

0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 1 1 0
0 0 0 1 1 1 1 1 1 0
0 0 0 1 1 1 1 1 1 0
0 0 0 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0

Any help would be greatly appreciated. Thank you!

Comment
NoseKills
ametkly

People who like this

2 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image OrbitGames · May 19, 2016 at 06:36 PM 0
Share

Unless I'm missing a really obvious and easy way to do this, this is actually quite complex. One way I can think off of doing this is by doing some sort of alteration of a flood fill algorithm. But you would also have to check if the edges are all of the same team. Another thing I can think of is that this reminds me a lot of the game go. You might be able to find some resources on how to program that...

Edit: Quick googling showed that Benson's Algorithm is used to determined which blocks belong to whom in go.

Hope this helps... Good luck

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

61 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to not repeat random array 0 Answers

Is it possible to summon specific GameObjects (i.e. from Assets) on a specific position in a jagged array so that I can later Destroy said object? 0 Answers

NullReferenceException in Update() 0 Answers

Sort an array in reverse alphabetical order 2 Answers

Array 2D of data 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges