Home » Stars! 2.6/7 » The Bar » Stars 3
| | |
Re: Stars 3 |
Fri, 06 June 2014 18:19 |
|
mrvan | | Officer Cadet 1st Year | Messages: 220
Registered: May 2014 | |
|
I added mining and a get_resources function.
My direct todo-list:
- implement production of planetary installations
- setup an 'integration test'
Questions on current code:
- As always, please check my unit tests and algorithms
- To mimic stars! behaviour, I had to set factory resources to round up production. Since stars! seems to round down everywhere, this strikes me as quite odd, and the freestars code (Planet.cpp +888) also just uses integer math, and even seems to round down factory and population production separately.
Test case: start a new game as humanoids but with factory efficiency, produce two factories, end turn. You now have 28.7k pop and 12 factories, which should produce 28.7 + 12*.9 = 39.5 resources, which matches the 39 displayed by stars!
End turn again. You now have 33k pop and 12 factories. This should yield 33 + 12*.9 = 43.8 resources, but stars! reports 44.
So, it seems that pop production is rounded down, but factory production is rounded up.
This is matched on a new planet: If I colonize a new planet (ie no factories), I get 1 resource for pop up to 1900, 2 up to 2900, etc; so it's rounded down with a minimum of 1. If I build a single factory (which should yield .9 resources) I get 2 resources for population up to 1900. With 10k pop and 8 factories, I get 18 resources, while 10+8*.9=17.2.
The relevant Planet.cpp code seems to not capture this:
Res = facts * GetOwner()->FactoryRate() / 10;
Res += pop / GetOwner()->PopEfficiency();
Since res is long, it is rounded down after computing factory resources and again after computing population resources. So, for the 28.7k pop + 12 factories you would get
Res = 12 * 9 / 10 = 10.8 --> 10 (long)
Res += 28700 / 1000 -> Res += 28.7 -> Res = 38 (compared to stars! reporting 39)
So, am I correct that factory production is rounded up (and hence is the freestars implementation inconsistent with stars!?)
Questions for production:
- Is tech gain processed immediately, i.e. does order of production matter such that if planet 3 researches enough for a new tech, planet 4 produces with reduced costs due to miniaturizaion? If so, I assume planets are processed in order of planet ID?
- Am I correct that if you cannot finish a (non-autoqueue) item due to lack of minerals, you produce N% such that the lowest mineral is depleted, and leftover resources go to research?
[Updated on: Fri, 06 June 2014 18:21] Report message to a moderator
|
|
|
Re: Stars 3 |
Sat, 07 June 2014 04:38 |
|
m.a@stars | | Commander | Messages: 2765
Registered: October 2004 Location: Third star to the left | |
|
mrvan wrote on Sat, 07 June 2014 00:19I added mining and a get_resources function.
The mining code doesn't seem to include mineral depletion? Also, are ARs and remoteminers handled?
Question: there's a way to "profile" python, I hope, and so check if a particular implementation is particularly fast or slow, yes?
Quote:So, am I correct that factory production is rounded up (and hence is the freestars implementation inconsistent with stars!?)
Pretty likely, as recently seen in this Academy thread (toward the end).
Freestars coders did their own tests (as comments show in some places) but this one might have escaped them.
Quote:Questions for production:
- Is tech gain processed immediately, i.e. does order of production matter such that if planet 3 researches enough for a new tech, planet 4 produces with reduced costs due to miniaturizaion? If so, I assume planets are processed in order of planet ID?
- Am I correct that if you cannot finish a (non-autoqueue) item due to lack of minerals, you produce N% such that the lowest mineral is depleted, and leftover resources go to research?
In theory, yes and yes.
[Updated on: Sat, 07 June 2014 04:41]
So many Stars, so few Missiles!
In space no one can hear you scheme! Report message to a moderator
|
|
|
Re: Stars 3 |
Sat, 07 June 2014 05:18 |
|
mrvan | | Officer Cadet 1st Year | Messages: 220
Registered: May 2014 | |
|
@M.A. Thanks
I'm assuming remote mining is done in the fleet WP0 tasks, right (plus AR inhabited WP1)
Indeed, mining is quite simplistic now, I've added the "limitations". My current push is to get to a "playable" version, ie a version where you can play a baseline testbedding game, and hopefully convince some people to start using it for testbedding.
I looked at the freestars code for the depletion, and I found a lot of strange code in Planet::GetMiningVelocity that never seems to be called. Can anyone enlighten me on that?
The freestars code for mineral depletion seems to be:
mMinMined[mineral] += mines;
long minesper = Rules::GetConstant("MineralDecayFactor") / mMinConc[mineral] / mMinConc[mineral];
if (mMinMined[mineral] > minesper) {
mMinConc[mineral] -= mMinMined[mineral] / minesper;
if (mMinConc[mineral] < Rules::GetConstant("MineralMinimum"))
mMinConc[mineral] = Rules::GetConstant("MineralMinimum");
mMinMined[mineral] %= minesper;
}
So, the amount of mines needed to deplete a mineral is given by MineralDecayFactor=1500000 / conc^2. For conc 100, this is 150.
Then, there seems to be a persistent counter mMinMined to keep track of "fractional depletion", ie if the decay factor is 150 and we have 250 mines, it is depleted by 1 and the counter is set to 250 % 150 = 100. Next turn, minesper is 153, and we've "mined" 250 plus 100 remainder = 350, so we deplete by 2 and counter is now 350 % 153 = 44.
For remote mining, it seems that a mining module with max 18kt is simply processed as 18 mines at mining efficiency 10, so the 18 max is not actually the max if concentration > 100. Is that correct? Also, what happens if a player mines a planet inhabited by a different AR?
Edit:
Quote:Question: there's a way to "profile" python, I hope, and so check if a particular implementation is particularly fast or slow, yes?
Sure. I usually do old fashioned profiling (record time, call function A N times, print time difference), which is very easy to do if you have separate functions, as in the current engine setup. You can also do more advanced profiling, which requires a bit more effort to set up, but can show you where the bottlenecks are in a complex program. See https://docs.python.org/3/library/profile.html
[Updated on: Sat, 07 June 2014 05:23] Report message to a moderator
|
|
| | |
Re: Stars 3 |
Sat, 07 June 2014 07:20 |
|
mrvan | | Officer Cadet 1st Year | Messages: 220
Registered: May 2014 | |
|
I've added some simplistic production code.
At the moment, you can only build factories and mines (and actually only factories are tested), and there is no fractional completion; but I ran out of stars time for the moment
What I find strange is how fractional production works in stars! I would have expected 50% to mean that 50% of resources and minerals are paid, so completing it costs 50% of resources, 50% of iron etc.
However, a very simplistic test on a new (red) world shows something subtly different. I set factory cost to 9 and planetary production to 3 to see how rounding is handled. Planet has 0 mines and so mining rate 0.
Turn 0: germanium 13
Turn 1: germanium 12kt, factory complete 43%.
Turn 2: germanium 10kt, factory complete 76%
Turn 3: germanium 9kt, factory complete
What I don't understand is where the 43% comes from. The planet only has production 3, so it can produce 33% of resources. It has paid 1kt germanium, so 25% of germanium. How does that add up to 43%?
I could also imagine that it records "cost remaining" instead of %complete, but the recent academy thread suggests otherwise and anyway if remaining costs are 6 out of 9 resources and 3 out of 4 germanium I still don't see where to get 43%.
Another question: How does it know to pay 1 germanium in the 1st and 3d turn of production and 2 in the second, if all it records is % complete?
Edit: setting research tax to 100% and queuing another factory (completion time: never) gives 10% done after end turn without any germanium consumed. However, queuing a ship in the main starbase with 100% tax gives 0% done???
Edit2: building a cost 5 mine on a 2 production world gives completion percentages 59% - 99% - done. With zero production it shows 19%. So it seems that actual production complete makes sense in both factory and mine case, with a "display bonus" of 10 and 19%, respectively. So the remaining questions are:
- what is the function or reason of the display bonus?
- how are fractional mineral completions dealt with? I guess a possibility is that it calculates mineral cost at new% - old% and pays the difference, e.g. for the factory case:
Turn 1: 0% -> 33%. Germanium cost for 0%=0, for 33%=1.333=1, so pay 1
Turn 2: 33% -> 67%. Germanium cost for 33%=1, for 67%=2.667=3, so pay 2
Turn 3: 67% -> 100%. Cost 4-3 = 1
However, a remaining question is how it gets to 67% from 33% plus 3 production. I guess it calculates new percentage as percentage given total invested resources, so after second round invested resources are 3 (33% of 9) plus 3 (current production) = 6, which is 6/9=66.6667->67 by rounding to nearest instead of rounding down?
In a sense, this means that invested resources are recalculated from the percentage, added to available resources, and that is used to calculate new percentage. Does that make sense?
[Updated on: Sat, 07 June 2014 07:46] Report message to a moderator
|
|
| |
Re: Stars 3 |
Sat, 07 June 2014 08:07 |
|
m.a@stars | | Commander | Messages: 2765
Registered: October 2004 Location: Third star to the left | |
|
mrvan wrote on Sat, 07 June 2014 11:18I'm assuming remote mining is done in the fleet WP0 tasks, right (plus AR inhabited WP1)
Well, as far as anyone knows, remotes mine after WP1 colonization and before Production, so I guess they could be handled that way (and non-SD minelayers too?)
Quote:Indeed, mining is quite simplistic now, I've added the "limitations". My current push is to get to a "playable" version, ie a version where you can play a baseline testbedding game, and hopefully convince some people to start using it for testbedding.
Yay!
Quote:I looked at the freestars code for the depletion, and I found a lot of strange code in Planet::GetMiningVelocity that never seems to be called. Can anyone enlighten me on that?
Hmmmm, it looks weird, but some ppl talk about "mine equivalents" when studying depletion, and that same concept applies to remote miners, so perhaps it was cleverly coded that way. I wonder if they did tests confirming their approach.
Quote:Also, what happens if a player mines a planet inhabited by a different AR?
All dimensions explode, likely.
Quote:I usually do old fashioned profiling (record time, call function A N times, print time difference), which is very easy to do if you have separate functions, as in the current engine setup.
Heh, that's how I usually do it too, though some times it's hard to tell what code performs best or why something is slow.
So many Stars, so few Missiles!
In space no one can hear you scheme! Report message to a moderator
|
|
| | | |
Re: Stars 3 |
Sat, 07 June 2014 09:00 |
|
mrvan | | Officer Cadet 1st Year | Messages: 220
Registered: May 2014 | |
|
m.a@stars wrote on Sat, 07 June 2014 08:18mrvan wrote on Sat, 07 June 2014 13:20In a sense, this means that invested resources are recalculated from the percentage, added to available resources, and that is used to calculate new percentage. Does that make sense?
As much sense as plenty other "wrinkles" all over the code. I wonder if your "3 Res" planet is actually 3, or something close to 3 that's nudging the equations around.
I did a limited inspection of ProdOrder.cpp (around line 349) and this indeed seems to be how freestars does it, as in, they record partial production for resources+minerals separately in a Cost object, and add those resoruces/minerals to the available stockpile.
I'm inclined to skip this for now, and move to ship production, at first limited to preset designs, and then move over to a first attempt at an HTML5 client.
Good things to do for contributors, in order of increasing complexity:
- add mineral depletion
- add partial production
- add defenses and terraforming
- add research
Any takers?
Report message to a moderator
|
|
| |
Re: Stars 3 |
Sat, 07 June 2014 09:33 |
|
mrvan | | Officer Cadet 1st Year | Messages: 220
Registered: May 2014 | |
|
Cool. No worries, I also don't have any time left today, although I might try to setup the integration test I've been talking about later today so we can test consistency between the various modules...
Let me know (here or on chat) if you need any help cloning the repo and getting the unit tests up and running.
[Updated on: Sat, 07 June 2014 09:48] Report message to a moderator
|
|
|
Re: Stars 3 |
Sat, 07 June 2014 18:39 |
|
mrvan | | Officer Cadet 1st Year | Messages: 220
Registered: May 2014 | |
|
I've added an integration test. It basically consists of running a complete turn (as far as defined) and checking the results.
The purpose of this test is to make sure that (1) the universe/orders respresentations are consistent between the different engine modules, and (2) that any (future) subtle interactions between modules can be tested. It is not intended to be a feature complete check of every module (that is what the unit tests are for).
As secondary benefit is that it is an example of a compelte universe/orders representation.
When editing/creating engine modules, please update/create both the relevant unit test and the integration test!
[Updated on: Sat, 07 June 2014 18:39] Report message to a moderator
|
|
| | | | | | | |
Goto Forum:
Current Time: Tue Apr 23 16:31:49 EDT 2024
|