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 json
|
||||||
import argparse
|
import argparse
|
||||||
|
from random import shuffle
|
||||||
|
|
||||||
|
|
||||||
def load_dict(dict_file):
|
def load_dict(dict_file):
|
||||||
@ -19,13 +20,9 @@ def noDouble(mots):
|
|||||||
# Fonction d'élimination de mots contenant plusieurs occurences de lettres
|
# Fonction d'élimination de mots contenant plusieurs occurences de lettres
|
||||||
ndList = []
|
ndList = []
|
||||||
for mot in mots:
|
for mot in mots:
|
||||||
llist = []
|
if len(list(mot)) == len(set(list(mot))):
|
||||||
for lettre in mot:
|
|
||||||
if lettre not in llist:
|
|
||||||
llist.append(lettre)
|
|
||||||
if len(mot) == len(llist):
|
|
||||||
ndList.append(mot)
|
ndList.append(mot)
|
||||||
return(ndList)
|
return ndList
|
||||||
|
|
||||||
|
|
||||||
def firstTryFilter(mots, max_mots):
|
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']
|
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 +118,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 +169,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 +188,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")
|
||||||
|
Reference in New Issue
Block a user