diff --git a/README.md b/README.md
index cfaa5310..91acfc1d 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,7 @@
# AdaGrams
+Project Credit: Ada Developers Academy
+Name: Linh Huynh
+Date: March 16, 2023
## Skills Assessed
diff --git a/adagrams/game.py b/adagrams/game.py
index 5fb37b11..a393f812 100644
--- a/adagrams/game.py
+++ b/adagrams/game.py
@@ -1,11 +1,170 @@
+import random
+from collections import Counter
+
+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
+}
+
+SCORE_CHART = {
+ 'A': 1,
+ 'B': 3,
+ 'C': 3,
+ 'D': 2,
+ 'E': 1,
+ 'F': 4,
+ 'G': 2,
+ 'H': 4,
+ 'I': 1,
+ 'J': 8,
+ 'K': 5,
+ 'L': 1,
+ 'M': 3,
+ 'N': 1,
+ 'O': 1,
+ 'P': 3,
+ 'Q': 10,
+ 'R': 1,
+ 'S': 1,
+ 'T': 1,
+ 'U': 1,
+ 'V': 4,
+ 'W': 4,
+ 'X': 8,
+ 'Y': 4,
+ 'Z': 10
+}
+
+LETTER_POOL_LIST = []
+temp_list = []
+
def draw_letters():
- pass
-def uses_available_letters(word, letter_bank):
- pass
+ # Creates a comprehensive list which includes the total quanity of each available letter from the LETTER_POOL dictionary as individual elements.
+ for letter, quantity in LETTER_POOL.items():
+ temp_list.append([letter] * quantity)
+
+ for sublist in temp_list:
+ for letter in sublist:
+ LETTER_POOL_LIST.append(letter)
+
+ # Chooses 10 random letters as hand, excluding the ones that are already chosen.
+ #hand = random.sample(LETTER_POOL_LIST, 10)
+
+ hand = []
+ while len(hand) < 10:
+ random_letter = random.choice(LETTER_POOL_LIST)
+ random_letter_index = LETTER_POOL_LIST.index(random_letter)
+ LETTER_POOL_LIST.pop(random_letter_index)
+ hand.append(random_letter)
+
+ return hand
+
+draw_letters()
+
+def uses_available_letters(word, letter_bank):
+ word_verification = []
+ hand_letter_count = {}
+ word_letter_count = {}
+ count = 0
+ capitalized_word = word.upper()
+
+ for letter in letter_bank:
+ if letter not in hand_letter_count:
+ count = 1
+ hand_letter_count[letter] = count
+ else:
+ count += 1
+ hand_letter_count[letter] = count
+
+ for letter in capitalized_word:
+ letter_quantity = capitalized_word.count(letter)
+ word_letter_count[letter] = letter_quantity
+
+ if letter in letter_bank and word_letter_count[letter] <= hand_letter_count[letter]:
+ word_verification.append("True")
+ else:
+ word_verification.append("False")
+
+ if "False" in word_verification:
+ return False
+ else:
+ return True
+
def score_word(word):
- pass
+ word_score = {}
+
+ if word == "":
+ word_score["empty"] = 0
+
+ for letter in word.upper():
+ if letter in SCORE_CHART:
+ if letter not in word_score:
+ word_score[letter] = SCORE_CHART[letter]
+ else:
+ word_score[letter] += SCORE_CHART[letter]
+
+ if 7 <= len(word) <= 10:
+ word_score["bonus"] = 8
+
+ return sum(word_score.values())
def get_highest_word_score(word_list):
- pass
\ No newline at end of file
+ score_dict = {}
+ score_list = []
+ matching_scores_dict = {}
+ highest_score = 0
+
+ for word in word_list:
+ score = score_word(word)
+ score_dict[word] = score
+
+ for word, score in score_dict.items():
+ score_list.append(score)
+ if score > highest_score:
+ highest_score = score
+ winning_word = word
+
+ matching_scores = [k for k,v in Counter(score_list).items() if v>1]
+
+ for word, score in score_dict.items():
+ if score in matching_scores:
+ matching_scores_dict[word] = score
+
+ for word, score in matching_scores_dict.items():
+ if score == highest_score and len(word) == 10:
+ highest_score = score
+ winning_word = word
+ break
+ elif score == highest_score and len(word) < len(winning_word):
+ highest_score = score
+ winning_word = word
+ break
+
+ best_word = (winning_word, highest_score)
+ return best_word
\ No newline at end of file
diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py
index ef48e03b..6d776100 100644
--- a/tests/test_wave_01.py
+++ b/tests/test_wave_01.py
@@ -38,6 +38,7 @@ def test_draw_letters_draws_ten():
# Assert
assert len(letters) == 10
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_draw_letters_is_list_of_letter_strings():
# Arrange/Act
letters = draw_letters()
@@ -49,6 +50,7 @@ def test_draw_letters_is_list_of_letter_strings():
assert type(elem) == str
assert len(elem) == 1
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_letter_not_selected_too_many_times():
for i in range(1000):
@@ -66,6 +68,7 @@ def test_letter_not_selected_too_many_times():
for letter in letters:
assert letter_freq[letter] <= LETTER_POOL[letter]
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_draw_letters_returns_different_hands():
# Arrange/Act
hand1 = draw_letters()
diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py
index a5170d8a..a9a9759d 100644
--- a/tests/test_wave_02.py
+++ b/tests/test_wave_02.py
@@ -13,6 +13,7 @@ def test_uses_available_letters_true_word_in_letter_bank():
# Assert
assert is_valid == True
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_uses_available_letters_false_word_in_letter_bank():
# Arrange
letters = ["D", "O", "X", "X", "X", "X", "X", "X", "X", "X"]
@@ -24,6 +25,7 @@ def test_uses_available_letters_false_word_in_letter_bank():
# Assert
assert is_valid == False
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_uses_available_letters_false_word_overuses_letter():
# Arrange
letters = ["A", "X", "X", "X", "X", "X", "X", "X", "X", "X"]
@@ -35,6 +37,7 @@ def test_uses_available_letters_false_word_overuses_letter():
# Assert
assert is_valid == False
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_uses_available_letters_does_not_change_letter_bank():
# Arrange
letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
@@ -48,6 +51,7 @@ def test_uses_available_letters_does_not_change_letter_bank():
assert is_valid == True
assert letters == letters_copy
+#pytest.mark.skip(reason="no way of currently testing this")
def test_uses_available_letters_ignores_case():
# Arrange
letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py
index 5473db39..85fff889 100644
--- a/tests/test_wave_03.py
+++ b/tests/test_wave_03.py
@@ -8,16 +8,19 @@ def test_score_word_accurate():
assert score_word("DOG") == 5
assert score_word("WHIMSY") == 17
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_score_word_accurate_ignores_case():
# Assert
assert score_word("a") == 1
assert score_word("dog") == 5
assert score_word("wHiMsY") == 17
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_score_zero_for_empty():
# Assert
assert score_word("") == 0
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_score_extra_points_for_seven_or_longer():
# Assert
assert score_word("XXXXXXX") == 64
diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py
index e586621c..b04b3ac1 100644
--- a/tests/test_wave_04.py
+++ b/tests/test_wave_04.py
@@ -14,6 +14,7 @@ def test_get_highest_word_score_accurate():
assert best_word[0] == "XXXX"
assert best_word[1] == 32
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_get_highest_word_score_accurate_unsorted_list():
# Arrange
words = ["XXX", "XXXX", "XX", "X"]
@@ -25,6 +26,7 @@ def test_get_highest_word_score_accurate_unsorted_list():
assert best_word[0] == "XXXX"
assert best_word[1] == 32
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_get_highest_word_tie_prefers_shorter_word():
# Arrange
words = ["MMMM", "WWW"]
@@ -38,6 +40,7 @@ def test_get_highest_word_tie_prefers_shorter_word():
assert best_word[0] == "WWW"
assert best_word[1] == 12
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_get_highest_word_tie_prefers_shorter_word_unsorted_list():
# Arrange
words = ["WWW", "MMMM"]
@@ -51,6 +54,7 @@ def test_get_highest_word_tie_prefers_shorter_word_unsorted_list():
assert best_word[0] == "WWW"
assert best_word[1] == 12
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_get_highest_word_tie_prefers_ten_letters():
# Arrange
words = ["AAAAAAAAAA", "BBBBBB"]
@@ -62,6 +66,7 @@ def test_get_highest_word_tie_prefers_ten_letters():
assert best_word[0] == "AAAAAAAAAA"
assert best_word[1] == 18
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_get_highest_word_tie_prefers_ten_letters_unsorted_list():
# Arrange
words = ["BBBBBB", "AAAAAAAAAA"]
@@ -73,6 +78,7 @@ def test_get_highest_word_tie_prefers_ten_letters_unsorted_list():
assert best_word[0] == "AAAAAAAAAA"
assert best_word[1] == 18
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_get_highest_word_tie_same_length_prefers_first():
# Arrange
words = ["AAAAAAAAAA", "EEEEEEEEEE"]
@@ -86,6 +92,7 @@ def test_get_highest_word_tie_same_length_prefers_first():
assert best_word[0] == words[0]
assert best_word[1] == 18
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_get_highest_word_many_ties_pick_first_ten_letters():
# Arrange
words = ["JQ", "FHQ", "AAAAAAAAAA", "BBBBBB", "TTTTTTTTTT"]
@@ -97,6 +104,7 @@ def test_get_highest_word_many_ties_pick_first_ten_letters():
assert best_word[0] == "AAAAAAAAAA"
assert best_word[1] == 18
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_get_highest_word_many_ties_pick_shortest():
# Arrange
words = ["BBBBBB", "AAAAAAAAD", "JQ", "KFHK"]
@@ -108,6 +116,7 @@ def test_get_highest_word_many_ties_pick_shortest():
assert best_word[0] == "JQ"
assert best_word[1] == 18
+#@pytest.mark.skip(reason="no way of currently testing this")
def test_get_highest_word_does_not_return_early_after_first_tiebreaker():
# Arrange
words = ["WWW", "MMMM", "BBBBBB", "AAAAAAAAD", "JQ", "KFHK"]