Compare commits
2 Commits
v1.0
...
25669da340
Author | SHA1 | Date | |
---|---|---|---|
25669da340
|
|||
6603f4012e |
31
wgamesolv.py
31
wgamesolv.py
@ -3,6 +3,7 @@
|
||||
|
||||
import json
|
||||
import argparse
|
||||
from random import shuffle
|
||||
|
||||
|
||||
def load_dict(dict_file):
|
||||
@ -19,13 +20,9 @@ def noDouble(mots):
|
||||
# Fonction d'élimination de mots contenant plusieurs occurences de lettres
|
||||
ndList = []
|
||||
for mot in mots:
|
||||
llist = []
|
||||
for lettre in mot:
|
||||
if lettre not in llist:
|
||||
llist.append(lettre)
|
||||
if len(mot) == len(llist):
|
||||
if len(list(mot)) == len(set(list(mot))):
|
||||
ndList.append(mot)
|
||||
return(ndList)
|
||||
return ndList
|
||||
|
||||
|
||||
def firstTryFilter(mots, max_mots):
|
||||
@ -35,13 +32,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 +118,7 @@ if __name__ == "__main__":
|
||||
'-fl',
|
||||
'--firstLetter',
|
||||
help='Première lettre',
|
||||
default=False,
|
||||
required=True
|
||||
default=False
|
||||
)
|
||||
parser.add_argument(
|
||||
'-nb',
|
||||
@ -171,9 +169,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 +188,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")
|
||||
|
Reference in New Issue
Block a user