Nettoyage
This commit is contained in:
parent
e4b517168a
commit
fc93178303
39
wgamesolv.py
39
wgamesolv.py
@ -6,12 +6,12 @@ import argparse
|
||||
|
||||
|
||||
def load_dict(dict_file):
|
||||
try :
|
||||
try:
|
||||
with open(dict_file, "r") as dico:
|
||||
liste = json.load(dico)
|
||||
return liste
|
||||
except:
|
||||
print("Impossible d'ouvrir le fichier" + fp)
|
||||
except Exception as error:
|
||||
print(f"Impossible d'ouvrir le fichier {dict_file} : {error}")
|
||||
exit(2)
|
||||
|
||||
|
||||
@ -20,13 +20,14 @@ def noDouble(mots):
|
||||
ndList = []
|
||||
for mot in mots:
|
||||
llist = []
|
||||
for l in mot:
|
||||
if not l in llist:
|
||||
llist.append(l)
|
||||
for lettre in mot:
|
||||
if lettre not in llist:
|
||||
llist.append(lettre)
|
||||
if len(mot) == len(llist):
|
||||
ndList.append(mot)
|
||||
return(ndList)
|
||||
|
||||
|
||||
def firstTryFilter(mots, max_mots):
|
||||
'''
|
||||
First Try : sélectionne des mots ayant des chances de valider ou invalider
|
||||
@ -71,19 +72,12 @@ def resolv_pattern(liste, pattern):
|
||||
liste = list(set(liste))
|
||||
return liste
|
||||
|
||||
#if pattern:
|
||||
# patternCount = len(pattern) - pattern.count(".")
|
||||
# for mot in goodLen:
|
||||
# patternEval = 0
|
||||
# for l in range(len(mot)):
|
||||
# if mot[l] == pattern[l]:
|
||||
# patternEval += 1
|
||||
# if patternEval == patternCount :
|
||||
# patternFilter.append(mot)
|
||||
#
|
||||
|
||||
def resolv_kl(liste, lettres):
|
||||
# Known Letters : élimination des mots ne comprenant pas les lettres validées (hors pattern)
|
||||
'''
|
||||
Known Letters : élimination des mots ne comprenant pas
|
||||
les lettres validées (hors pattern)
|
||||
'''
|
||||
lettres = list(set(list(lettres)))
|
||||
MotsRestants = []
|
||||
for mot in liste:
|
||||
@ -93,7 +87,10 @@ def resolv_kl(liste, lettres):
|
||||
|
||||
|
||||
def resolv_bl(liste, lettres):
|
||||
# Bad Letters : élimination des mots contenant des lettres invalidées (hors pattern)
|
||||
'''
|
||||
Bad Letters : élimination des mots contenant
|
||||
des lettres invalidées (hors pattern)
|
||||
'''
|
||||
lettres = list(set(list(lettres)))
|
||||
MotsSuppr = []
|
||||
for mot in liste:
|
||||
@ -103,7 +100,7 @@ def resolv_bl(liste, lettres):
|
||||
for mot in MotsSuppr:
|
||||
try:
|
||||
liste.pop(liste.index(mot))
|
||||
except:
|
||||
except ValueError:
|
||||
pass
|
||||
return liste
|
||||
|
||||
@ -167,11 +164,11 @@ if __name__ == "__main__":
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
if args.pattern and args.nbLetters and len(args.pattern) != args.nbLetters:
|
||||
print("Tu as merdé ta pattern petit scarabé !")
|
||||
exit(2)
|
||||
|
||||
|
||||
liste = load_dict(args.dictionary)
|
||||
liste = resolv_len(liste, args.nbLetters)
|
||||
liste = resolv_fl(liste, args.firstLetter)
|
||||
|
Loading…
Reference in New Issue
Block a user