@@ -429,39 +429,41 @@ async def run_battle(self, fight: FightHandler, config: Config, min_size: int, u
429429 """
430430
431431 def sizes (size : int , max_size : int ) -> Iterable [int ]:
432+ if size > max_size :
433+ return
432434 counter = count (1 )
433- size = max (size , min_size )
434435 while size < max_size :
435436 yield size
436437 size += next (counter ) ** config .exponent
437438 yield max_size
438439
439440 note = "Starting battle..."
440- for _ in range (config .rounds ):
441- max_size = config .maximum_size
441+ for _i in range (config .rounds ):
442+ lower_bound = min_size
443+ upper_bound = config .maximum_size
442444 self .results .append (0 )
443445 gen_errors = 0
444- while self .results [- 1 ] < max_size :
445- for size in sizes (self .results [- 1 ] + 1 , max_size ):
446- ui .update_battle_data (self .UiData (reached = self .results , cap = max_size , note = note ))
446+ while lower_bound <= upper_bound :
447+ lower_bound = max (lower_bound , self .results [- 1 ] + 1 )
448+ for size in sizes (lower_bound , upper_bound ):
449+ ui .update_battle_data (self .UiData (reached = self .results , cap = upper_bound , note = note ))
447450 result = await fight .run (size )
448451 if result .generator .error and config .max_generator_errors != "unlimited" :
449452 gen_errors += 1
450453 if gen_errors >= config .max_generator_errors :
451- self .results [- 1 ] = max_size
454+ self .results [- 1 ] = upper_bound
452455 note = f"Generator failed { gen_errors } times in a row, solver wins round by default!"
453456 break
454457 else :
455458 gen_errors = 0
456459 if result .score < config .minimum_score :
457- max_size = size - 1
460+ upper_bound = size - 1
458461 note = "Solver didn't achieve the needed score, resetting the cap"
459462 break
460463 else :
461464 note = "Solver was successful, increasing the cap"
462465 self .results [- 1 ] = size
463- else :
464- note = "Cap reached, resetting instance size"
466+ note = "Cap reached, resetting instance size"
465467
466468 def score (self ) -> float :
467469 """Averages the highest instance size reached in each round."""
0 commit comments