From 6603f4012e8049f06f0833ee780bf9f76ae9e12b Mon Sep 17 00:00:00 2001 From: Antoine Van Elstraete Date: Mon, 24 Jan 2022 23:14:17 +0100 Subject: [PATCH] Optimisations --- wgamesolv.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/wgamesolv.py b/wgamesolv.py index 85b3d1b..f894d70 100755 --- a/wgamesolv.py +++ b/wgamesolv.py @@ -3,6 +3,7 @@ import json import argparse +from random import shuffle def load_dict(dict_file): @@ -35,13 +36,15 @@ def firstTryFilter(mots, max_mots): ''' bestLetters = ['E', 'A', 'I', 'R', 'S', 'N', 'T', 'O', 'L', 'U'] bestWords = [] + shuffle(mots) + mots = mots[:100] for mot in mots: for bestLetter in bestLetters: if bestLetter in mot: bestWords.append(mot) bestWords = list(set(bestWords)) bestWords = noDouble(bestWords) # Autant maximiser les chances - bestWords = bestWords[0:max_mots] + bestWords = bestWords[:max_mots] return(bestWords) @@ -119,8 +122,7 @@ if __name__ == "__main__": '-fl', '--firstLetter', help='Première lettre', - default=False, - required=True + default=False ) parser.add_argument( '-nb', @@ -171,9 +173,16 @@ if __name__ == "__main__": liste = load_dict(args.dictionary) liste = resolv_len(liste, args.nbLetters) - liste = resolv_fl(liste, args.firstLetter) + if args.firstLetter: + liste = resolv_fl(liste, args.firstLetter) + if args.pattern: + liste = resolv_pattern(liste, args.pattern) if args.noDoubleLetters: liste = noDouble(liste) + if args.knownLetters: + liste = resolv_kl(liste, args.knownLetters) + if args.badLetters: + liste = resolv_bl(liste, args.badLetters) if args.firstTry: liste = firstTryFilter(liste, args.firstTry) if len(liste) == 1: @@ -183,12 +192,6 @@ if __name__ == "__main__": else: print("Hmmm... Je crois qu'on s'est perdu...") exit(0) - if args.knownLetters: - liste = resolv_kl(liste, args.knownLetters) - if args.badLetters: - liste = resolv_bl(liste, args.badLetters) - if args.pattern: - liste = resolv_pattern(liste, args.pattern) if len(liste) > 1: print(liste) print(f"Il y a {len(liste)} mots dans la liste")