Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dep1engenharia opened this issue Aug 24, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@dep1engenharia
Copy link

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.

@dep1engenharia dep1engenharia added the bug Something isn't working label Aug 24, 2024
@dep1engenharia dep1engenharia changed the title [BUG] [BUG] Ship Construction Discrepancy: Fewer Ships Built Than Ordered When Building Large Quantities Aug 24, 2024
@lanedirt
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants