Home World Forum
Stars! AutoHost web forums

Jump to Stars! AutoHost


 
 
Home » Stars! Clones, Extensions, Modding » FreeStars » some questions about coding
Re: some questions about coding Sat, 12 March 2005 07:45 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
Hi,

ConstB wrote on Fri, 11 March 2005 18:02


I used these to generate some kind of value tables to look at, just was too lazy to invent backward translation.



No problem, I spent a joyful 15 minutes reversing your functions to my needs. The power of integer math Smile

And, at least for the 1500+ planets present in the reports I had on hand, your functions work as advertised. Cool

Summarizing:
- Clicks to Grav calculation: exact
- Grav to Clicks calculation: exact for unambiguous values of Grav. (code available on request)
- Hab value calculation: exact for a wide variety of cases, including CA and 1WW (immunities not tested). No ambiguous values of grav present in sample.

And all of these without time-consuming "higher math"! Twisted Evil I think I'll update the HabCalc tool soon. Very Happy

So, kudos to the "Russian reverse engineer" for revealing another beautiful instance of the Jeff's craft.

C U @ the Board!


[Updated on: Sat, 12 March 2005 12:04]




So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: some questions about coding Sat, 12 March 2005 08:19 Go to previous messageGo to next message
ConstB is currently offline ConstB

 
Crewman 1st Class

Messages: 27
Registered: March 2005
Location: Tomsk, Russia
That's great. But I'm still unable to reimplement player advantage points calculation algo. I'm missing good 16-bit debugger. WinDBG works only with 32-bit progs. I found old Borland's Turbo Debugger, but it doesn't operate properly. It hangs on a breakpoint. I feel ruined. I corrected fourth bug in my reversed code, but it's still doesn't work as expected. If you are interested in playing with this wrong code, I can either post it here (528 lines) or send it by e-mail.

Report message to a moderator

Re: some questions about coding Sat, 12 March 2005 09:19 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
Hi,

ConstB wrote on Sat, 12 March 2005 14:19

I feel ruined. I corrected fourth bug in my reversed code, but it's still doesn't work as expected. If you are interested in playing with this wrong code, I can either post it here (528 lines) or send it by e-mail.


Don't feel bad. That monster has defeated many bright people. Sad Most of us believe that "algorithm" to be One Big Kludge, countless times tweaked by the Jeffs, sworn enemies of simplicity Wink

While I bet I'm not the only one interested in playing with your code, I'm not sure if this board can handle so many lines. Confused As a first step, you can send me a zipped copy in a PM, or in an email message (address to be found in your PM box) Assembly code would be very welcome. Very Happy

Cheers,




[Updated on: Sat, 12 March 2005 09:24]




So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: some questions about coding Mon, 14 March 2005 02:52 Go to previous messageGo to next message
Madman is currently offline Madman

 
Officer Cadet 1st Year

Messages: 228
Registered: November 2003
Location: New Zealand
ConstB wrote on Thu, 10 March 2005 06:08

Hmm.. In my humble opinion exceptions help avoid repeating this huge error reporting code, making it shorter and cleaner. Throwing is like another way of returning from function unambiguously treated as an error condition by calling function.

I'd like to second that comment Smile In addition, using exceptions make the code much more readable for others, by separating the normal case and the error cases - to understand most of the code, you can look through the 'normal' case code.

I develop software professionally, and curse loudly whenever I'm forced to use a language that doesn't support exceptions.

Report message to a moderator

Re: some questions about coding Thu, 17 March 2005 12:48 Go to previous messageGo to next message
ConstB is currently offline ConstB

 
Crewman 1st Class

Messages: 27
Registered: March 2005
Location: Tomsk, Russia
just checked out new copy of freestars. wow, the work goes on! and now it even reports errors! but it's marked as for debugging.

