-
Notifications
You must be signed in to change notification settings - Fork 69
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
Olena Rostotskyy and Joanna Parisi Adagram project c17 otter class #35
base: master
Are you sure you want to change the base?
Changes from all commits
066ffdf
0a2a7c5
f078274
7ab31f8
7c01048
48e5246
040a1e6
ce54ae8
cd145d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,11 +1,179 @@ | ||||||||
#testing commit | ||||||||
from copy import deepcopy | ||||||||
import random | ||||||||
|
||||||||
|
||||||||
|
||||||||
def draw_letters(): | ||||||||
pass | ||||||||
LETTER_POOL = { | ||||||||
'A': 9, | ||||||||
'B': 2, | ||||||||
'C': 2, | ||||||||
'D': 4, | ||||||||
'E': 12, | ||||||||
'F': 2, | ||||||||
'G': 3, | ||||||||
'H': 2, | ||||||||
'I': 9, | ||||||||
'J': 1, | ||||||||
'K': 1, | ||||||||
'L': 4, | ||||||||
'M': 2, | ||||||||
'N': 6, | ||||||||
'O': 8, | ||||||||
'P': 2, | ||||||||
'Q': 1, | ||||||||
'R': 6, | ||||||||
'S': 4, | ||||||||
'T': 6, | ||||||||
'U': 4, | ||||||||
'V': 2, | ||||||||
'W': 2, | ||||||||
'X': 1, | ||||||||
'Y': 2, | ||||||||
'Z': 1 | ||||||||
} | ||||||||
|
||||||||
letter_key_list = list(LETTER_POOL.keys()) | ||||||||
random.shuffle(letter_key_list) | ||||||||
|
||||||||
letter_list = [] | ||||||||
for letter in letter_key_list: | ||||||||
if LETTER_POOL[letter] > 0: | ||||||||
if len(letter_list) < 10: | ||||||||
letter_list.append(letter) | ||||||||
|
||||||||
return letter_list | ||||||||
|
||||||||
#=====another example========== | ||||||||
# def draw_letters(): | ||||||||
# # Each time when we cal the function it will create new pool by appending keys v(value)timeseach in our list | ||||||||
# # Invoking this function will not change the original pool of letters | ||||||||
# #========creating new pool of letters============== | ||||||||
# pool=[] | ||||||||
# for k,v in LETTER_POOL.items(): | ||||||||
# count=0 | ||||||||
# while count <v: | ||||||||
# pool.append(k) | ||||||||
# count+=1 | ||||||||
Comment on lines
+56
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would work to create a letter pool with the correct distribution. |
||||||||
|
||||||||
# #======creating hand of letters================= | ||||||||
# #hand - random letters that the player has drawn [list of 10] | ||||||||
# hand=[] | ||||||||
# counter=0 | ||||||||
# while counter <10:# creating random index from 0 to 10 | ||||||||
# random_inex=random.randint(0, len(pool)-1) | ||||||||
# hand.append(pool[random_inex]) #adding randomly picked letter to our hand (list of 10) | ||||||||
# pool.pop(random_inex) #removing the same element from the pool | ||||||||
# counter+=1 | ||||||||
Comment on lines
+64
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||||||||
# return hand | ||||||||
|
||||||||
def uses_available_letters(word, letter_bank): | ||||||||
pass | ||||||||
pool = deepcopy(letter_bank) | ||||||||
pool = [p.upper() for p in pool] # convert each element in a list to uppercase | ||||||||
Comment on lines
+72
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both of these lines are creating a new list. They can be combined:
Suggested change
In addition, a deep copy is not necessary, a shallow copy, ie |
||||||||
#print(pool) | ||||||||
#print("============") | ||||||||
for letter in word: | ||||||||
if letter.upper() not in pool: | ||||||||
return False | ||||||||
else: | ||||||||
pool.remove(letter.upper()) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||||||||
return True | ||||||||
|
||||||||
|
||||||||
#======another example============ | ||||||||
# def uses_available_letters(word, letter_bank): | ||||||||
# pass | ||||||||
# letter_bank_dict = {} | ||||||||
# for letter in letter_bank: | ||||||||
# if letter not in letter_bank_dict: | ||||||||
# letter_bank_dict[letter] = 1 | ||||||||
# elif letter in letter_bank_dict: | ||||||||
# letter_bank_dict[letter] += 1 | ||||||||
|
||||||||
# new_word = "" | ||||||||
# for letter in word: | ||||||||
# if letter.upper() in letter_bank_dict: | ||||||||
# if letter_bank_dict[letter.upper()] > 0: | ||||||||
# letter_bank_dict[letter.upper()] -= 1 | ||||||||
# new_word = new_word+letter | ||||||||
# else: | ||||||||
# return False | ||||||||
|
||||||||
# if word == new_word: | ||||||||
# return True | ||||||||
# else: | ||||||||
# return False | ||||||||
|
||||||||
|
||||||||
def score_word(word): | ||||||||
pass | ||||||||
|
||||||||
list_1 = ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"] | ||||||||
list_2 = ["D", "G"] | ||||||||
list_3 = ["B", "C", "M", "P"] | ||||||||
list_4 = ["F", "H", "V", "W", "Y"] | ||||||||
list_5 = ["K"] | ||||||||
list_6 = ["J", "X"] | ||||||||
list_7 = ["Q", "Z"] | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See feedback in Adagrams PSE for notes on optimization. |
||||||||
|
||||||||
total_points = 0 | ||||||||
|
||||||||
for letter in word: | ||||||||
if letter.upper() in list_1: | ||||||||
total_points += 1 | ||||||||
elif letter.upper() in list_2: | ||||||||
total_points += 2 | ||||||||
elif letter.upper() in list_3: | ||||||||
total_points += 3 | ||||||||
elif letter.upper() in list_4: | ||||||||
total_points += 4 | ||||||||
elif letter.upper() in list_5: | ||||||||
total_points += 5 | ||||||||
elif letter.upper() in list_6: | ||||||||
total_points += 8 | ||||||||
elif letter.upper() in list_7: | ||||||||
total_points += 10 | ||||||||
|
||||||||
if len(word)>=7 and len(word)<=10: | ||||||||
total_points+=8 | ||||||||
|
||||||||
return total_points | ||||||||
|
||||||||
|
||||||||
def get_highest_word_score(word_list): | ||||||||
pass | ||||||||
dict_of_words={} | ||||||||
for word in word_list: | ||||||||
score =score_word(word) | ||||||||
dict_of_words[word]=score | ||||||||
|
||||||||
highest_score=0 | ||||||||
highest_score_words=[] | ||||||||
|
||||||||
for k,v in dict_of_words.items(): | ||||||||
if v>highest_score: | ||||||||
highest_score=v | ||||||||
highest_score_words.clear() | ||||||||
highest_score_words.append(k) | ||||||||
elif v==highest_score: | ||||||||
highest_score_words.append(k) | ||||||||
Comment on lines
+152
to
+158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||||||||
|
||||||||
highest_score_word=highest_score_words[0] | ||||||||
for e in highest_score_words: | ||||||||
if len(e) >=10: | ||||||||
highest_score_word=e | ||||||||
break | ||||||||
elif len(e)<len(highest_score_word): | ||||||||
highest_score_word=e | ||||||||
Comment on lines
+161
to
+166
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fantastic work with this algorithm! Small note, I recommend avoiding single letter variable names - more descriptive variable improve readability. |
||||||||
|
||||||||
result=tuple([highest_score_word,highest_score]) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tuple here can be built directly, no need to create a list and then convert it to a tuple.
Suggested change
|
||||||||
return result | ||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import pytest | ||
import random | ||
|
||
from adagrams.game import draw_letters | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function will pass the tests, but the letter distribution is not correct.
letter_key_list
will contain all of the letters only once, and then the loop starting on line 41 will pick the first 10. Essentially, this is a letter distribution of 1 tile per letter.