10
10
11
11
@plugin ("word chain game" )
12
12
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
- """
23
13
if s :
24
14
jarvis .say ("This command does not take arguments. Just type 'word chain game' to start." )
25
15
return
26
16
27
17
def is_valid_word (word_to_check ):
28
- """Checks if a word is valid using Dictionary API."""
29
18
api_url = f"https://api.dictionaryapi.dev/api/v2/entries/en/{ word_to_check } "
30
19
try :
31
20
response = requests .get (api_url )
@@ -34,22 +23,20 @@ def is_valid_word(word_to_check):
34
23
return False
35
24
36
25
def get_jarvis_word (starting_letter , used_words ):
37
- """Jarvis finds a valid, unused word starting with the given letter."""
38
26
possible_words = [word for word in english_words
39
27
if word .startswith (starting_letter ) and word .lower () not in used_words ]
40
28
if possible_words :
41
29
return random .choice (possible_words ).lower ()
42
30
return None
43
31
44
32
def get_initial_word ():
45
- """Selects a random starting word from the pre-defined list."""
46
33
initial_words = [
47
34
"example" , "banana" , "grape" , "orange" , "kiwi" , "apple" , "lemon" , "melon" , "olive" , "peach" ,
48
35
"rhythm" , "synergy" , "wizard" , "oxygen" , "quartz" , "sphinx" , "voyage" , "utopia" , "yacht" , "zebra" ,
49
36
"azure" , "bronze" , "crimson" , "daisy" , "ebony" , "frost" , "golden" , "hazel" , "indigo" , "jade" ,
50
37
"amber" , "beige" , "coral" , "denim" , "ivory" , "khaki" , "lavender" , "magenta" , "ochre" , "pearl" ,
51
38
"apricot" , "burgundy" , "cyan" , "fuchsia" , "ginger" , "lime" , "maroon" , "navy" , "orchid" , "plum"
52
- ] # 50 diverse starting words
39
+ ]
53
40
return random .choice (initial_words ).lower ()
54
41
55
42
jarvis .say ("\n Let's play Word Chain! No word repeats allowed in this game." )
@@ -58,7 +45,6 @@ def get_initial_word():
58
45
last_letter = None
59
46
used_words = set ()
60
47
61
- # Jarvis starts first - using pre-defined initial word list
62
48
initial_word = get_initial_word ()
63
49
current_word = initial_word
64
50
word_chain .append (current_word )
@@ -91,14 +77,12 @@ def get_initial_word():
91
77
jarvis .say (f"Invalid! '{ user_word } ' not recognized. Game Over!" )
92
78
break
93
79
94
- # Valid word
95
80
word_chain .append (user_word )
96
81
used_words .add (user_word )
97
82
score += 1
98
83
last_letter = user_word [- 1 ].lower ()
99
84
jarvis .say (f"Valid word! '{ user_word } '. My turn..." )
100
85
101
- # Jarvis's Turn
102
86
next_word = get_jarvis_word (last_letter , used_words )
103
87
if next_word :
104
88
current_word = next_word
@@ -113,4 +97,4 @@ def get_initial_word():
113
97
114
98
jarvis .say ("\n Game Over!" )
115
99
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