Possible RNG bug

Post any bumps you find on the road to galactic domination.

Moderators: Makail, Erinys, ddub

Post Reply
User avatar
willdieh
Posts: 234
Joined: Mon May 08, 2017 4:41 pm

Possible RNG bug

Post by willdieh » Fri Jan 04, 2019 4:24 am

Hi!

I wasn't sure if I could/should still post this, given the uncertain status of this game in 2019, but I thought I'd give it a shot. I've found what I believe to be a bug in the random number generator (RNG) implementation, at least with the initial faction tech style selections. Looks like the RNG is being instanced too quickly for the seed to change, resulting in identical results where random results are desired.

This can be reproduced on the dev console by running a large 8 faction map (eg, Large Disk) with only Human players. Humans have 40% odds at most Tech Styles and thus should show the most variety between separate faction instantiations. Instead we see something like this:

Code: Select all

TEST 1 - 8 Player Map, all SolForce (Human)
ai  Turn 1 (1): {BallisticWeapons,ShieldTechnology,Torpedos,EnergyWeapons,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (18); 
	  >>> POL_FTL_Economics
ai  Turn 1 (2): {IndustrialTechnology} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (7); X/POL_FTL_Economics (7); X/BIO_Environmental_Tailoring (20); 
	  >>> POL_FTL_Economics
ai  Turn 1 (3): {IndustrialTechnology} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (18); 
	  >>> POL_FTL_Economics
ai  Turn 1 (4): {IndustrialTechnology} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (18); 
	  >>> POL_FTL_Economics
ai  Turn 1 (5): {IndustrialTechnology} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (18); 
	  >>> POL_FTL_Economics
ai  Turn 1 (6): {EnergyWeapons,ShieldTechnology,Torpedos,EnergyWeapons,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (18); 
	  >>> POL_FTL_Economics
ai  Turn 1 (7): {EnergyWeapons,ShieldTechnology,Torpedos,EnergyWeapons,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (18); 
	  >>> POL_FTL_Economics
ai  Turn 1 (8): {EnergyWeapons,ShieldTechnology,Torpedos,EnergyWeapons,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (18); 
	  >>> POL_FTL_Economics
	  
TEST 2 - 8 Player Map, all SolForce (Human)	  
ai  Turn 1 (1): {EnergyWeapons,BioTechnology} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (8); 
	  >>> POL_FTL_Economics
ai  Turn 1 (2): {EnergyWeapons,IndustrialTechnology,Torpedos,EnergyWeapons,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (18); 
	  >>> POL_FTL_Economics
ai  Turn 1 (3): {EnergyWeapons,IndustrialTechnology,Torpedos,EnergyWeapons,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (18); 
	  >>> POL_FTL_Economics
ai  Turn 1 (4): {EnergyWeapons,IndustrialTechnology,Torpedos,EnergyWeapons,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (5); X/POL_FTL_Economics (5); X/BIO_Environmental_Tailoring (16); 
	  >>> POL_FTL_Economics
ai  Turn 1 (5): {EnergyWeapons,IndustrialTechnology,Torpedos,EnergyWeapons,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (18); 
	  >>> POL_FTL_Economics
ai  Turn 1 (6): {EnergyWeapons,IndustrialTechnology,Torpedos,EnergyWeapons,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (7); X/POL_FTL_Economics (7); X/BIO_Environmental_Tailoring (22); 
	  >>> POL_FTL_Economics
ai  Turn 1 (7): {EnergyWeapons,IndustrialTechnology,Torpedos,EnergyWeapons,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (18); 
	  >>> POL_FTL_Economics
ai  Turn 1 (8): {EnergyWeapons,IndustrialTechnology,Torpedos,EnergyWeapons,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (18); 
	  >>> POL_FTL_Economics

TEST 3 - 8 Player Map, all SolForce (Human)
ai  Turn 1 (1): {IndustrialTechnology,Torpedos,EnergyWeapons,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (7); X/POL_FTL_Economics (7); X/BIO_Environmental_Tailoring (20); 
	  >>> POL_FTL_Economics
ai  Turn 1 (2): {EnergyWeapons,ShieldTechnology,Torpedos,EnergyWeapons,WarheadTechnology} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (18); 
	  >>> BIO_Environmental_Tailoring
ai  Turn 1 (3): {EnergyWeapons,ShieldTechnology,Torpedos,EnergyWeapons,WarheadTechnology} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (16); 
	  >>> BIO_Environmental_Tailoring
ai  Turn 1 (4): {BallisticWeapons,ShieldTechnology,BioTechnology,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (8); 
	  >>> BIO_Environmental_Tailoring
ai  Turn 1 (5): {BallisticWeapons,ShieldTechnology,BioTechnology,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (7); X/POL_FTL_Economics (7); X/BIO_Environmental_Tailoring (10); 
	  >>> POL_FTL_Economics
ai  Turn 1 (6): {BallisticWeapons,ShieldTechnology,BioTechnology,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (9); 
	  >>> POL_FTL_Economics
ai  Turn 1 (7): {BallisticWeapons,ShieldTechnology,BioTechnology,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (7); X/POL_FTL_Economics (7); X/BIO_Environmental_Tailoring (10); 
	  >>> POL_FTL_Economics
ai  Turn 1 (8): {BallisticWeapons,ShieldTechnology,BioTechnology,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/POL_FTL_Economics (6); X/POL_FTL_Economics (6); X/BIO_Environmental_Tailoring (9); 
	  >>> POL_FTL_Economics

NEW GAME (restart application) - 8 Player Map, all SolForce (Human)
[ai] Turn 1 (1): {ShieldTechnology,BioTechnology,RiderTechnology,Psionics} (phase 0) X/EXPANDING prospects: X/IND_Reflective (4); X/IND_Reflective (4); X/POL_FTL_Economics (7);  
	  >>> IND_Reflective
[ai] Turn 1 (2): {IndustrialTechnology,Torpedos,EnergyWeapons,WarheadTechnology} (phase 0) X/EXPANDING prospects: X/IND_Reflective (1); X/IND_Reflective (1); X/POL_FTL_Economics (6);  
	  >>> POL_FTL_Economics
[ai] Turn 1 (3): {IndustrialTechnology,Torpedos,EnergyWeapons,WarheadTechnology} (phase 0) X/EXPANDING prospects: X/IND_Reflective (1); X/IND_Reflective (1); X/POL_FTL_Economics (6); 
	  >>> POL_FTL_Economics
[ai] Turn 1 (4): {IndustrialTechnology,Torpedos,EnergyWeapons,WarheadTechnology} (phase 0) X/EXPANDING prospects: X/IND_Reflective (1); X/IND_Reflective (1); X/POL_FTL_Economics (6);  
	  >>> POL_FTL_Economics
[ai] Turn 1 (5): {IndustrialTechnology,Torpedos,EnergyWeapons,WarheadTechnology} (phase 0) X/EXPANDING prospects: X/IND_Reflective (2); X/IND_Reflective (2); X/POL_FTL_Economics (7);  
	  >>> POL_FTL_Economics
[ai] Turn 1 (6): {IndustrialTechnology,Torpedos,EnergyWeapons,WarheadTechnology} (phase 0) X/EXPANDING prospects: X/IND_Reflective (2); X/IND_Reflective (2); X/POL_FTL_Economics (7);  
	  >>> POL_FTL_Economics
[ai] Turn 1 (7): {IndustrialTechnology,Torpedos,EnergyWeapons,WarheadTechnology} (phase 0) X/EXPANDING prospects: X/IND_Reflective (1); X/IND_Reflective (1); X/POL_FTL_Economics (6);  
	  >>> IND_Reflective
[ai] Turn 1 (8): {WarheadTechnology} (phase 0) X/EXPANDING prospects: X/IND_Reflective (3); X/IND_Reflective (3); X/POL_FTL_Economics (6);  
	  >>> IND_Reflective
 
While there is what seems like one and occasionally two RNG reseeds between evaluations, the repeated assignment of identical tech styles for different players is clear. We would instead expect to see considerable variation between the human factions.

These results can be replicated with any race however. You will see matching tech styles for all factions of that race as each race will be evaluated with the same RNG seed.

I only mention this as it might be indicative of a larger scale issue with how RNGs are used in the game. Microsoft has the following recommendations about using System.Random within tight loops (such as one would expect to see in the above results):
Initializing two random number generators in a tight loop or in rapid succession creates two random number generators that can produce identical sequences of random numbers. In most cases, this is not the developer's intent and can lead to performance issues, because instantiating and initializing a random number generator is a relatively expensive process.

Both to improve performance and to avoid inadvertently creating separate random number generators that generate identical numeric sequences, we recommend that you create one Random object to generate many random numbers over time, instead of creating new Random objects to generate one random number.
https://docs.microsoft.com/en-us/dotnet ... 2#Multiple

A fix might be as easy as introducing a simple wait loop around the Random call or as complex as rewriting how the RNG is accessed betwen classes via a single instantiation (as recommended by Microsoft).

Sorry for the long post. I realize resources are probably not available to investigate this issue, but as a fellow programmer and one of those who still enjoys playing this gem, I hope this information might prove useful. I came across this bug while trying to improve the AI and am happy to assist in any way I can to further that goal.

Thanks!
William
log-20190103195347.zip
(AI Debug Profile, Verbose Log)
You do not have the required permissions to view the files attached to this post.

ZedF
Board Ninja
Board Ninja
Posts: 12575
Joined: Sun Aug 27, 2006 7:13 pm

Re: Possible RNG bug

Post by ZedF » Fri Jan 04, 2019 6:09 am

Might be more useful as a tip for future development rather than a potential bug fix. Don't think Paradox is likely to request/fund any SotS2 updates for their property.
Zed's TARs (sample):
Fractious Allies -- Hiver vs. Hiver, with allies
Who Let The Bugs Out -- Hiver vs. Tarka and Zuul
Tarka Ascendant -- Tarka vs. Hiver and Zuul

Strategy & Tactics Forum Archive -- More posts on strategy, tactics, and TARs

User avatar
willdieh
Posts: 234
Joined: Mon May 08, 2017 4:41 pm

Re: Possible RNG bug

Post by willdieh » Sat Jan 05, 2019 6:57 am

Most likely, but I thought I'd give it a shot. Doesn't hurt to try. I could be completely wrong. Perhaps it's supposed to operate this way.

:)

William

Post Reply

Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 4 guests