Home World Forum
Stars! AutoHost web forums

Jump to Stars! AutoHost


 
 
Home » Stars! 2.6/7 » The Academy » Planet value calculation made easy!
Re: Planet value calculation made easy! Wed, 03 October 2007 16:45 Go to previous messageGo to next message
regiss

 
Petty Officer 1st Class

Messages: 65
Registered: November 2002
Shouldn't this be moved to "Free Stars" or smth..

"Academy's" starting to gather up all kinds of posts I guess.

Report message to a moderator

Re: Planet value calculation made easy! Wed, 03 October 2007 20:17 Go to previous messageGo to next message
m.a@stars is currently offline m.a@stars

 
Commander

Messages: 2765
Registered: October 2004
Location: Third star to the left
regiss wrote on Wed, 03 October 2007 22:45

Shouldn't this be moved to "Free Stars" or smth..

"Academy's" starting to gather up all kinds of posts I guess.



This is not Freestars code (yet) Rolling Eyes

This is an original Stars! algorithm, somewhat refactored to make it cleaner/more readable, and posted to show the inner workings of a vital part of the game. Sherlock Whip



So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: Planet value calculation made easy! Mon, 17 November 2008 14:52 Go to previous messageGo to next message
Kelzar is currently offline Kelzar

 
Master Chief Petty Officer

Messages: 112
Registered: January 2006
Location: Ohio, US
Alright maybe I'm doing something wrong but according to this calculation it still seems to miss by 1% (up and down) for several cases I've tried. Lets use a simple 2 Immune, smallest bandwidth possible. There should be 11 different green habs and according to this calculation they would be ....

100,97,94,92,89,87,77,67,58,49 and 41.

I run a test bed and get a 6click from perfect planet as 76.
I've run several other testbeds and am getting variances with them also.

the equation boils down to
sqrt(21600/3)*.9+.9
or 77.2675 so I don't see some minor flakey rounding problem accounting for the variance.
Am I doing something wrong?

Report message to a moderator

Re: Planet value calculation made easy! Mon, 17 November 2008 20:50 Go to previous messageGo to next message
m.a@stars is currently offline m.a@stars

 
Commander

Messages: 2765
Registered: October 2004
Location: Third star to the left
Kelzar wrote on Mon, 17 November 2008 20:52

Alright maybe I'm doing something wrong but according to this calculation it still seems to miss by 1% (up and down) for several cases I've tried. Lets use a simple 2 Immune, smallest bandwidth possible. There should be 11 different green habs and according to this calculation they would be ....

I think I follow what you're doing, but I'm afraid I'll need actual numbers to be able to check your results: Sherlock
Deal What are the Immunities, and what are the numbers for the 3rd hab?
Deal What are the habs for that rogue 76/77 value planet?
Deal What other cases have you tried that give you trouble?



So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: Planet value calculation made easy! Tue, 18 November 2008 07:42 Go to previous messageGo to next message
Kelzar is currently offline Kelzar

 
Master Chief Petty Officer

Messages: 112
Registered: January 2006
Location: Ohio, US
Very simple case

Grav and Temp Immune
Rad perfectly centered 40-60

I've tried other cases while opening up the rad band with similar results and I'm pretty sure I had similar results with that same bandwidth with the center of the hab being a few clicks off 50. Don't have the actual results here at work.


Report message to a moderator

Re: Planet value calculation made easy! Tue, 18 November 2008 09:11 Go to previous messageGo to next message
m.a@stars is currently offline m.a@stars

 
Commander

Messages: 2765
Registered: October 2004
Location: Third star to the left
Hmm, I see. Without all the numbers I can only guess you might be applying rounding incorrectly. Sherlock

In the step sqrt((double)planetValuePoints/3)+0.9 the result is truncated (rounded down)

Then in the step planetValuePoints * ideality/10000 another truncation takes place. That isn't the same as your sqrt(21600/3)*.9+.9



So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: Planet value calculation made easy! Tue, 18 November 2008 19:31 Go to previous messageGo to next message
Kelzar is currently offline Kelzar

 
Master Chief Petty Officer

Messages: 112
Registered: January 2006
Location: Ohio, US
According to the algorithm what percentage for
GravImm TempImm Rad37-63 race would you get for a 45mR planet?

