Skip to content

Pcc02 #806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: community
Choose a base branch
from
Open

Pcc02 #806

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
**pyc
**swp
**log
**.pyc
**.swp
**__pycache__
**.venv
**venv
**drafts
**.cache
**sqlite
**sqlite3
**.idea
**.vscode
**.DS_Store
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
60 changes: 60 additions & 0 deletions 02/eternity336/game.py
Original file line number Diff line number Diff line change
@@ -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()
File renamed without changes.
27 changes: 0 additions & 27 deletions 02/game-nohelp.py

This file was deleted.