Hi Forum. Hope you can help me.
I'm working on a spreadsheet for a science fiction game. In it, the spreadsheet is randomly designing a solar system for me. It can have a varied number of planets, each residing in 1 of 19 possible orbits. The orbits it resides in is somewhat random, though, for example, icy planets have a greater chance of being further out from the central star than hot ones, etc.
I have everything working fine as for how the planets are generated. The spreadsheet will also assign them an orbit number according to my rules. My problems are this:
1) The spreadsheet will often assign an orbit number that duplicates an already existing one, and/or
2) Sometimes the spreadsheet will assign a planet an orbit that can't exist because of the size of the central star (really big stars can envelop up to the first 9 orbits).
The rules for the game state that if you randomly roll an orbit that is already taken, you put the world in the nearest empty orbit, going either up or down in orbits until you find an empty one. I have the spreadsheet already calculating star size, and if the star takes up any orbits, it marks them as taken. So my question:
How can I have Excel determine a non-repeating orbit number for each planet within these rules? I.e. if an orbit is occupied for any reason, go up or down an orbit until an empty orbit is found, and assign the planet to that orbit. Of course, as the list is populated, more orbits are occupied and so that would affect which orbits later planets could go into.
An example might help:
Here's a simplified list from the spreadsheet:
Orbit
0 Occupied by Star
1 Occupied by Star
2
3
4 Planet Amethyst
5
6
So, let's say that Planet Beryl is generated, and given an orbit of 4. Well, Orbit 4 is occupied, so the rules say Planet Beryl can occupy either Orbit 3 or 5.
Let's say that Planet Beryl was given an orbit of 1. This orbit is occupied by the star. So it should be put into Orbit 2. It can't go into Orbit 0.
About me: I am self-taught with Excel. I don't know anything about VBA or macros. However, I'm pretty good at picking up on formulae and their use. (I learned a lot from building this project.) I'm handy with IFs, ANDs, ORs, VLOOKUPS, etc. and used LEFTs and RIGHTs a few times. Maybe there's a formula that makes this easy-- would be great if you could point me towards it.
Thanks in advance.
Bookmarks