X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=examples%2Fwordle%2Fwordle.py;h=ca7930a384f203b0360cd1355ac82b146540181e;hb=ccca7ea8fae7ab9a79a88baf9a7f8f3219403c7b;hp=e5b6c6f7cb0f5be899a881face9a3d32a7ed8024;hpb=25cc42619c9f4381df45d84f5188dba290c3cfaa;p=pyutils.git diff --git a/examples/wordle/wordle.py b/examples/wordle/wordle.py index e5b6c6f..ca7930a 100755 --- a/examples/wordle/wordle.py +++ b/examples/wordle/wordle.py @@ -24,7 +24,7 @@ from pyutils.files import file_utils from pyutils.parallelize import executors from pyutils.parallelize import parallelize as par from pyutils.parallelize import smart_future -from pyutils.typez import histogram +from pyutils.types import histogram logger = logging.getLogger(__name__) args = config.add_commandline_args( @@ -90,19 +90,19 @@ For example: args.add_argument( '--solutions_file', type=str, - default='/home/scott/bin/wordle_solutions.txt', + default='wordle_solutions.txt', help='Where can I find a valid word list for solutions?', ) args.add_argument( '--guesses_file', type=str, - default='/home/scott/bin/wordle_guesses.txt', + default='wordle_guesses.txt', help='Where can I find a valid word list for guesses?', ) args.add_argument( '--hash_file', type=str, - default='/home/scott/bin/wordle_hash.txt', + default='wordle_hash.txt', help='Where can I find my precomputed hash file?', ) @@ -573,7 +573,7 @@ class AutoPlayer(object): # remaining words. See --mode=PRECOMPUTE for how to populate. self.position_hash = {} filename = config.config['hash_file'] - if filename is not None and file_utils.file_is_readable(filename): + if filename is not None and file_utils.is_readable(filename): logger.debug(f'Initializing position hash from {filename}...') with open(filename, 'r') as rf: for line in rf: @@ -594,7 +594,7 @@ class AutoPlayer(object): # All legal solutions pre-sorted by length. self.all_possible_solutions_by_length = defaultdict(list) filename = config.config['solutions_file'] - if filename is not None and file_utils.file_is_readable(filename): + if filename is not None and file_utils.is_readable(filename): logger.debug(f'Initializing valid solution word list from {filename}...') with open(filename) as rf: for word in rf: @@ -608,7 +608,7 @@ class AutoPlayer(object): # All legal guesses pre-sorted by length. self.all_possible_guesses_by_length = defaultdict(list) filename = config.config['guesses_file'] - if filename is not None and file_utils.file_is_readable(filename): + if filename is not None and file_utils.is_readable(filename): logger.debug(f'Initializing legal guess word list from {filename}...') with open(filename) as rf: for word in rf: @@ -655,11 +655,6 @@ class AutoPlayer(object): if letter in word_state.letters_excluded: return False - # If we already tried this letter in this position and - # it wasn't green, this isn't a possible solution. - if n in word_state.letters_at_unknown_positions[letter]: - return False - # If we know a letter is in a position, solution words # must have that letter in that position. if ( @@ -667,6 +662,12 @@ class AutoPlayer(object): and letter != word_state.letters_at_known_positions[n] ): return False + + # If we already tried this letter in this position and + # it wasn't green, this isn't a possible solution. + if n in word_state.letters_at_unknown_positions[letter]: + return False + letters_seen[letter] += 1 # Finally, the word must include all letters presently @@ -1083,7 +1084,7 @@ def colorize_guess(guess: Word, hints: Dict[Position, Hint]) -> str: def get_max_letter_population() -> Dict[Letter, int]: filename = config.config['solutions_file'] max_letter_population_per_word: Dict[Letter, int] = defaultdict(int) - if filename is not None and file_utils.file_is_readable(filename): + if filename is not None and file_utils.is_readable(filename): logger.debug( 'Figuring out all letters\' max frequency in the solution space...' )