Home » Stars! 2.6/7 » The Academy » Planet value calculation made easy!
Planet value calculation made easy! |
Sun, 20 March 2005 18:45 |
|
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!
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! Report message to a moderator
|
|
|
|
|
Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: sirgwain on Wed, 23 March 2005 12:56
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: sirgwain on Wed, 23 March 2005 15:54
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: ConstB on Fri, 08 April 2005 01:27
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: ConstB on Sat, 09 April 2005 12:44
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: Kotk on Sat, 09 April 2005 13:15
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: Kotk on Sat, 09 April 2005 15:03
|
|
|
Re: Planet value calculation made easy!
By: Ptolemy on Sat, 09 April 2005 15:25
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: LEit on Thu, 14 April 2005 14:09
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: Kotk on Sat, 09 April 2005 15:02
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: yartrebo on Tue, 02 October 2007 17:36
|
|
|
Re: Planet value calculation made easy!
By: regiss on Wed, 03 October 2007 16:45
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: Kelzar on Mon, 17 November 2008 14:52
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: Kelzar on Tue, 18 November 2008 07:42
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: Kelzar on Tue, 18 November 2008 19:31
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: Kelzar on Tue, 18 November 2008 22:23
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: XAPBob on Wed, 10 April 2013 05:05
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: XAPBob on Fri, 12 April 2013 02:41
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: Kelzar on Wed, 19 November 2008 10:33
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: Kelzar on Wed, 19 November 2008 12:39
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: XAPBob on Fri, 12 April 2013 07:29
|
|
|
Re: Planet value calculation made easy!
By: craebild on Fri, 12 April 2013 11:59
|
|
|
Re: Planet value calculation made easy!
By: XAPBob on Fri, 12 April 2013 12:40
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: XAPBob on Fri, 12 April 2013 18:58
|
|
|
Re: Planet value calculation made easy!
|
|
|
Re: Planet value calculation made easy!
By: leonidas on Sat, 13 April 2013 06:33
|
|
|
Re: Planet value calculation made easy!
|
Goto Forum:
Current Time: Wed May 01 19:26:28 EDT 2024
|