Optimisations
This commit is contained in:
parent
fc93178303
commit
6603f4012e
23
wgamesolv.py
23
wgamesolv.py
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
|
from random import shuffle
|
||||||
|
|
||||||
|
|
||||||
def load_dict(dict_file):
|
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']
|
bestLetters = ['E', 'A', 'I', 'R', 'S', 'N', 'T', 'O', 'L', 'U']
|
||||||
bestWords = []
|
bestWords = []
|
||||||
|
shuffle(mots)
|
||||||
|
mots = mots[:100]
|
||||||
for mot in mots:
|
for mot in mots:
|
||||||
for bestLetter in bestLetters:
|
for bestLetter in bestLetters:
|
||||||
if bestLetter in mot:
|
if bestLetter in mot:
|
||||||
bestWords.append(mot)
|
bestWords.append(mot)
|
||||||
bestWords = list(set(bestWords))
|
bestWords = list(set(bestWords))
|
||||||
bestWords = noDouble(bestWords) # Autant maximiser les chances
|
bestWords = noDouble(bestWords) # Autant maximiser les chances
|
||||||
bestWords = bestWords[0:max_mots]
|
bestWords = bestWords[:max_mots]
|
||||||
return(bestWords)
|
return(bestWords)
|
||||||
|
|
||||||
|
|
||||||
@ -119,8 +122,7 @@ if __name__ == "__main__":
|
|||||||
'-fl',
|
'-fl',
|
||||||
'--firstLetter',
|
'--firstLetter',
|
||||||
help='Première lettre',
|
help='Première lettre',
|
||||||
default=False,
|
default=False
|
||||||
required=True
|
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-nb',
|
'-nb',
|
||||||
@ -171,9 +173,16 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
liste = load_dict(args.dictionary)
|
liste = load_dict(args.dictionary)
|
||||||
liste = resolv_len(liste, args.nbLetters)
|
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:
|
if args.noDoubleLetters:
|
||||||
liste = noDouble(liste)
|
liste = noDouble(liste)
|
||||||
|
if args.knownLetters:
|
||||||
|
liste = resolv_kl(liste, args.knownLetters)
|
||||||
|
if args.badLetters:
|
||||||
|
liste = resolv_bl(liste, args.badLetters)
|
||||||
if args.firstTry:
|
if args.firstTry:
|
||||||
liste = firstTryFilter(liste, args.firstTry)
|
liste = firstTryFilter(liste, args.firstTry)
|
||||||
if len(liste) == 1:
|
if len(liste) == 1:
|
||||||
@ -183,12 +192,6 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
print("Hmmm... Je crois qu'on s'est perdu...")
|
print("Hmmm... Je crois qu'on s'est perdu...")
|
||||||
exit(0)
|
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:
|
if len(liste) > 1:
|
||||||
print(liste)
|
print(liste)
|
||||||
print(f"Il y a {len(liste)} mots dans la liste")
|
print(f"Il y a {len(liste)} mots dans la liste")
|
||||||
|
Loading…
Reference in New Issue
Block a user