UEWBot / dipvis

Django-based visualiser for tournaments for the boardgame Diplomacy
GNU General Public License v3.0
7 stars 5 forks source link

fixed bug in _improve_fitness in game_seeder.py #307

Open jasonmastbaum opened 2 weeks ago

jasonmastbaum commented 2 weeks ago

I was poking around in the game seeding code and noticed that in _improve_fitness on lines 400-401 you're sampling the same list twice with replacement, so in a two board tournament it's going to pick the same game (g1 == g2) twice about 50% of the time the way you have it set up. I'm thinking wasting 50% of the fitness checks may have contributed to the wonky seeding results we saw at Skycon.

The only change in this pull request is switching that to sampling without replacement so that _improve_fitness never picks the same game as both g1 and g2.

jasonmastbaum commented 2 weeks ago

Looking at the failure on the automated checks I think it's just failing because games isn't populated unless you're using it against an active tournament?

====================================================================== ERROR: test_seed_games_and_powers_issues (tournament.test_game_seeder.GameSeederSetupTest)

Traceback (most recent call last): File "/home/runner/work/dipvis/dipvis/visualiser/tournament/test_game_seeder.py", line 611, in test_seed_games_and_powers_issues r = seeder.seed_games_and_powers() File "/home/runner/work/dipvis/dipvis/visualiser/tournament/game_seeder.py", line 538, in seed_games_and_powers games = self.seed_games(omitting_players, players_doubling_up) File "/home/runner/work/dipvis/dipvis/visualiser/tournament/game_seeder.py", line 584, in seed_games seedings.append(self._seed_games(omitting_players, File "/home/runner/work/dipvis/dipvis/visualiser/tournament/game_seeder.py", line 525, in _seed_games res, fitness = self._improve_fitness(res, include_these_games=(len(players_doubling_up) > 1)) File "/home/runner/work/dipvis/dipvis/visualiser/tournament/game_seeder.py", line 400, in _improve_fitness g1, g2 = random.sample(games,2) File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/random.py", line 449, in sample raise ValueError("Sample larger than population or is negative") ValueError: Sample larger than population or is negative