Re: [Freecol-developers] Fixing issues with production on tiles

2022-10-12 Thread Stian Grenborgen
Hi!

I have been looking into the correct tile production formula, and have arrived 
at this result after verifying a lot of different outputs:

normal production =
  (
base production
+ additive expert production
+ additive resource production
+ additive expert resource production
  ) 
  * multiplier resource
  * multiplier expert
  
  
tile improvement production =
  additive tile improvements (plow, road, minor river, major river)  
  * multiplier expert
   
colony efficiency bonus =
  MAX(rebel bonus number, (
rebel bonus number
* multiplier resource
* IF(expert at producing goodstype, 2, 1)
  ))

total production =
  normal production
  + tile improvement production
  + colony efficiency bonus


Note that the colony efficiency bonus gets multiplied even for expert types 
that only have additive bonuses (Expert Farmer).

The current production numbers in FreeCol deviates rather heavily from this 
formula, and I have built an acceptance test based on the above formula and 
verified a few hundred production variations in the original game as well.


Best wishes,
Stian Grenborgen



___
From: Stian Grenborgen
Sent: 03 September 2022 10:51
    
Hi again,

I have found that getPotentialProduction/getMaximumPotential for 
Tile/BuildingType produces different results than the actual production 
(ColonyTile/Building) even when the results should be the same.

When looking into the code I have noticed all sorts of issues with modifiers 
not being applied. Some of these issues only affect methods used by the AI, 
while other issues affect the actual production. For example, an expert farmer 
never gets the additional  (expert) bonus from the grain resource.

I think the best solution for these problems is having a separate class for 
calculating production/consumption -- and that this class gets the list of 
modifiers for the colony and player as parameters. This way, we can use the 
same code everywhere (potential,  maximum and actual production) and 
Tile+ColonyTile+Building+Colony gets simplified.

The main problem with the rewrite is lack of tests for the correct tile 
production values ... so it would be really helpful if someone would make 
tables/lists with the correct values for each combination of:
* Tile type
* Resource
* Tile improvements (plow, minor river, major river and/or road)
* Worker type (unattended, petty criminal, indentured servant, colonist, 
convert, expert)
* Liberty bonuses (-2, -1, 0, +1, +2)

That's lots of combinations and numbers ... but only having a complete set for 
one resource (grain) would help immensely. Please do tell if you can help make 
these tables/lists :-)


Best wishes,
Stian Grenborgen

___
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers


Re: [Freecol-developers] Fixing issues with production on tiles

2022-09-24 Thread Stian Grenborgen
> From: Lone_Wolf via Freecol-developers 
> 
> Sent: 07 September 2022 10:47
>
> [...]
>
> I strongly suggest to look at the code used for production in buildings .
>
> The data the formulae used there are based on is found in bug tickets 
> created by me.
>
> Analysis is also found in those tickets and mpope took care of the 
> actual coding.
>
> You will find lots of weird things / exceptions and inconsistenties in 
> the formulae, but all have been verified thoroughly .
>
> The data that was collected for outdoors production sofar has strong 
> indications they are worse and may reveal dependencies that are 
> illogical and mentioned nowhere in col1 documentation .

Yes, I have used the building tests continuously while working on the code. I 
have also considered unifying the code for building and colony tile production, 
but currently it's less complicated to just have two different implementation 
of the calculations (BuildingProductionCalculator and TileProductionCalculator):

https://github.com/FreeCol/freecol/commit/3bdda582bd5ed78bd586f31304db868ecb558c09


I have also fixed an interesting bug that prevented experts from getting the 
extra production bonus on resources:

https://github.com/FreeCol/freecol/commit/2bdcec888d191692eb44d26425f804807d36f9e7


I'm not done doing the rewrite. The ProductionCache needs to be updated as well 
... and a lot of old production methods should just be removed.


Best wishes,
Stian Grenborgen

___
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers


Re: [Freecol-developers] Fixing issues with production on tiles

