Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8993769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:16:07+00:00 2026-06-15T23:16:07+00:00

I was wondering what would be the best way to handle complex structures with

  • 0

I was wondering what would be the best way to handle complex structures with relationships?

I am implementing a galaxy generation algorithm for my project, basically i have simple enums of

GalaxySize { Small, Medium, Large };
GalaxyAge { Young, Mature, Ancient}; 
StarTypes { Black = 1, White = 3, Yellow = 1, Red = 3 };

I am generating stars limited by the value of GalaxySize so far so good.
Then i get randomly a type from StarTypes and create a star from this type.
What i want to do is have a relationship between the StarTypes and the GalaxyAge.

Meaning that in a young galaxy (for example) there will be a higher chance for Yellow and White stars, and in a ancient galaxy there will be a higher chance for black and red stars.

What i am thinking of is having a base chance for a StarType to get “rolled” and then add the modifier depending on the GalaxyAge, which will result in more of the more common stars in the specific galaxy age.

Example: weight (chance) of a white star in young galaxy is 3 base + 3 
from the "young" galaxy age modifier 
against the weight of a red star which has 3 base + 1 from the "young" modifier.


Resulting in:
White star type weight = (3 + 3 ) * rand.nextDouble() 
Red star type weight = (3 + 1) * rand.nextDouble()

Any suggestions on how to realize/represent this functionality since obviously enums alone will not be enough? 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:16:08+00:00Added an answer on June 15, 2026 at 11:16 pm

    I didn’t really understand the algorithm but you can start from this:

    sealed class Age
    {
        public static readonly Young = new Size(3.0);
        public static readonly Mature = new Size(2.0);
        public static readonly Ancient = new Size(1.0);
    
        public double Weight
        {
            get;
            private set;
        }
    
        private Age(float weight)
        {
            Weight = weight;
        }
    }
    
    sealed class Size
    {
        public static readonly Small = new Size(3.0);
        public static readonly Medium = new Size(2.0);
        public static readonly Large = new Size(1.0);
    
        public double Weight
        {
            get;
            private set;
        }
    
        private Size(float weight)
        {
            Weight = weight;
        }
    }
    

    Now let’s define a class for Galaxy:

    sealed class Galaxy
    {
        public Age Age
        {
            get;
            set;
        }
    
        public Size Size
        {
            get;
            set;
        }
    }
    

    Now you have to define a class to define the star:

    abstract class Star
    {
        protected Star(string color, Galaxy galaxy)
        {
            Color = color;
            Galaxy = galaxy;
        }
    
        public string Color
        {
            get;
            private set;
        }
    
        public Galaxy Galaxy
        {
            get;
            private set;
        }
    
        public abstract float Chances(Random rnd);
    }
    

    Now let’s define a new class for each star (don’t forget to change algorithm, formula and weights according to what it is in reality for each type):

    sealed class WhiteStar : Star
    {
        public WhiteStar(Galaxy galaxy) : base("White", galaxy)
        {
        }
    
        public override float Chances(Random rnd)
        {
            return (3 + Galaxy.Age + Galaxy.Size) * rnd.NextDouble();
        }
    }
    

    Of course this can’t be the final code but you can use it as hint to organize your code.

    Best benefit is that the Galaxy isn’t aware of the rules to get a particular type of star, each star type knows its own rules (it means if you add a new star type you won’t need to search for rules spanned all around in many classes). Of course this is valid for other classes too (for example if you add a MiddleAge galaxy’s age you won’t need to update any other class).

    Finally don’t forget to change the name of the Weight property to something more meaningful for your domain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Was wondering what the best way to handle this would be. Say I have
I was wondering what would be the best way to handle errors in an
Was wondering what the best way to handle an expensive web task? I have
I was wondering what would be the best way to handle an application timeout,
i was wondering what would be the best way to code a browser plugin
I recently started learning backbone and was wondering what would be the best way
I was wondering, what would be the best way to validate an integer. I'd
I've been wondering what the best way to do this would be. I've got
Wondering what the best / good way of doing this would be in jQuery.
I'm wondering what would be best to do. Right now I have running a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.