(I'm really sorry to have ask another question about arrays - I promise I have searched the forums and read the many, many existing threads!)
I'm maintaining a structure similar to a local high score table but, rather than ranking the player's performance between successive games, I'm ranking the performance of the computer-controlled enemies within the current game. As the game progresses, new enemy instances are created based on the properties of the previously highest-performing instances. It's a kind of simple genetic evolutionary progression, in that I hope the "fittest" (i.e. best performing) enemies in each level pass on their behaviours to create more successful future generations of enemies.
Let's say for the sake of argument that my enemies have two properties - their movement speed and their rate of fire. And, when each enemy is destroyed I assign a "fitness" score that determines how successful they were (based, say, on how many ticks they stayed alive for).
So, a snapshot of my data might have the following information about enemies that have died so far:
Movement_Speed | Rate_Of_Fire | Stayed_alive_for
30 | 2 | 10
20 | 1 | 8
5 | 8 | 30
1 | 6 | 25
As enemies are destroyed, a new row is added to the table. Each level has a fixed number of enemies, so the maximum number of rows is known.
However, the number of columns may vary in the future (let's say I also decide to record the "Armour" property of each enemy in another column).
I need to be able to sort the data but only based on one key (how long they stayed alive for), in order to be able to select the best-performing parents from which to derive better enemies in the next generation. In fact, I'd quite like the table be maintained as a sorted list so that I could pick off the highest scoring enemy to date as at any time.
So, my question is, how would you best achieve this using the structures available in C2? I've considered various combinations of multiple 1d arrays - one for each property (but I couldn't work out how to sort them all based on the keys in one array?), a 2d array containing only the fitness score and an ID that points to a dictionary entry maintaining the other properties (but I couldn't work out how to push() onto a 2d array).... and I've rewritten my code so many times that it's got scraps of different ideas all over the place now.
Hoping that some of you brainy and helpful let might save me from this dirge of code spaghetti! Thanks in advance.