Compare commits
5 Commits
25669da340
...
578bc69820
Author | SHA1 | Date | |
---|---|---|---|
578bc69820 | |||
9c9439b39b | |||
23c8f27def | |||
e34317000c | |||
332c571b71 |
24
wgamesolv.py
24
wgamesolv.py
@ -46,6 +46,7 @@ def firstTryFilter(mots, max_mots):
|
||||
|
||||
def resolv_fl(liste, firstletter):
|
||||
# On ne garde que les mots qui commence par FirstLetter
|
||||
firstletter = firstletter.upper()
|
||||
return [mot for mot in liste if mot[0] == firstletter]
|
||||
|
||||
|
||||
@ -56,10 +57,12 @@ def resolv_len(liste, lenght):
|
||||
|
||||
def resolv_pattern(liste, pattern):
|
||||
# Pattern : élimination des mots ne satisfaisant pas la pattern
|
||||
pattern_dict = {}
|
||||
pattern_dict, not_pattern_dict = {}, {}
|
||||
for lettre in pattern:
|
||||
if lettre != ".":
|
||||
if lettre != "." and lettre.isupper():
|
||||
pattern_dict.update({pattern.index(lettre): lettre})
|
||||
if lettre != "." and lettre.islower():
|
||||
not_pattern_dict.update({pattern.index(lettre): lettre.upper()})
|
||||
MotsOK, MotsKO = [], []
|
||||
for mot in liste:
|
||||
for key in pattern_dict:
|
||||
@ -67,6 +70,10 @@ def resolv_pattern(liste, pattern):
|
||||
MotsOK.append(mot)
|
||||
else:
|
||||
MotsKO.append(mot)
|
||||
for key in not_pattern_dict:
|
||||
if mot[key] == not_pattern_dict[key]:
|
||||
MotsKO.append(mot)
|
||||
MotsKO = set(MotsKO)
|
||||
liste = [mot for mot in MotsOK if mot not in MotsKO]
|
||||
liste = list(set(liste))
|
||||
return liste
|
||||
@ -77,7 +84,7 @@ def resolv_kl(liste, lettres):
|
||||
Known Letters : élimination des mots ne comprenant pas
|
||||
les lettres validées (hors pattern)
|
||||
'''
|
||||
lettres = list(set(list(lettres)))
|
||||
lettres = list(set(list(lettres.upper())))
|
||||
MotsRestants = []
|
||||
for mot in liste:
|
||||
if len(set(lettres).intersection(mot)) == len(lettres):
|
||||
@ -90,18 +97,13 @@ def resolv_bl(liste, lettres):
|
||||
Bad Letters : élimination des mots contenant
|
||||
des lettres invalidées (hors pattern)
|
||||
'''
|
||||
lettres = list(set(list(lettres)))
|
||||
lettres = list(set(list(lettres.upper())))
|
||||
MotsSuppr = []
|
||||
for mot in liste:
|
||||
for lettre in lettres:
|
||||
if lettre in mot:
|
||||
MotsSuppr.append(mot)
|
||||
for mot in MotsSuppr:
|
||||
try:
|
||||
liste.pop(liste.index(mot))
|
||||
except ValueError:
|
||||
pass
|
||||
return liste
|
||||
return [mot for mot in liste if mot not in MotsSuppr]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@ -144,7 +146,7 @@ if __name__ == "__main__":
|
||||
'-p',
|
||||
'--pattern',
|
||||
default=False,
|
||||
help='Placement, avec des "." pour les inconnues : -p A...T.I.'
|
||||
help='Placement : bien placée en majuscule, mal placée en minuscule et non existante par un \'.\'. E.g. : Ra..e.T'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-nd',
|
||||
|
Loading…
Reference in New Issue
Block a user