Atlantis-PBEM / Atlantis

Main Atlantis development Repository
GNU General Public License v2.0
53 stars 37 forks source link

Trade items in the market is kinda horrible to assign #188

Open jt-traub opened 4 months ago

jt-traub commented 4 months ago

There was a bug where if you had < 4 trade items it would infinite loop. That was reported in #54 and I implemented a slightly better fix in (add PR).

An even better solution would be

0) initialize all the buy/sell variables to -1 1) collect a random vector of all trade item ids 2) collect a second vector of references to the 2 sell and 2 buy variables. 3) Perform a random_shuffle on both vectors. 4) while both vectors have elements remaining, take one id and one reference and assign the id to the reference 5) repeat until one vector is empty and you have assigned as much as you can and faster than the iterative random assignment below.

valdisz commented 2 months ago

The current and proposed change has one big issue. Trade routes are random, too. This creates unbalanced scenarios when a lucky player gets a huge boost in the very important early stages of the game because he has several high-yield trade routes available.

A better algorithm would be to create trade routes first, taking into account city size and distance. Bigger cities would have more trade routes, and longer trade routes would yield bigger profits—all with the intent of making trade routes more homogenous.

jt-traub commented 2 months ago

Yeah.. this needs an entire re-think/rework.

I am not sure you want trade routes to be homogenous, which would imply that each and every city had exactly the same trade potential, but I think what you do want is 'fair distribution' of high-value routes so that they don't cluster.

I think one way to potentially solve for that would be to have trade goods be somewhat regional (ie, jewelry is much more likely to be sold in cities near mountains and wanted in cities with very few nearby mountains, etc). I think as we evolve into a more complex world-building structure, trade will be able to be (hopefully) factored into that better.

For instance, you see trade goods at production sites on the map, then you seed cities and cities are more likely to spring up around production sites, then you find a reasonable set of markets that want what is produced at those cities.

jt-traub commented 2 months ago

With the above stated, this issue was solely about better allocation under the existing system. I would be find changing this to be the more complex one, or opening a separate issue for that.