lanedirt / OGameX

Open-source OGame redesign clone built with Laravel 11.x.
https://main.ogamex.dev
MIT License
30 stars 14 forks source link

[BUG] Ship Construction Discrepancy: Fewer Ships Built Than Ordered When Building Large Quantities #307

Open dep1engenharia opened 3 weeks ago

dep1engenharia commented 3 weeks ago

Describe the bug When building a large quantity of ships (e.g., 1000 units), the final amount of ships constructed does not match the requested amount. For example, when ordering 1000 Heavy Fighters, only 995 were built. Similarly, when ordering 1000 Cruisers, only 987 were built. This discrepancy occurs consistently across different types of ships.

To Reproduce Steps to reproduce the behavior:

  1. Go to the shipyard or the relevant ship construction page.
  2. Select any type of ship (e.g., Heavy Fighter, Cruiser).
  3. Enter a large quantity for construction, such as 1000 units.
  4. Confirm the construction order and wait for the ships to be built.
  5. Observe the final number of ships constructed and compare it with the requested amount.

Expected behavior The expected behavior is that the exact number of ships requested for construction should be built and reflected in the fleet count. For example, if 1000 Heavy Fighters are ordered, 1000 Heavy Fighters should be built.

Screenshots image

Additional context This issue seems to affect various types of ships and is consistently reproducible when ordering large quantities. It may be related to a bug in the construction logic or resource allocation. This discrepancy could impact gameplay, especially in situations where precise fleet numbers are crucial.

lanedirt commented 2 weeks ago

Hi @dep1engenharia,

Thank you for the interesting bug report!

I haven't been able to reproduce this issue myself yet, but I've only tested the system with small quantities of 10-20 units at a time.

How the current system works technically: For larger ship/defense build queue orders, these orders are gradually processed if the planet is updated in the meantime. For example, if you order 1,000 units that would take 1 hour to build in total, and then you update the planet (by accessing any page) after 10 minutes, the system will divide the total time by the elapsed time (60 minutes divided by 10 minutes) and add the corresponding number of units to the planet.

Based on your bug report, I suspect there might be some mathematical rounding issues with the existing logic, resulting in fewer than the requested number of units being built.

We already have automated tests for the build queue logic, but these tests also built around lower unit counts and did not reveal any errors up to this point. I think it will be a good idea to add more tests with larger unit counts to see if we can reproduce the error that way.

Thank you again for reporting this. I'll be looking into it in the coming days!

dep1engenharia commented 2 weeks ago

Hi @lanedirt

Based on your bug report, I suspect there might be some mathematical rounding issues with the existing logic, resulting in fewer than the requested number of units being built.

I agree with your point, and I think similarly. This seems to be related to some mathematical issues in the algorithm.

Thank you.

lanedirt commented 2 weeks ago

Update: after some more investigation I came to the conclusion that the problems you noticed are not caused by rounding issues in the algorithm but instead are caused by so-called "Race conditions" that can occur under special circumstances.

I have made some additional fixes in #321 which should further minimize the chance that these race conditions occur. In order to fully eliminate these race conditions I have also opened up #322 to track higher-level architectural rewrites that will most likely be required.

With the latest fixes that have just been merged I believe you should see some improvements in stability. If you come across any more examples where there are discrepancies please keep reporting them by updating this issue or creating new issues. This will help me keep track of whether the fixes so far are doing their job.

dep1engenharia commented 2 weeks ago

Sounds like a plan! This week I have some time free. And I will spend sometime on the project/game, so that I can fully understand it.

If something..., i'll keep you posted.