implement proper method to find feasible instances

This commit is contained in:
Maximilian Keßler 2023-03-13 13:22:54 +01:00
parent a40361b7f3
commit 5c06ef7887
Signed by: max
GPG Key ID: BCC5A619923C0BA5

View File

@ -42,46 +42,36 @@ def get_decks_of_seeds():
def update_trivially_feasible_games(): def update_trivially_feasible_games():
cur = conn.cursor() cur = conn.cursor()
for var in VARIANTS: for var in VARIANTS:
cur.execute("SELECT COUNT(*) FROM seeds WHERE variant_id = (%s) AND feasible is null", (var['id'],)) cur.execute("SELECT seed FROM seeds WHERE variant_id = (%s) AND feasible is null", (var['id'],))
num_seeds = cur.fetchone()[0] seeds = cur.fetchall()
cur.execute("SELECT seed, id FROM games WHERE score = (%s) AND variant_id = (%s) ORDER BY seed;", (5 * len(var['suits']), var['id'])) print('Checking variant {} (id {}), found {} seeds to check...'.format(var['name'], var['id'], len(seeds)))
res = cur.fetchall()
print('Checking variant {} (id {}), found {} seeds with {} max-score games to check...'.format(var['name'], var['id'], num_seeds, len(res))) with alive_bar(total=len(seeds), title='{} ({})'.format(var['name'], var['id'])) as bar:
cur_seed = None for (seed,) in seeds:
seed_finished = False cur.execute("SELECT id, deck_plays, one_extra_card, one_less_card, all_or_nothing "
with alive_bar(num_seeds) as bar: "FROM games WHERE score = (%s) AND seed = (%s) ORDER BY id;",
for (seed, game_id) in res: (5 * len(var['suits']), seed)
if seed_finished and cur_seed == seed: )
print('skipping further game of seed {}'.format(seed)) res = cur.fetchall()
continue print("Checking seed {}: {:3} results".format(seed, len(res)))
if cur_seed != seed: for (game_id, a, b, c, d) in res:
bar() if None in [a,b,c,d]:
cur_seed = seed print(' Game {} not found in database, exporting...'.format(game_id))
seed_finished = False succ, valid = export_game(game_id)
cur.execute("SELECT deck_plays, one_extra_card, one_less_card, all_or_nothing FROM games WHERE id = (%s)", (game_id,)) if not succ:
cheat_options = cur.fetchall()[0] print('Error exporting game {}.'.format(game_id))
valid = None continue
if None in cheat_options: else:
print('Game {} not found in database, exporting...'.format(game_id)) valid = not any([a,b,c,d])
succ, valid = export_game(game_id) print(' Game {} already in database, valid: {}'.format(game_id, valid))
if not succ: if valid:
print('Error exporting game {}.'.format(game_id)) print('Seed {:9} (variant {} / {}) found to be feasible via game {:6}'.format(seed, var['id'], var['name'], game_id))
continue cur.execute("UPDATE seeds SET feasible = (%s) WHERE seed = (%s)", (True, seed))
else: conn.commit()
valid = not any(cheat_options) break
print('Game {} already in database, valid: {}'.format(game_id, valid)) else:
if valid: print(' Cheaty game found')
print('Seed {:9} (variant {} / {}) found to be feasible via game {:6}'.format(seed, var['id'], var['name'], game_id)) bar()
cur.execute("UPDATE seeds SET feasible = (%s) WHERE seed = (%s)", (True, seed))
conn.commit()
seed_finished = True
else:
print('Cheaty game found')
return
for (seed,) in cur:
cur2.execute("UPDATE seeds SET feasible=TRUE WHERE seed=(%s)", (seed,))
print("Seed {} found to be feasible")
conn.commit()
update_trivially_feasible_games() update_trivially_feasible_games()
exit(0) exit(0)