and it looks like you guys have mixed up player in-game messages from server and messages regarding turn processing itself. :-(

if one has turn generation automated how does he distinguish what error has happened? all he gets is -1 return code. not too much.

And consider rewriting code like in Battle.cpp
long** Battle::StartX = NULL;
long** Battle::StartY = NULL;
and
StartX = new long*[TheGame->NumberPlayers() - 1];
StartY = new long*[TheGame->NumberPlayers() - 1];
for (unsigned int i = 0; i < TheGame->NumberPlayers() - 1; ++i) {
    StartX[i] = new long[i+2];
    StartY[i] = new long[i+2];
    for (unsigned int j = 0; j < i+2; ++j) {
        StartX[i][j] = 1;
        StartY[i][j] = 1;
    }
}
with something less horrible. maybe vector<vector<long> > ?

and seems like you're still addicted to use of global variables. if this is inevitable create them statically! see, you create one Game and one Galaxy object and then delete them. why not make them static and let compiler generate all creation and destruction code?

and once again: use smart pointers. avoid code like:
Planet::~Planet()
{
    deque<ProdOrder *>::iterator iter;
    for (iter = mProductionQ.begin(); iter != mProductionQ.end(); ++iter)
        delete *iter;
}

all you have to do is replace deque<ProdOrder *> mProductionQ with something like deque<SmartPtr<ProdOrder> > mProductionQ where smartptr is a most appropriate implementation. (my favourite is very flexible one from Loki library loki-lib.sf.net).

and about design - I don't see any relation between Player and Race. In stars.exe race info is made a part of player structure. and I find it right!..

Report message to a moderator

Re: some questions about coding Thu, 17 March 2005 18:30 Go to previous messageGo to next message
Marduk is currently offline Marduk

 
Ensign

Messages: 345
Registered: January 2003
Location: Dayton, OH
ConstB wrote on Fri, 11 March 2005 05:18

planetValuePoints = sqrt((double)planetValuePoints/3)+0.9;



I don't think it is sqrt(3) - with a sample of 11,244 green habs, I got my best results dividing by 1.724. I presume some sort of rounding issue was at work. Here are the number of systems where my hab calculation was off by 1%, substituting different values for sqrt(3):

1.720 - 4391
1.721 - 4060
1.722 - 3768
1.723 - 3380
1.724 - 3068
1.725 - 3170
1.726 - 3195
1.727 - 3208
1.728 - 3229
1.729 - 3286
1.730 - 3334
1.731 - 3448
1.732 - 3521
root3 - 3528

I don't have time for it tonight, but tomorrow I'll check my formula against yours and see if it is the same - at a glance it looks to be slightly different, but you still might want to try dividing by something other than root 3.

The 11244 samples I got by using a JoaT race with all three habs at maximum width, making all systems green. No TT, as I wanted to limit my starting terraforming. I'll try again with TT at some point, since there are several more levels of terraforming available that way.

I set the race loose in a Huge, Dense galaxy, allowing only enough tech to get the fuel mizer, and then scanning every system. Once that was done, I saved a .P file - that gave me the base hab values and the hab after Grav3 and Temp3 terraforming (what I got with the fuel mizer). After that I advanced one terraforming milestone at a time, saving a .P file at each step. Since each file's terraformed hab values gave me another set of samples to check my formulas against, it was more or less like scanning another Huge, Dense galaxy each time.

Report message to a moderator

Re: some questions about coding Thu, 17 March 2005 18:56 Go to previous messageGo to next message
PricklyPea is currently offline PricklyPea

 
Lieutenant

Messages: 534
Registered: February 2005
Marduk wrote on Thu, 17 March 2005 18:30

ConstB wrote on Fri, 11 March 2005 05:18

planetValuePoints = sqrt((double)planetValuePoints/3)+0.9;



I don't think it is sqrt(3) - with a sample of 11,244 green habs, I got my best results dividing by 1.724. I presume some sort of rounding issue was at work.


The actual implementation is a double precision multiplication by 0.33333etc. and then sqrt. Not sure if this gives rise to differences in what you've implemented.

Report message to a moderator

Re: some questions about coding Fri, 18 March 2005 07:24 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
Marduk wrote on Fri, 18 March 2005 00:30

Since each file's terraformed hab values gave me another set of samples to check my formulas against, it was more or less like scanning another Huge, Dense galaxy each time.


If I understand correctly, terraforming capability will matter only in settled planets... So, did you colonize/terraform the whole huge galaxy? Shocked



So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: some questions about coding Fri, 18 March 2005 19:48 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
PricklyPear wrote on Fri, 18 March 2005 00:56

The actual implementation is a double precision multiplication by 0.33333etc. and then sqrt. Not sure if this gives rise to differences in what you've implemented.



Interesting. So not *everything* is integer math out there... Twisted Evil

But after testing about 35000 green, red and yellow planets (from 25 different races/hab schemes, including terraforming, immunities, 1WW, widebands, and whatnot), ConstB's original formula (and my newest reinterpretation, to be found in The Academy) remains exact. Cool So, I say sqrt(3) stays.

{added latest latest test figures}

{a note on accuracy: planets whose grav values are ambiguous can give inexact results. For those I've coded a rematch with their other possible grav value. So far, all rematches have resulted in the correct values as stated in the planet report. Twisted Evil }


[Updated on: Tue, 22 March 2005 07:05]




So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: some questions about coding Fri, 18 March 2005 22:25 Go to previous messageGo to next message
PricklyPea is currently offline PricklyPea

 
Lieutenant

Messages: 534
Registered: February 2005
there's actually a hell of a lot of floating point stuff in there. i hate reversing FP code Evil or Very Mad

Report message to a moderator

Re: some questions about coding Sat, 19 March 2005 20:50 Go to previous messageGo to next message
Marduk is currently offline Marduk

 
Ensign

Messages: 345
Registered: January 2003
Location: Dayton, OH
m.a@stars wrote on Fri, 18 March 2005 07:24

Marduk wrote on Fri, 18 March 2005 00:30

Since each file's terraformed hab values gave me another set of samples to check my formulas against, it was more or less like scanning another Huge, Dense galaxy each time.


If I understand correctly, terraforming capability will matter only in settled planets... So, did you colonize/terraform the whole huge galaxy? Shocked


In the planet report, there is a second planet value for complete (according to current tech) terraforming. It's the parenthetical hab value you see when examining a system. Assuming that is correct, and it seems to be, it gives you another hab value for a different set of system environment values.

Report message to a moderator

Re: some questions about coding Sun, 20 March 2005 06:20 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
Hi,

Marduk wrote on Sun, 20 March 2005 02:50


In the planet report, there is a second planet value for complete (according to current tech) terraforming. It's the parenthetical hab value you see when examining a system. Assuming that is correct, and it seems to be, it gives you another hab value for a different set of system environment values.


Sounds good. But I find it faster to just force gen a huge/packed with 16 races and transfer around a bunch of well-placed Elephant galleons to get each player's report on the whole galaxy. Allows lazy me to test a wider variety of hab settings on the same planets without the need to track everyone's terraf levels. Shocked

I guess I'll eventually add your idea to my testing just to squeeze another 15000 test points out of the same testbed Smile

{terraforming added for those reports where I know the race's terraforming tech. All (15000+) results exact so far Cool }


[Updated on: Tue, 22 March 2005 06:58]




So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: some questions about coding Sun, 20 March 2005 06:25 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
PricklyPear wrote on Sat, 19 March 2005 04:25

there's actually a hell of a lot of floating point stuff in there. i hate reversing FP code Evil or Very Mad


I remember back in the days you could keep track (aka paper-based lookup table) of the most frequently used FP operations and library calls, thus allowing less traumatic "reading"... If the debugger was smart enough to not translate FP data into code! Razz



So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: some questions about coding Sun, 20 March 2005 18:56 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
Hi,

I finally managed to write a more readable/simpler version of the planet value algorithm. I posted it in The Academy for all to enjoy/demolish:

http://starsautohost.org/sahforum/index.php?t=msg&th=229 9&start=0&rid=625&S=fdfca492d0e72c55f919e79b9d3f df95

Of particular interest to Freestars can be that my 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"...

C U @ the Board!

{added explanation about symmetry}


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




So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: some questions about coding Sun, 19 February 2006 22:12 Go to previous messageGo to next message
LEit is currently offline LEit

 
Lt. Commander

Messages: 879
Registered: April 2003
Location: CT
ConstB wrote on Thu, 17 March 2005 12:48

and about design - I don't see any relation between Player and Race. In stars.exe race info is made a part of player structure. and I find it right!..


Again, almost a year later...
class Player : public Race {

A Player is a Race, so all the race info is in the player class.


The code in Battle.cpp is very preliminary (still is). Battles arn't done, and I just wanted to get something going. I do intend to use something better then that bit of code, ideally getting starting positions out of the rules file. I'm not sure how to specify starting positions in XML though (other then just listing them all).

Smart pointers and static globals: Both seem like good ideas. I've never worried too much about losing pointers, because I'm pretty good at keeping track of them, and pretty good at tracking them down if I do lose them. However, being smart up front is safer. I'll have to learn about smart pointers, I understand the basics, it's the details I need to understand.



- LEit

Report message to a moderator

Re: some questions about coding Mon, 20 February 2006 04:48 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
LEit wrote on Mon, 20 February 2006 04:12

The code in Battle.cpp is very preliminary (still is). Battles arn't done, and I just wanted to get something going. I do intend to use something better then that bit of code, ideally getting starting positions out of the rules file. I'm not sure how to specify starting positions in XML though (other then just listing them all).


If only I had the time, I'd love to work on the Battlesystem. As it is, I have given some thought to it, but haven't actually coded a thing. Sad

Having to pull Freestars files from CVS by hand doesn't help a whole lot, either. Razz

About starting positions: seems to me there can be some math behind them, perhaps akin to splitting a pie, but interleaving the race positions. Although just listing them all sounds easier. Wink


[Updated on: Mon, 20 February 2006 08:54]




So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: some questions about coding Mon, 20 February 2006 06:03 Go to previous messageGo to next message
Kotk

 
Commander

Messages: 1227
Registered: May 2003
m.a@stars wrote on Mon, 20 February 2006 11:48

Having to pull Freestars files from CVS by hand doesn't help a whole lot, either. Razz


How you pull by hand? CVS at sourceforge is slow ... but seems to work. For example anonymous access:
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/freestars login 
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/freestars co -P freestars

And ... done. Rolling Eyes

Report message to a moderator

Re: some questions about coding Mon, 20 February 2006 08: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
Kotk wrote on Mon, 20 February 2006 12:03

m.a@stars wrote on Mon, 20 February 2006 11:48

Having to pull Freestars files from CVS by hand doesn't help a whole lot, either. Razz


How you pull by hand? CVS at sourceforge is slow ... but seems to work. For example anonymous access:
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/freestars login 
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/freestars co -P freestars

And ... done. Rolling Eyes


I guess those are CVS commands? As in, you have a CVS client? That's a luxury I don't have. Sad

Worse, my old VC++ compiler is not getting younger... :-/


[Updated on: Mon, 20 February 2006 09:55]




So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: some questions about coding Mon, 20 February 2006 10:49 Go to previous messageGo to next message
Kotk

 
Commander

Messages: 1227
Registered: May 2003
Hmm ... why you dont have it? Surprised CVS is not a luxury. Confused3 Its public thing. Open-source-free-to-download. Nod Download WinCVS or something if you want a CVS client with GUI.

Report message to a moderator

Re: some questions about coding Mon, 20 February 2006 11:21 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
Kotk wrote on Mon, 20 February 2006 16:49

Hmm ... why you dont have it? Surprised CVS is not a luxury. Confused3 Its public thing. Open-source-free-to-download. Nod Download WinCVS or something if you want a CVS client with GUI.


Long story short: My 'Net-enabled PC (AKA ol' heap-o-junk) has neither space nor power to run it. Hadn't had a powerful enough motive to solve the matter, with so few hobby projects at home. Now, with Freestars beckoning, things may change. Wink

By the by, in a cursory review of battle.cpp I haven't found damage calculations as discussed in
http://starsautohost.org/sahforum/index.php?t=msg&th=206 5&rid=625&S=971cf48d1cf3c677d6bdba01acc6555e#msg_176 22
Perhaps they're there but somewhat disguised? Sherlock



So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: some questions about coding Mon, 20 February 2006 12:08 Go to previous messageGo to next message
PricklyPea is currently offline PricklyPea

 
Lieutenant

Messages: 534
Registered: February 2005
It's also very old and buggy. CVS was the reason that ALL the GNU servers were 0wned by hackers a few years back.

Report message to a moderator

Re: some questions about coding Mon, 20 February 2006 15:58 Go to previous messageGo to next message
Kotk

 
Commander

Messages: 1227
Registered: May 2003
Use that command line CVS thing if your hardware is weak. You dont need to run CVS server (to have local repository on your computer) just connect as client to sourceforge.

[email

m.a@stars[/email] wrote on Mon, 20 February 2006 18:21]By the by, in a cursory review of battle.cpp I haven't found damage calculations ... Sherlock

The battle.cpp deals with other aspects of battle like moving and targeting at the moment. Battle::Shootslot does nothing (contents commented out).

Maybe torpedo/missile damage logic given in the thread you pointed at is worth to implement ... but 1/500 hull damage minimum will go i hope. Wink


[Updated on: Mon, 20 February 2006 16:56]

Report message to a moderator

Re: some questions about coding Mon, 20 February 2006 16:31 Go to previous messageGo to next message
Kotk

 
Commander

Messages: 1227
Registered: May 2003
PricklyPea wrote on Mon, 20 February 2006 19:08

It's also very old and buggy. CVS was the reason that ALL the GNU servers were 0wned by hackers a few years back.

Sourceforge has free CVS repository, freestars code is in there and so what is alternative constructive suggestion? Smile

Old... sure. There are ~ 5 releases of a CVS per year ... bugs in CVS are fixed. It gets better and better with each patch. Wink

Report message to a moderator

Re: some questions about coding Tue, 21 February 2006 05: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
Kotk wrote on Mon, 20 February 2006 21:58

Use that command line CVS thing if your hardware is weak. You dont need to run CVS server (to have local repository on your computer) just connect as client to sourceforge.


*sigh* I wouldn't bet on the old heap-o-junk being able to run even a streamlined CVS client on top of the antivirus, the firewall, the anti-spyware and windoze itself. Embarassed I only need to refresh my copies of the data/test/rules files now, anyway.

Quote:

The battle.cpp deals with other aspects of battle like moving and targeting at the moment. Battle::Shootslot does nothing (contents commented out).

Maybe torpedo/missile damage logic given in the thread you pointed at is worth to implement ... but 1/500 hull damage minimum will go i hope. Wink


So, I had guessed correctly on what that code was [not] doing. Is nobody working with it? I'd say even the barest running version would be a significant leap forward, being able to destroy things and count coup and all that. Cool

About the "hull damage minimum", I'd say it is something for a couple versions down the road... Wink



So many Stars, so few Missiles!

In space no one can hear you scheme! Deal

Report message to a moderator

Re: some questions about coding Tue, 21 February 2006 13:31 Go to previous messageGo to previous message
LEit is currently offline LEit

 
Lt. Commander

Messages: 879
Registered: April 2003
Location: CT
Battle.cpp is still very preliminary.

But, the 1/500 min damage thing is something that should be fixed. There is no reason to keep it (other then to abuse a bug) and keeping it would require more work then getting rid of it.



- LEit

Report message to a moderator

Previous Topic: Summary of Math?
Next Topic: Need web hosting for Race Wizard
Goto Forum:
  


Current Time: Fri May 03 11:04:44 EDT 2024