Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
1
Question by penance · Aug 02, 2013 at 12:34 PM · spherepickupalgorithmcheck

Check for closed circuit of pickups

Hello all, me and a few friends are experimenting with some possible game ideas. Our attempts at creating this mechanic have been close but unfortunately broken.

The gameplay takes place upon a grid full of pickups. The player can attain these pickups in any order they like. Once they have created a circuit of attained pickups (circuit shown as red line); the circuit of attained pickups and the ones contained within; are transformed into bonus pickups.

alt text

Currently, each pickup has an ID and knows the ID of the pickup N E S & W of itself. The history of which pickups the player attains and in which order is recorded. We are checking for a circuit when the players location has 2 or more neighboring attained pickups. Stepping back through the playerPosition history to check if they have done a full circuit and then using a flood fill algorithm.

This works most of the time, however if the player is to exit the area of the current circuit they are creating and then return somewhere else (see picture below): In this circumstance, the flood fill executes when the player hits the blue coloured pickup, before the actual circuit is complete.

alt text

Basically, my question is: can anyone give us a shove in the right direction for a better way of calculating if a full circuit has been completed. The circuit doesnt have to be a square or rectangle, can be a very odd shape ... as long as it has unattained pickups contained within.

Ive been searching for some kind of mathematical algorithm to use but so far we are stumped.

example.jpg (206.0 kB)
example2.jpg (194.2 kB)
Comment
Add comment · Show 3
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 Owen-Reynolds · Aug 02, 2013 at 01:49 PM 0
Share

Does the order of pickups matter (same question: in the 2nd picture, should it pop after the entire path? Should the center pop if they grab all 16 edge pickups in random order?)

Can the edge pickups ever pop (if they grab the three around the lower corner, should it become bonus?)

You mention checking the player's history, and recording NESW directions. If they were in a 2D array, and order didn't matter, you could s$$anonymous$$l code from a GO game.

avatar image penance · Aug 02, 2013 at 01:55 PM 0
Share

In the example above, all 16 would need to be obtained before the centre would pop. The order in which the player takes the pickups shouldnt matter. However the player does not need to do the full 5x5 grid. They could do a 3x3 and pop the remaining 1 inside. Will have a look at "Go" now.

avatar image robertbu · Aug 02, 2013 at 03:44 PM 0
Share

Can they connect any place other then the end? For example, could they have gone "straight" from the blue marked object another row or two before turning right? Also can they reenter using a sphere that is already in use?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jamora · Aug 02, 2013 at 07:25 PM

I would approach this problem from a behavioral point of view: Create objects, but don't control them. Instaed tell them what, when and how to do their job.

The way I understand your question is that a circuit is complete if there exists a list of spheres, which connect to eachother. Instead of doing a top-down control scheme, what you should do is let the spheres themselves determine if they are a part of a circuit. I propose the following (recursive) solution:

Every time a new spehere is picked up, it sends a message to all neighboring speheres that have already been picked up. These neighboring spheres send a similar message to all picked-up neighbors except the source of the message. Now, if any sphere that has already sent a message receives one, it means it is a part of a circuit. The circuit could then be recovered by backtracking or other means if need be.

The message need not be an actual message, as you probably figured, a simple boolean flag that is set whenever the message sending function is called should suffice. Of course you might need something more complex if you have different types of spheres or circuits that cannot connect with eachother.

Also depending on how you want the actual search to behave, have a look at Depth First Search and Breadth First Search

Comment
Add comment · Share
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
0

Answer by Owen-Reynolds · Aug 03, 2013 at 05:34 PM

You pretty much have it. After each pickup, select any unused space and do your flood fill. If that touches no edges, you're surrounded. At first, that will fill the entire area. But after enough pickups, the first flood fill will be cut off from other free squares. So, keep picking unfilled squares and flood-filling from there.

A sneaky way to say "run flood fill until done" is to have a loop going through all pickups (a nested loop if you use a 2D array, but sounds like you aren't?) Whenever it finds a free square, run floodfill on that square. All runs in O(n).

Comment
Add comment · Share
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

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.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Check planes that have the same color of gameobject 2 Answers

How can I check if my Player leaves a Sphere? 2 Answers

Collision between sambe objects with same Layer 1 Answer

How do I cause the collision of one object affect the movement of another object? 0 Answers

How do I stop a timer when a sphere gets to a certain point? 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