Home World Forum
Stars! AutoHost web forums

Jump to Stars! AutoHost


 
 
Home » Stars! 2.6/7 » The Academy » Planet value calculation made easy!
Planet value calculation made easy! Sun, 20 March 2005 18:45 Go to previous message
m.a@stars is currently offline m.a@stars

 
Commander

Messages: 2765
Registered: October 2004
Location: Third star to the left
Hi,

I finally managed to understand how the planet habitability works (it took some zen!). In the process I rewrote the algorithm to make it easier on the eye (and perhaps on the compiler) as well as closer to the spirit of things. This code has already calculated 26000+ planets (belonging to 28 different planet reports) accurately.

A note for testers: Complications may arise due to integer math implicit conversions. Two of them are marked as such. The third is ugly enough that alternate code is provided.

Comments, suggestions, welcome!

#define BYTE char
#define WORD short

#define IMMUNE(a) ((a)==-1)

//simplified for this. Initialized somewhere else
struct playerDataStruct 
{
  BYTE lowerHab[3];	 // from 0 to 100 "clicks", -1 for immunity
  BYTE upperHab[3];
} player;

//in: an array of 3 bytes from 0 to 100
//out: a signed integer between -45 and 100
//hey, it was the Jeffs idea! Smile
signed long planetValueCalc(BYTE* planetHabData)
{
  signed long planetValuePoints=0,redValue=0,ideality=10000;	//in fact, they are never < 0
  WORD planetHab,habUpper,habLower,habCenter;
  WORD Excentr,habRadius,margin,Negativ,dist2Center;

  for (WORD i=0; i<3; i++) {
    habUpper = player.upperHab[i];
    if (IMMUNE(habUpper)) {			//perfect hab
      planetValuePoints += 10000;
    }
    else {	//the messy part
      habLower  = player.lowerHab[i];
      habCenter = (habUpper+habLower)/2;	//no need to precalc
      planetHab = planetHabData[i];

/*
 note: this version makes the basic assumption that habitability is
 symmetrical around the center, that is, the ideal center is located
 in the middle of the lower and upper boundaries, and both halves
 have the same value. The original algorithm seems able to cope with
 weirder definitions, i.e: bottom is 20, top is 80, center is 65,
 and hab value stretches proportionally to the different length of
 both "halves"...
*/

      dist2Center = abs(planetHab-habCenter);
      habRadius = habCenter-habLower;

      if (dist2Center<=habRadius) {		/* green planet */
	Excentr = 100*dist2Center/habRadius;	//note: implicit conversion to integer
	Excentr = 100 - Excentr;		//kind of reverse excentricity
	planetValuePoints += Excentr*Excentr;
	margin = dist2Center*2 - habRadius;
	if (margin>0) {		//hab in the "external quarters". dist2Center > 0.5*habRadius
	  ideality *= (double)(3/2 - dist2Center/habRadius);	//decrease ideality up to ~50%
	/*
	  ideality *= habRadius*2 - margin;	//better suited for integer math
	  ideality /= habRadius*2;
	*/
	}
      } else {					/* red planet */
	Negativ = dist2Center-habRadius;
	if (Negativ>15) Negativ=15;
	redValue += Negativ;
      }
    }
  }

  if (redValue!=0) return -redValue;
  planetValuePoints = sqrt((double)planetValuePoints/3)+0.9;	//rounding a la Jeffs
  planetValuePoints = planetValuePoints * ideality/10000;	//note: implicit conversion to integer

  return planetValuePoints;		//Thanks ConstB for starting this
}


{related topics: http://starsautohost.org/sahforum/index.php?t=msg&th=227 1&start=0&rid=625&S=425579ce978e6d33b2db2f095c4a 3dee

added some comments, mainly for version developers
}


[Updated on: Sun, 27 March 2005 16:10]




So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message icon1.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Research
Next Topic: Ship Teleportation bug
Goto Forum:
  


Current Time: Wed May 01 19:26:28 EDT 2024