Réorganisation du code
This commit is contained in:
parent
8b9175454b
commit
0a8c29de74
241
wgamesolv.py
241
wgamesolv.py
@ -4,97 +4,16 @@
|
||||
import json
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Cheating with SUTOM'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-d',
|
||||
'--dictionary',
|
||||
help='Dictionnaire des mots du jeu',
|
||||
required=True
|
||||
)
|
||||
parser.add_argument(
|
||||
'-fl',
|
||||
'--firstLetter',
|
||||
help='Première lettre',
|
||||
default=False,
|
||||
required=True
|
||||
)
|
||||
parser.add_argument(
|
||||
'-nb',
|
||||
'--nbLetters',
|
||||
type=int,
|
||||
help='Nombre de lettres, un entier',
|
||||
default=False,
|
||||
required=True
|
||||
)
|
||||
parser.add_argument(
|
||||
'-kl',
|
||||
'--knownLetters',
|
||||
default=False,
|
||||
help='Lettres connues, hors première, sans espaces : -kl BE'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-bl',
|
||||
'--badLetters',
|
||||
default=False,
|
||||
help='Lettres non valides, sans espaces : -bl AKL'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-p',
|
||||
'--pattern',
|
||||
default=False,
|
||||
help='Placement, avec des "." pour les inconnues : -p A...T.I.'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-nd',
|
||||
'--noDoubleLetters',
|
||||
help="Option pour ne chercher que des mots ne contenant qu'une occurence de chaque lettre",
|
||||
default=False,
|
||||
action="store_true"
|
||||
)
|
||||
parser.add_argument(
|
||||
'-ft',
|
||||
'--firstTry',
|
||||
default=False,
|
||||
type=int,
|
||||
help="Sélectionne des mots commençants par firstLetter et composés de ft voyelles différentes: -ft 4",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
def load_dict(dict_file):
|
||||
try :
|
||||
with open(dict_file, "r") as dico:
|
||||
liste = json.load(dico)
|
||||
return liste
|
||||
except:
|
||||
print("Impossible d'ouvrir le fichier" + fp)
|
||||
|
||||
# First letter
|
||||
fl = args.firstLetter
|
||||
|
||||
# Nbr Letters
|
||||
nb = args.nbLetters
|
||||
|
||||
# Pattern
|
||||
pattern = args.pattern
|
||||
if pattern and args.nbLetters and len(pattern) != nb:
|
||||
print("Tu as merdé ta pattern petit scarabé !")
|
||||
exit(2)
|
||||
|
||||
# Known Letters
|
||||
kl = args.knownLetters
|
||||
|
||||
# Bad Letters
|
||||
bl = args.badLetters
|
||||
|
||||
# First Try
|
||||
ft = args.firstTry
|
||||
|
||||
patternFilter = []
|
||||
klFilter = []
|
||||
blFilter = []
|
||||
ftFilter = []
|
||||
|
||||
def noDouble(mots):
|
||||
# Fonction d'élimination de mots contenant plusieurs occurences de lettres
|
||||
@ -148,58 +67,130 @@ def resolv_len(liste, lenght):
|
||||
|
||||
|
||||
# First Try
|
||||
if ft:
|
||||
bestWords = noDouble(firstTryFilter(goodLen, ft))
|
||||
#if ft:
|
||||
# bestWords = noDouble(firstTryFilter(goodLen, ft))
|
||||
|
||||
# Pattern : élimination des mots ne satisfaisant pas la pattern
|
||||
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)
|
||||
|
||||
#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)
|
||||
#
|
||||
# Known Letters : élimination des mots ne comprenant pas les lettres validées (hors pattern)
|
||||
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)
|
||||
#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)
|
||||
|
||||
# Bad Letters : élimination des mots contenant des lettres invalidées (hors pattern)
|
||||
if bl:
|
||||
if klFilter:
|
||||
mots = klFilter
|
||||
elif patternFilter:
|
||||
mots = patternFilter
|
||||
else:
|
||||
mots = goodLen
|
||||
for mot in mots:
|
||||
invalidate = 0
|
||||
for l in bl:
|
||||
if l in mot and l in pattern:
|
||||
if pattern.count(l) != mot.count(l):
|
||||
invalidate += 1
|
||||
elif l in mot:
|
||||
invalidate += 1
|
||||
if invalidate == 0:
|
||||
blFilter.append(mot)
|
||||
#if bl:
|
||||
# if klFilter:
|
||||
# mots = klFilter
|
||||
# elif patternFilter:
|
||||
# mots = patternFilter
|
||||
# else:
|
||||
# mots = goodLen
|
||||
# for mot in mots:
|
||||
# invalidate = 0
|
||||
# for l in bl:
|
||||
# if l in mot and l in pattern:
|
||||
# if pattern.count(l) != mot.count(l):
|
||||
# invalidate += 1
|
||||
# elif l in mot:
|
||||
# invalidate += 1
|
||||
# if invalidate == 0:
|
||||
# blFilter.append(mot)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Cheating with SUTOM'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-d',
|
||||
'--dictionary',
|
||||
help='Dictionnaire des mots du jeu',
|
||||
required=True
|
||||
)
|
||||
parser.add_argument(
|
||||
'-fl',
|
||||
'--firstLetter',
|
||||
help='Première lettre',
|
||||
default=False,
|
||||
required=True
|
||||
)
|
||||
parser.add_argument(
|
||||
'-nb',
|
||||
'--nbLetters',
|
||||
type=int,
|
||||
help='Nombre de lettres, un entier',
|
||||
default=False,
|
||||
required=True
|
||||
)
|
||||
parser.add_argument(
|
||||
'-kl',
|
||||
'--knownLetters',
|
||||
default=False,
|
||||
help='Lettres connues, hors première, sans espaces : -kl BE'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-bl',
|
||||
'--badLetters',
|
||||
default=False,
|
||||
help='Lettres non valides, sans espaces : -bl AKL'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-p',
|
||||
'--pattern',
|
||||
default=False,
|
||||
help='Placement, avec des "." pour les inconnues : -p A...T.I.'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-nd',
|
||||
'--noDoubleLetters',
|
||||
help="Option pour ne chercher que des mots ne contenant qu'une occurence de chaque lettre",
|
||||
default=False,
|
||||
action="store_true"
|
||||
)
|
||||
parser.add_argument(
|
||||
'-ft',
|
||||
'--firstTry',
|
||||
default=False,
|
||||
type=int,
|
||||
help="Sélectionne des mots commençants par firstLetter et composés de ft voyelles différentes: -ft 4",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.pattern and args.nbLetters and len(pattern) != nb:
|
||||
print("Tu as merdé ta pattern petit scarabé !")
|
||||
exit(2)
|
||||
|
||||
# Known Letters
|
||||
kl = args.knownLetters
|
||||
|
||||
# Bad Letters
|
||||
bl = args.badLetters
|
||||
|
||||
# First Try
|
||||
ft = args.firstTry
|
||||
|
||||
liste = load_dict(args.dictionary)
|
||||
liste = resolv_len(liste, nb)
|
||||
liste = resolv_fl(liste, fl)
|
||||
liste = resolv_len(liste, args.nbLetters)
|
||||
liste = resolv_fl(liste, args.firstLetter)
|
||||
if args.noDoubleLetters:
|
||||
liste = noDouble(liste)
|
||||
if len(liste) > 1:
|
||||
|
Loading…
Reference in New Issue
Block a user