Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
176 changes: 172 additions & 4 deletions adagrams/game.py
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

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.


#=====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

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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
pool = deepcopy(letter_bank)
pool = [p.upper() for p in pool] # convert each element in a list to uppercase
pool = [p.upper() for p in letter_bank] # convert each element in a list to uppercase

In addition, a deep copy is not necessary, a shallow copy, ie letter_bank.copy() would work here as well to create a copy of the list. The letters in the letter bank are immutable strings. A deep copy is only needed when the contents of the list are mutable, and the original data needs to be preserved.

#print(pool)
#print("============")
for letter in word:
if letter.upper() not in pool:
return False
else:
pool.remove(letter.upper())

Choose a reason for hiding this comment

The 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"]

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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])

Choose a reason for hiding this comment

The 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
result=tuple([highest_score_word,highest_score])
result=tuple(highest_score_word,highest_score)

return result










1 change: 1 addition & 0 deletions tests/test_wave_01.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import random

from adagrams.game import draw_letters

Expand Down