2022-09-24 Thread Stian Grenborgen
> From: Sébastien Fauvel 
> Sent: 07 September 2022 00:33
>
> To quickly create non-regression tests on cases with high combinatorics,
> I use approvaltests. You execute code with all cases and for each, you write
> the value in a file. You just have to check that this file is always the same
> after a test execution to make the test passed.
>
> I made an example you can see here:
> https://github.com/sfauvel/freecol/blob/test_with_approvals/test/src/net/sf/freecol/common/model/ColonyProductionApprovalsTest.java
>
> [...]
>
> I'm not sure about all the cases you want to test and how to generate them
> but If you think this approach could help, I can explain in more detail or
> complete those tests to cover more cases..

Sorry for the late reply -- I thought I had already responded, but obviously 
not.

The problem is that it's not entirely clear what the actual production should 
be in the classic ruleset, and just looking at the current production (and 
approving it) will probably not discover any more bugs with the current 
implementation. However, using approval tests for regression testing might be a 
really good idea. 

A solution like this is especially interesting when making changes to the 
specification (mods), since it can be used to both quickly determine if a 
change has the desired outcome and if any regressions have happened.

There's already a documentation generator for the rules 
(GenerateDocumentation). We could use this approach for making the 
documentation better as well.

For example, we could make a utility for both generating the documentation and 
verifying the specification changes:

  verifyRulesAndDocument --output=build/my-mod data/default data/rules/classic 
data/mods/my-mod
  mv build/my-mod docs/my-mod
  verifyRulesAndDocument --expected=docs/my-mod --output=build/my-mod 
data/default data/rules/classic data/mods/my-mod

The tool would take the TC, rule and a list of mods as input ... and use that 
for generating the documentation + files with the outputs we want to verify. 
These files can then later be used as the expected values.

We can also make a list of differences highlighting the changes that happens 
after applying the mod. That is something that might even be interesting to 
display in the mod selection dialog.

Anyone who wants to work on a solution like this?


Best wishes,
Stian Grenborgen

___
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers


Re: [Freecol-developers] Fixing issues with production on tiles

2022-09-07 Thread Lone_Wolf via Freecol-developers

On 03-09-2022 10:51, Stian Grenborgen wrote:

When looking into the code I have noticed all sorts of issues with modifiers 
not being applied. Some of these issues only affect methods used by the AI, 
while other issues affect the actual production. For example, an expert farmer 
never gets the additional (expert) bonus from the grain resource.

I think the best solution for these problems is having a separate class for 
calculating production/consumption -- and that this class gets the list of 
modifiers for the colony and player as parameters. This way, we can use the 
same code everywhere (potential, maximum and actual production) and 
Tile+ColonyTile+Building+Colony gets simplified.



I strongly suggest to look at the code used for production in buildings .

The data the formulae used there are based on is found in bug tickets 
created by me.


Analysis is also found in those tickets and mpope took care of the 
actual coding.



You will find lots of weird things / exceptions and inconsistenties in 
the formulae, but all have been verified thoroughly .


The data that was collected for outdoors production sofar has strong 
indications they are worse and may reveal dependencies that are 
illogical and mentioned nowhere in col1 documentation .



Lone_Wolf



___
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers


Re: [Freecol-developers] Fixing issues with production on tiles

2022-09-06 Thread Sébastien Fauvel
HI,

To quickly create non-regression tests on cases with high combinatorics, I
use approvaltests .
You execute code with all cases and for each, you write the value in a
file. You just have to check that this file is always the same after a test
execution to make the test passed.

I made an example you can see here:
https://github.com/sfauvel/freecol/blob/test_with_approvals/test/src/net/sf/freecol/common/model/ColonyProductionApprovalsTest.java
There is 2 tests:
One is a very basic test (testGetPotentialProduction) that produces a text
file with raw data (testGetPotentialProduction.approved.txt
)
. Simple to produce but not easy to interpret cases.
The second one is more complicated to generate but it creates an asciidoc
file that makes a non regression reference and can be used as documentation
when converted to HTML. Many cases can be represented in a concise way. You
can see the result here:
testGetPotentialProductionInReadableTable.approved.adoc
.


I'm not sure about all the cases you want to test and how to generate them
but If you think this approach could help, I can explain in more detail or
complete those tests to cover more cases..

Best regards
*Sébastien Fauvel*


Le sam. 3 sept. 2022 à 10:51, Stian Grenborgen <
stian...@student.matnat.uio.no> a écrit :

