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
0
Question by Howey-Do-It · Sep 26, 2013 at 01:11 AM · arrayloopfor loopunknown

Method to loop through an unknown number of variable combinations in C#

Goal:

My goal is to set up a function that will find all possible combinations of letters that make words (assuming you can combine the letters in any direction, without using the same object twice or combining objects that are not next to each other).

Context:

I have a grid of objects with randomly picked letters as children. Each object has a script attached that has the other letters immediately around it stored in a GameObject[] variable. Like this:

0------1------2

7------X------3

6------5------4

I already have way to check against the letter combinations to see if they are actual words.

The "allLetters" variable below is an array of all the letter objects.

     void FindPossibleWords()
     {
         
         foreach(GameObject al in allLetters)
         {
             
             string word = al.GetComponent<Letter>().letter;
         
             for(int i = 0; i < 7; i++)
             {
                 
                 word += al.GetComponent<Letter>().near[i].GetComponent<Letter>().letter;
                 
                 if("Letters can still potentially make a real word")
                 {
                     
                 // Repeat?        
                     
                 }
             }
         }
     }

I'm not looking for someone to write the code for me. I just can't get my brain around a method/strategy for looping through an "unknown" number of times.

I can already see that this will not work the way I am going about it. Essentially I am looking for a way for it to loop through an unknown number of letter combinations and then store the ones that are real words.

I apologize for the minimal amount of code, mostly I am stuck on what strategy to use to get the result. I feel like I could get the result with a ridiculous amount of code, but there is usually some other option that I am missing.

I appreciate any help.

Thanks,

Howey

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Seizure · Sep 26, 2013 at 03:48 AM

OK, A little late for me to take a crack at this but lets hope I can shed some light for you...

Anyways I would use a circular method, so take X as your starting position, circle out from that position and continously check against you library of words, if it counts as one maintain that in an array and continue on with your array. I will try and psuedo code this for you...

 string word = "";
 for (int i = 0; i<gridWidth.Length; i++)
 {
     for (int k = 0; k<gridHeight.Length; k++)
     {
           for (int l = 0; l< i; l++)
           {
               word = Array.join(word,i,k);//This isn't the right syntax I hardly ever use this command
           }
     }
 }

I hope this gets you on the way, if it helps but not quite gets you all the way let me know where you're stuck and I'll help some more.

Comment
Add comment · Show 2 · 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 Howey-Do-It · Oct 02, 2013 at 01:06 AM 0
Share

Ok, sorry for not getting back to you sooner. I was gone over the weekend. I'm not sure I fully understand how this would work or at least I guess I don't get where the other pieces would fit in.

$$anonymous$$y GameObject[]s currently only contain the immediately adjacent GameObjects which have a GameObject[] variable that contains the ones immediately around it, etc. The concept of this method was that it would be easier to transition in any direction.

It looks like you are theorizing using a multidimensional array? Or is it just a normal array that contains all of the letter objects?

And thank you again for answering so quickly.

Howey

avatar image Howey-Do-It · Feb 05, 2014 at 08:38 PM 0
Share

Thank you for the help, I appreciate it, and it helped me get to where I wanted to go.

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

Loop through array until certain value is found. 2 Answers

Trouble with for loop out of range. Simple? Maybe. 1 Answer

How to correctly shorten this script using arrays and iterations 2 Answers

Checking an array variable in C# vs JavaScript 3 Answers

How to create an image gallery with previous and next button with C#? 6 Answers


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