I keep getting 89%, and if I completely remove all the rounding the most I can get the value up to (using the algorithm's calcs) is 89.9449

Two 45mR planets in the same testbed are showing as 90% planets.

One .21grav,64deg,45mR the other 3.92,-56deg,45mR

So do I still have something wrong or is there another Jeff factor buried in the calculation yet?

Report message to a moderator

Re: Planet value calculation made easy! Tue, 18 November 2008 20:45 Go to previous messageGo to next message
AlexTheGreat is currently offline AlexTheGreat

 
Lieutenant

Messages: 661
Registered: May 2006
Location: Sydney, Australia
Kelzar wrote on Tue, 18 November 2008 19:31

According to the algorithm what percentage for
GravImm TempImm Rad37-63 race would you get for a 45mR planet?

I keep getting 89%, and if I completely remove all the rounding the most I can get the value up to (using the algorithm's calcs) is 89.9449

Two 45mR planets in the same testbed are showing as 90% planets.

One .21grav,64deg,45mR the other 3.92,-56deg,45mR

So do I still have something wrong or is there another Jeff factor buried in the calculation yet?



I can assure you that 89% is the correct value for any planet with Rad=45 with those hab settings.

Report message to a moderator

Re: Planet value calculation made easy! Tue, 18 November 2008 22:23 Go to previous messageGo to next message
Kelzar is currently offline Kelzar

 
Master Chief Petty Officer

Messages: 112
Registered: January 2006
Location: Ohio, US
Then how can I be looking at TWO planets that are 90% Confused
Have you actually run the test beds because I'm looking at them, and yes I'm running version j.

Report message to a moderator

Re: Planet value calculation made easy! Wed, 19 November 2008 04:49 Go to previous messageGo to next message
m.a@stars is currently offline m.a@stars

 
Commander

Messages: 2765
Registered: October 2004
Location: Third star to the left
AlexTheGreat wrote on Wed, 19 November 2008 02:45

I can assure you that 89% is the correct value for any planet with Rad=45 with those hab settings.

Are you sure on that? I get 90. Confused



So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: Planet value calculation made easy! Wed, 19 November 2008 04:59 Go to previous messageGo to next message
m.a@stars is currently offline m.a@stars

 
Commander

Messages: 2765
Registered: October 2004
Location: Third star to the left
Kelzar wrote on Wed, 19 November 2008 01:31

According to the algorithm what percentage for
GravImm TempImm Rad37-63 race would you get for a 45mR planet?

90. Cool

Quote:

I keep getting 89%, and if I completely remove all the rounding the most I can get the value up to (using the algorithm's calcs) is 89.9449

Two 45mR planets in the same testbed are showing as 90% planets.

One .21grav,64deg,45mR the other 3.92,-56deg,45mR

So do I still have something wrong or is there another Jeff factor buried in the calculation yet?

I'd need to know exactly how are you applying the formulas. Bear in mind that the posted algorithm is C, which means an integer truncation happens every time integer math is performed (which is a lot of times) Sherlock

It is very unlikely a "Jeff Factor" is still buried somewhere in this, since this algorithm was extracted from Stars! own binary code. It is also part of race validation, which we have reverse-engineered too and found to be exact. Race validation calls planetValueCalc hundreds of times. Plus, before publishing it I validated the math against 35000 actual planet values lifted from 20 different universes for a bunch of different races. Deal



So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: Planet value calculation made easy! Wed, 19 November 2008 05:05 Go to previous messageGo to next message
m.a@stars is currently offline m.a@stars

 
Commander

Messages: 2765
Registered: October 2004
Location: Third star to the left
Kelzar wrote on Mon, 17 November 2008 20:52

Lets use a simple 2 Immune, smallest bandwidth possible. There should be 11 different green habs and according to this calculation they would be ....

100,97,94,92,89,87,77,67,58,49 and 41.

I run a test bed and get a 6click from perfect planet as 76.

The algorithm gets that too, as well as your whole sequence of hab values, for a Grav/Temp Immune + Rad40-60 race. Cool



So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: Planet value calculation made easy! Wed, 19 November 2008 10:33 Go to previous messageGo to next message
Kelzar is currently offline Kelzar

 
Master Chief Petty Officer

Messages: 112
Registered: January 2006
Location: Ohio, US
Aha, found the truncation that pushes it to the 90% and I suspect that it will remedy the other variances. Thanks for the help. Cool

Report message to a moderator

Re: Planet value calculation made easy! Wed, 19 November 2008 12:02 Go to previous messageGo to next message
m.a@stars is currently offline m.a@stars

 
Commander

Messages: 2765
Registered: October 2004
Location: Third star to the left
You're welcome. Very Happy I take it you're translating the formulas to something other than C?



So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: Planet value calculation made easy! Wed, 19 November 2008 12:39 Go to previous messageGo to next message
Kelzar is currently offline Kelzar

 
Master Chief Petty Officer

Messages: 112
Registered: January 2006
Location: Ohio, US
Nailed it right on the nose.
Working on updating/fixing a .xls

Report message to a moderator

Re: Planet value calculation made easy! Wed, 19 November 2008 13:26 Go to previous messageGo to next message
m.a@stars is currently offline m.a@stars

 
Commander

Messages: 2765
Registered: October 2004
Location: Third star to the left
Heh, I had similar problems when translating to javascript. Twisted Evil


So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: Planet value calculation made easy! Wed, 19 November 2008 20:05 Go to previous messageGo to next message
AlexTheGreat is currently offline AlexTheGreat

 
Lieutenant

Messages: 661
Registered: May 2006
Location: Sydney, Australia
[email

m.a@stars[/email] wrote on Wed, 19 November 2008 04:49]
AlexTheGreat wrote on Wed, 19 November 2008 02:45

I can assure you that 89% is the correct value for any planet with Rad=45 with those hab settings.

Are you sure on that? I get 90. Confused


I've been using posey's method of calculating planet values for quite a while & have used it in a spreadsheet I created to calculate values for an entire universe for given race habs & at any tech levels. The only time it's ever been wrong is with very low grav planets, the ones where grav is shown as eg. 0.14 where you can't tell if it's actually 0.14 or 0.145.

I get 89% for all planets with Rad=45 regardless of other planet habs if race settings are Imm,Imm,37-63 (I modified 512 planets to all be Rad=45).

You seem to have gone into this quite deeply m.a. so I'll back off on the "I can assure you" & make it "in my experience it's always 89%".

Off subject here m.a. but I like your fuelusage.html. I use it often.
Have you thought about providing an alternative so that you can just specify the distance (as an alternative) rather than needing to put in the co-ordinates? That might not be as easy as it sounds tho since it looks like your coding depend upon co-ords.



[Updated on: Wed, 19 November 2008 20:19]

Report message to a moderator

Re: Planet value calculation made easy! Thu, 20 November 2008 08:35 Go to previous messageGo to next message
m.a@stars is currently offline m.a@stars

 
Commander

Messages: 2765
Registered: October 2004
Location: Third star to the left
AlexTheGreat wrote on Thu, 20 November 2008 02:05

I've been using posey's method of calculating planet values for quite a while & have used it in a spreadsheet I created to calculate values for an entire universe for given race habs & at any tech levels. The only time it's ever been wrong is with very low grav planets, the ones where grav is shown as eg. 0.14 where you can't tell if it's actually 0.14 or 0.145.

I get 89% for all planets with Rad=45 regardless of other planet habs if race settings are Imm,Imm,37-63 (I modified 512 planets to all be Rad=45).

Posey's math is pretty good except for "borderline" cases, where smooth exponential curves don't quite match the Jeffs quirky (and presumably faster) code. Sherlock


Quote:

You seem to have gone into this quite deeply m.a. so I'll back off on the "I can assure you" & make it "in my experience it's always 89%".

Others dived. All I did was translate, mass-test (with the help of a dozen gamehosts) and publish in a mostly readable form. Rolling Eyes


Quote:

Off subject here m.a. but I like your fuelusage.html. I use it often.
Have you thought about providing an alternative so that you can just specify the distance (as an alternative) rather than needing to put in the co-ordinates? That might not be as easy as it sounds tho since it looks like your coding depend upon co-ords.

I probably should rewrite most of that tool. It is indeed geared towards extracting the shortest possible trips out of the given coords. If you just want to check fuel vs distance you can always input made-up coordinates. Deal



So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

icon1.gif  Re: Planet value calculation made easy! Wed, 10 April 2013 05:05 Go to previous messageGo to next message
XAPBob is currently offline XAPBob

 
Lt. Commander

Messages: 957
Registered: August 2012
Hi all - been pulling together a perl module to start playing with data...

The numbers I'm getting are close, but in various cases are a few (up to 4) percent out in either direction.

I'm about to fire up a fat (huge, packed) testbed with 16 different racial hab settings and then force gen it to oblivion (and elephant galleons) in order to get a significant data set (which I can share)

Can anyone spot any obvious bugs I've managed to generate whilst porting the C code in the first post to perl?


#!/usr/bin/perl
# Stars! check racial habs

use StarsHabCalc;

use warnings;
use strict;

use Switch;

sub usage {
  print "This script takes two csv files as parameters:\n";
  print " - A race hab file - this consists of four lines of data from the RW and game:\n";
  print "   - Low, High, Terraforming ability for each of\n";
  print "   - Grav, Temp, Rad\n";
  print "   - Followed by a racename\n";
  print " - A planet data file - consisting of a line per planet:\n";
  print "   - Name, Grav, Temp, Rad (Any other fields are ignored, but retained)\n";
  print "\n";
}

# CODE START:
my ($racefile, $planetfile) = @ARGV;
&StarsHabCalc::LoadRacial ($racefile);

open PLANETS, $planetfile or die $!;
while (my $line = <PLANETS>) {
  chomp $line;
  my @line = split(',', $line);
  my $planet = shift @line;
  my $grav = shift @line;
  my $temp = shift @line;
  my $rad = shift @line;
  my @clicks = (&StarsHabCalc::GravToClicks($grav),
                &StarsHabCalc::TempToClicks($temp),
                &StarsHabCalc::RadToClicks($rad)   );
  print join(',', $planet, &StarsHabCalc::HabFromClicks(@clicks), $grav, $temp, $rad, @line) . "\n";
}
close PLANETS;


"use"s StarsHabCalc.pm:
#!/usr/bin/perl
# Stars! Hab calculator...
# Version 0.1

# Credit particularly due to m.a@stars on the SAH forums:
#  http://starsautohost.org/sahforum2/index.php?t=msg&th=2299

package StarsHabCalc;
require Exporter;

use warnings;
use strict;

use Switch;

# Functions to take the value of parameter and convert to clicks:
sub RadToClicks {
  my $rad = shift;
  return $rad;
}
sub TempToClicks {
  my $temp = shift;
  return ($temp+200)/4;
}
sub GravToClicks {
  # Early grav clicks are ambiguous: .12,.12,.13,.13,.14,.14,.15,.15,.16,.17,(.17)
  # (.17) - The last ambiguous point and the lowest possible hab centre (wacky choice).
  # We always assume the worst (i.e. the lower clicks), appropriate for planet values.
  # For hab the click width is ALWAYS even, so we should be able to deduce hab properly
  # in the appropriate function (not here though)
  my $grav = shift;
  my $result;

  $grav *= 100;
  my $lowerHalf = 1;
  if ($grav < 100) {
    $grav = int(10000/$grav);   #integer truncation
    $lowerHalf = -1;
  }
  if ($grav < 200) {
    $result = ($grav /4) - 25; # NO integer truncation
  } else {
    $result = ($grav +400) / 24;
  }
  $result = int(50.9 + $lowerHalf * $result);
  #one less ambiguity since planets can never be zero clicks
  $result = 1 if ($result < 1);
  return $result;
}

# Define racial paramters. All arrays are in order "grav, temp, rad"
our $racename;
our @centre;
our @radius;
our @terra;

sub LoadRacial {
  my $file = $_[0];
  open (RACE, $file) or die $!;
  my @lines = <RACE>;
  close (RACE);
  chomp @lines;
  for (my $i=0; $i<3; $i++) { #i.e. grav/temp/rad
    my ($lower, $higher, $terra) = split(/,/, $lines[$i]);
        if ($lower ne 'immune') {
          switch ($i) {
            case 0 { $lower = &GravToClicks($lower);
                                 $higher = &GravToClicks($higher);
                                 $lower = 0 if ($lower == 1); # Correct for the planet assumption above
                                 $lower++ if (($higher - $lower) % 2 == 1);} #Width must always be even
                                               # This can he
...

Report message to a moderator

Re: Planet value calculation made easy! Thu, 11 April 2013 17:55 Go to previous messageGo to next message
m.a@stars is currently offline m.a@stars

 
Commander

Messages: 2765
Registered: October 2004
Location: Third star to the left
XAPBob wrote on Wed, 10 April 2013 11:05
$centre[$i] = $higher - $lower;

That one looks different from the original. Sherlock



So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: Planet value calculation made easy! Fri, 12 April 2013 02:41 Go to previous messageGo to next message
XAPBob is currently offline XAPBob

 
Lt. Commander

Messages: 957
Registered: August 2012
Thank you. been reading it for too long Smile

Report message to a moderator

Re: Planet value calculation made easy! Fri, 12 April 2013 07:29 Go to previous messageGo to next message
XAPBob is currently offline XAPBob

 
Lt. Commander

Messages: 957
Registered: August 2012
Updated to the below.

          $radius[$i] = ($higher - $lower) / 2;
          $centre[$i] = $higher - $radius[$i];
          $terra[$i] = $terra;



I get about 10% of planets where I have a 1% error (overwhelmingly I underestimate hab by 1%)
and a handful up to 4%

That handful is from a Huge Packed* universe (900+ planets) across 10 races with a variety of immunities and hab settings.
Summary: 9390 planets, 843 errors, 1@-4%, 3@-3%, 5@-2%, 86@-1%, 748@+1%


* Note - I used Map2XY to create a solid block of planets and then sent a scout to the middle of the group from each of the 10 JoAT races to ensure that in 2401 I had complete universe scanning...
I could automate much of that process now (gen, export map, remap, open each turn in turn (then I have to move a ship on half of them) then gen and export all the planet reports and analyse...

I've also added a GetRacial subroutine to allow exporting of the racial statistics.

Those "large" errors by the way:
Diff Difference between calculated and Stars! value
Planet Name of planet
Perl What I calculated the value to be
Stars! What Stars! reported
Grav/TEmp/Rad Stars reported
G/T/Rclicks Perl calculated
Race Name of race
RGrav/Temp/Rad Perl calculated (from values in put from RW)
G/T/Rwidth As above

Diff	Planet	Perl	Stars!	Grav	Temp	Rad	Gclicks	Tclicks	Rclicks	Race	RGrav	RTemp	RRad	Gwidth	Twidth	Rwidth
-4	H&M	54	58%	0.15	136	33	6	84	33	M9	22	78	31	22	22	23
-3	Cepheus	97	100%	0.17	-160	10	9	10	10	M8	10	10	10	10	10	10
-3	Dwarte	43	46%	0.15	148	24	6	87	24	M9	22	78	31	22	22	23
-3	Tattoo	32	35%	0.15	64	42	6	66	42	M9	22	78	31	22	22	23
-2	98053	41	43%	0.17	172	26	9	93	26	M9	22	78	31	22	22	23
-2	Accord	16	18%	0.17	56	51	9	64	51	M9	22	78	31	22	22	23
-2	Accord	48	50%	0.17	56	51	9	64	51	M5	50	50	50	50	50	50
-2	New	29	31%	0.15	120	12	6	80	12	M9	22	78	31	22	22	23
-2	W..ight	54	56%	0.17	-8	48	9	48	48	M5	50	50	50	50	50	50


[Updated on: Fri, 12 April 2013 10:29]

Report message to a moderator

Re: Planet value calculation made easy! Fri, 12 April 2013 11:59 Go to previous messageGo to next message
craebild is currently offline craebild

 
Lieutenant

Messages: 568
Registered: December 2003
Location: Copenhagen, Denmark
All of those large errors have grav at values where two clicks reports the same value. It seems to me your Perl assumes the worst of the possible clicks, while Stars! presumably uses the actual click for the calculations.

All those +/-1% errors are probably differences in rounding during the calculations.

That is just my guess, of course.



Med venlig hilsen / Best regards / Mit freundlichen Grüßen
Christian Ræbild / Christian Raebild

Report message to a moderator

Re: Planet value calculation made easy! Fri, 12 April 2013 12:40 Go to previous messageGo to next message
XAPBob is currently offline XAPBob

 
Lt. Commander

Messages: 957
Registered: August 2012
I absolutely use the 'worst possible' assumption, and am confident that the grav is indeed the source of my errors - I *think* my racial grav clicks are corrected by being even widths...

It would be nice to kill the rounding errors, but transposing integer maths onto a dynamically typed language is a pain.

I hope the module can come in handy - it certainly makes short work of the calculations. I might pass in the racial hab to the main function as well - would allow easy comparisons of different race habs...

Report message to a moderator

Re: Planet value calculation made easy! Fri, 12 April 2013 17:42 Go to previous messageGo to previous message
m.a@stars is currently offline m.a@stars

 
Commander

Messages: 2765
Registered: October 2004
Location: Third star to the left
XAPBob wrote on Fri, 12 April 2013 18:40
I absolutely use the 'worst possible' assumption, and am confident that the grav is indeed the source of my errors - I *think* my racial grav clicks are corrected by being even widths...

Here's what my "planet value report" tool does to get the correct Grav "clicks" from the ambiguous values where the calculations and Stars! own datadump don't match:

    theHabValue = planetValueCalc(grav, parseInt(temp)/4+50, parseInt(rad));
    if (theHabValue!=ReportHab) {	// report mismatch?
      if (grav<11) {
	grav++;	//kludge. Not all hab combos need it :-?
	theHabValue = planetValueCalc(grav, parseInt(temp)/4+50, parseInt(rad));
      }



Quote:
I hope the module can come in handy - it certainly makes short work of the calculations. I might pass in the racial hab to the main function as well - would allow easy comparisons of different race habs...

That's more or less what my "planet value report" tool does to see what planets are better for what races, be they allied or enemy. Very Happy


[Updated on: Fri, 12 April 2013 17:42]




So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Previous Topic: Research
Next Topic: Ship Teleportation bug
Goto Forum:
  


Current Time: Wed May 01 23:37:16 EDT 2024