Optimisations
This commit is contained in:
parent
fc93178303
commit
6603f4012e
23
wgamesolv.py
23
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")
|
||||
|
Loading…
Reference in New Issue
Block a user