diff --git a/.gitignore b/.gitignore index ed6cb0195..cea7431dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,10 @@ -**pyc -**swp -**log +**.pyc +**.swp **__pycache__ +**.venv **venv -**drafts **.cache -**sqlite +**sqlite3 **.idea **.vscode **.DS_Store diff --git a/02/README.md b/02/eternity336/README.md similarity index 100% rename from 02/README.md rename to 02/eternity336/README.md diff --git a/02/data.py b/02/eternity336/data.py similarity index 100% rename from 02/data.py rename to 02/eternity336/data.py diff --git a/01/dictionary.txt b/02/eternity336/dictionary.txt similarity index 100% rename from 01/dictionary.txt rename to 02/eternity336/dictionary.txt diff --git a/02/game-help.py b/02/eternity336/game-help.py similarity index 100% rename from 02/game-help.py rename to 02/eternity336/game-help.py diff --git a/02/eternity336/game.py b/02/eternity336/game.py new file mode 100644 index 000000000..82d7e8322 --- /dev/null +++ b/02/eternity336/game.py @@ -0,0 +1,60 @@ +#!python3 +# Code Challenge 02 - Word Values Part II - a simple game +# http://pybit.es/codechallenge02.html +import itertools + +from data import DICTIONARY, LETTER_SCORES, POUCH +import random +from datetime import date +from collections import Counter + +HANDS = [] +NUM_LETTERS = 7 + + +# re-use from challenge 01 +def calc_word_value(word): + """Calc a given word value based on Scrabble LETTER_SCORES mapping""" + return sum(LETTER_SCORES.get(char.upper(), 0) for char in word) + +# re-use from challenge 01 +def max_word_value(words): + """Calc the max value of a collection of words""" + return max(words, key=calc_word_value) + +def _get_permutations_draw(letters): + return list(itertools.chain.from_iterable([list(itertools.permutations(letters, n)) for n in range(1, NUM_LETTERS + 1)])) + +def _validation(word, letters): + if all([True if w in letters else False for w in list(word)]): + if word in DICTIONARY: + return True + raise ValueError("Word not in Letters!") + +def draw_letters(): + """Takes a tile out of the pouch and puts it into the hands""" + for n in range(NUM_LETTERS): + HANDS.append(random.choice(POUCH)) + POUCH.remove(HANDS[-1]) + return HANDS[-7:] + +def get_possible_dict_words(letters): + word_list = [] + for word in DICTIONARY: + if len(word) < 3: + print(word.upper()) + if len(word) <= len(letters): + list_word = Counter(list(word.upper())) + list_letters = Counter(letters) + if all([True if _ in list_letters.keys() and list_letters[_] >= list_word[_] else False for _ in list_word]): + word_list.append(word) + return word_list + +def main(): + for n in range(NUM_LETTERS): + draw_letters() + pass + +if __name__ == "__main__": + random.seed(date.today()) + main() diff --git a/02/test_game.py b/02/eternity336/test_game.py similarity index 100% rename from 02/test_game.py rename to 02/eternity336/test_game.py diff --git a/02/game-nohelp.py b/02/game-nohelp.py deleted file mode 100644 index 1531d09e5..000000000 --- a/02/game-nohelp.py +++ /dev/null @@ -1,27 +0,0 @@ -#!python3 -# Code Challenge 02 - Word Values Part II - a simple game -# http://pybit.es/codechallenge02.html - -from data import DICTIONARY, LETTER_SCORES, POUCH - -NUM_LETTERS = 7 - - -# re-use from challenge 01 -def calc_word_value(word): - """Calc a given word value based on Scrabble LETTER_SCORES mapping""" - return sum(LETTER_SCORES.get(char.upper(), 0) for char in word) - - -# re-use from challenge 01 -def max_word_value(words): - """Calc the max value of a collection of words""" - return max(words, key=calc_word_value) - - -def main(): - pass - - -if __name__ == "__main__": - main()