Skip to content

Commit a5f08ce

Browse files
authored
Update word_chain_game.py
Removed internal comments for better readability
1 parent a74023e commit a5f08ce

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

jarviscli/plugins/word_chain_game.py

+2-18
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,11 @@
1010

1111
@plugin("word chain game")
1212
def word_chain_game(jarvis, s):
13-
"""
14-
Starts a word chain game with varied starting words and no repeats.
15-
16-
Gameplay: Jarvis starts with a word from a pre-defined list.
17-
Players take turns entering words, each starting with the last letter
18-
of the previous word. Words cannot be repeated.
19-
The Dictionary API validates player words. Jarvis uses NLTK word list.
20-
21-
Usage: word chain game
22-
"""
2313
if s:
2414
jarvis.say("This command does not take arguments. Just type 'word chain game' to start.")
2515
return
2616

2717
def is_valid_word(word_to_check):
28-
"""Checks if a word is valid using Dictionary API."""
2918
api_url = f"https://api.dictionaryapi.dev/api/v2/entries/en/{word_to_check}"
3019
try:
3120
response = requests.get(api_url)
@@ -34,22 +23,20 @@ def is_valid_word(word_to_check):
3423
return False
3524

3625
def get_jarvis_word(starting_letter, used_words):
37-
"""Jarvis finds a valid, unused word starting with the given letter."""
3826
possible_words = [word for word in english_words
3927
if word.startswith(starting_letter) and word.lower() not in used_words]
4028
if possible_words:
4129
return random.choice(possible_words).lower()
4230
return None
4331

4432
def get_initial_word():
45-
"""Selects a random starting word from the pre-defined list."""
4633
initial_words = [
4734
"example", "banana", "grape", "orange", "kiwi", "apple", "lemon", "melon", "olive", "peach",
4835
"rhythm", "synergy", "wizard", "oxygen", "quartz", "sphinx", "voyage", "utopia", "yacht", "zebra",
4936
"azure", "bronze", "crimson", "daisy", "ebony", "frost", "golden", "hazel", "indigo", "jade",
5037
"amber", "beige", "coral", "denim", "ivory", "khaki", "lavender", "magenta", "ochre", "pearl",
5138
"apricot", "burgundy", "cyan", "fuchsia", "ginger", "lime", "maroon", "navy", "orchid", "plum"
52-
] # 50 diverse starting words
39+
]
5340
return random.choice(initial_words).lower()
5441

5542
jarvis.say("\nLet's play Word Chain! No word repeats allowed in this game.")
@@ -58,7 +45,6 @@ def get_initial_word():
5845
last_letter = None
5946
used_words = set()
6047

61-
# Jarvis starts first - using pre-defined initial word list
6248
initial_word = get_initial_word()
6349
current_word = initial_word
6450
word_chain.append(current_word)
@@ -91,14 +77,12 @@ def get_initial_word():
9177
jarvis.say(f"Invalid! '{user_word}' not recognized. Game Over!")
9278
break
9379

94-
# Valid word
9580
word_chain.append(user_word)
9681
used_words.add(user_word)
9782
score += 1
9883
last_letter = user_word[-1].lower()
9984
jarvis.say(f"Valid word! '{user_word}'. My turn...")
10085

101-
# Jarvis's Turn
10286
next_word = get_jarvis_word(last_letter, used_words)
10387
if next_word:
10488
current_word = next_word
@@ -113,4 +97,4 @@ def get_initial_word():
11397

11498
jarvis.say("\nGame Over!")
11599
jarvis.say(f"Word Chain: {', '.join(word_chain)}")
116-
jarvis.say(f"Your Score: {score}")
100+
jarvis.say(f"Your Score: {score}")

0 commit comments

Comments
 (0)