> Hi again,
>
> I have found that getPotentialProduction/getMaximumPotential for
> Tile/BuildingType produces different results than the actual production
> (ColonyTile/Building) even when the results should be the same.
>
> When looking into the code I have noticed all sorts of issues with
> modifiers not being applied. Some of these issues only affect methods used
> by the AI, while other issues affect the actual production. For example, an
> expert farmer never gets the additional (expert) bonus from the grain
> resource.
>
> I think the best solution for these problems is having a separate class
> for calculating production/consumption -- and that this class gets the list
> of modifiers for the colony and player as parameters. This way, we can use
> the same code everywhere (potential, maximum and actual production) and
> Tile+ColonyTile+Building+Colony gets simplified.
>
> The main problem with the rewrite is lack of tests for the correct tile
> production values ... so it would be really helpful if someone would make
> tables/lists with the correct values for each combination of:
> * Tile type
> * Resource
> * Tile improvements (plow, minor river, major river and/or road)
> * Worker type (unattended, petty criminal, indentured servant, colonist,
> convert, expert)
> * Liberty bonuses (-2, -1, 0, +1, +2)
>
> That's lots of combinations and numbers ... but only having a complete set
> for one resource (grain) would help immensely. Please do tell if you can
> help make these tables/lists :-)
>
>
> Best wishes,
> Stian Grenborgen
>
> ___
> Freecol-developers mailing list
> Freecol-developers@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/freecol-developers
>
___
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers


Re: [Freecol-developers] Fixing issues with production on tiles

2022-09-04 Thread Michael T. Pope
On Sat, 3 Sep 2022 08:51:07 +
Stian Grenborgen  wrote:
> The main problem with the rewrite is lack of tests for the correct tile 
> production values ...

I thought we had *some* tests... TileTest exists.

Cheers,
Mike Pope


pgpO1uAYBsNlm.pgp
Description: OpenPGP digital signature
___
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers


Re: [Freecol-developers] Fixing issues with production on tiles

2022-09-04 Thread Michael T. Pope
On Sat, 3 Sep 2022 08:51:07 +
Stian Grenborgen  wrote:
> The main problem with the rewrite is lack of tests for the correct tile 
> production values ... 

There is/was effort to determine the Col1 values, but as you note, it is a
lot of work.  See:
https://sourceforge.net/p/freecol/wiki/WWC1D%20-%20resource%20output%20v2/
and all the pages with a "WWC1D - resource" prefix visible at:
https://sourceforge.net/p/freecol/wiki/browse_pages/

Not knowing what is right has rather dampened enthusiasm for work in this
area.

Cheers,
Mike Pope


pgpsJBNN3piTH.pgp
Description: OpenPGP digital signature
___
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers


[Freecol-developers] Fixing issues with production on tiles

2022-09-03 Thread Stian Grenborgen
Hi again,

I have found that getPotentialProduction/getMaximumPotential for 
Tile/BuildingType produces different results than the actual production 
(ColonyTile/Building) even when the results should be the same.

When looking into the code I have noticed all sorts of issues with modifiers 
not being applied. Some of these issues only affect methods used by the AI, 
while other issues affect the actual production. For example, an expert farmer 
never gets the additional (expert) bonus from the grain resource.

I think the best solution for these problems is having a separate class for 
calculating production/consumption -- and that this class gets the list of 
modifiers for the colony and player as parameters. This way, we can use the 
same code everywhere (potential, maximum and actual production) and 
Tile+ColonyTile+Building+Colony gets simplified.

The main problem with the rewrite is lack of tests for the correct tile 
production values ... so it would be really helpful if someone would make 
tables/lists with the correct values for each combination of:
* Tile type
* Resource
* Tile improvements (plow, minor river, major river and/or road)
* Worker type (unattended, petty criminal, indentured servant, colonist, 
convert, expert)
* Liberty bonuses (-2, -1, 0, +1, +2)

That's lots of combinations and numbers ... but only having a complete set for 
one resource (grain) would help immensely. Please do tell if you can help make 
these tables/lists :-)


Best wishes,
Stian Grenborgen

___
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers