Fonction "Pattern"
This commit is contained in:
parent
e2452c1434
commit
e4b517168a
49
wgamesolv.py
49
wgamesolv.py
@ -43,21 +43,6 @@ def firstTryFilter(mots, max_mots):
|
|||||||
bestWords = bestWords[0:max_mots]
|
bestWords = bestWords[0:max_mots]
|
||||||
return(bestWords)
|
return(bestWords)
|
||||||
|
|
||||||
# Fonction de comparaison des lettres d'un mot, avec celle de la pattern
|
|
||||||
# Plus nécessaire actuellement mais peut être dans une prochaine vie
|
|
||||||
'''
|
|
||||||
def patternCheck(pattern, mot, l):
|
|
||||||
goodPosCounter = 0
|
|
||||||
for pos in range(len(pattern)):
|
|
||||||
print("Checking : " + l + "against : " + pattern[pos] + " and " + mot[pos])
|
|
||||||
if pattern[pos] == l and mot[pos] == l:
|
|
||||||
goodPosCounter +=1
|
|
||||||
print("checked")
|
|
||||||
if goodPosCounter == pattern.count(l):
|
|
||||||
return(0)
|
|
||||||
else:
|
|
||||||
return(1)
|
|
||||||
'''
|
|
||||||
|
|
||||||
def resolv_fl(liste, firstletter):
|
def resolv_fl(liste, firstletter):
|
||||||
# On ne garde que les mots qui commence par FirstLetter
|
# On ne garde que les mots qui commence par FirstLetter
|
||||||
@ -69,7 +54,23 @@ def resolv_len(liste, lenght):
|
|||||||
return [mot for mot in liste if len(mot) == lenght]
|
return [mot for mot in liste if len(mot) == lenght]
|
||||||
|
|
||||||
|
|
||||||
# Pattern : élimination des mots ne satisfaisant pas la pattern
|
def resolv_pattern(liste, pattern):
|
||||||
|
# Pattern : élimination des mots ne satisfaisant pas la pattern
|
||||||
|
pattern_dict = {}
|
||||||
|
for lettre in pattern:
|
||||||
|
if lettre != ".":
|
||||||
|
pattern_dict.update({pattern.index(lettre): lettre})
|
||||||
|
MotsOK, MotsKO = [], []
|
||||||
|
for mot in liste:
|
||||||
|
for key in pattern_dict:
|
||||||
|
if mot[key] == pattern_dict[key]:
|
||||||
|
MotsOK.append(mot)
|
||||||
|
else:
|
||||||
|
MotsKO.append(mot)
|
||||||
|
liste = [mot for mot in MotsOK if mot not in MotsKO]
|
||||||
|
liste = list(set(liste))
|
||||||
|
return liste
|
||||||
|
|
||||||
#if pattern:
|
#if pattern:
|
||||||
# patternCount = len(pattern) - pattern.count(".")
|
# patternCount = len(pattern) - pattern.count(".")
|
||||||
# for mot in goodLen:
|
# for mot in goodLen:
|
||||||
@ -90,18 +91,6 @@ def resolv_kl(liste, lettres):
|
|||||||
MotsRestants.append(mot)
|
MotsRestants.append(mot)
|
||||||
return MotsRestants
|
return MotsRestants
|
||||||
|
|
||||||
#if kl:
|
|
||||||
# if patternFilter:
|
|
||||||
# mots = patternFilter
|
|
||||||
# else:
|
|
||||||
# mots = goodLen
|
|
||||||
# for mot in mots:
|
|
||||||
# validate = 0
|
|
||||||
# for l in kl:
|
|
||||||
# if l in mot:
|
|
||||||
# validate += 1
|
|
||||||
# if validate == len(kl):
|
|
||||||
# klFilter.append(mot)
|
|
||||||
|
|
||||||
def resolv_bl(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)
|
||||||
@ -179,7 +168,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.pattern and args.nbLetters and len(pattern) != nb:
|
if args.pattern and args.nbLetters and len(args.pattern) != args.nbLetters:
|
||||||
print("Tu as merdé ta pattern petit scarabé !")
|
print("Tu as merdé ta pattern petit scarabé !")
|
||||||
exit(2)
|
exit(2)
|
||||||
|
|
||||||
@ -201,6 +190,8 @@ if __name__ == "__main__":
|
|||||||
liste = resolv_kl(liste, args.knownLetters)
|
liste = resolv_kl(liste, args.knownLetters)
|
||||||
if args.badLetters:
|
if args.badLetters:
|
||||||
liste = resolv_bl(liste, 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