Spaces:
Sleeping

byte-vortex commited on
Commit
4f409b9
·
verified ·
1 Parent(s): 39c59c9

Deploy Myco from CI

Browse files
Files changed (2) hide show
  1. README.md +13 -0
  2. game/engine.py +81 -0
README.md CHANGED
@@ -15,6 +15,19 @@ Myco is a small Gradio game for Hugging Face Spaces. Explore a cozy forest with
15
 
16
  **Live Space:** https://huggingface.co/spaces/byte-vortex/Myco
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  ## First Play Loop
19
 
20
  1. Click **Start Exploring**.
 
15
 
16
  **Live Space:** https://huggingface.co/spaces/byte-vortex/Myco
17
 
18
+
19
+ ## Hackathon Direction
20
+
21
+ Myco is built for Hugging Face's Build Small hackathon and the OpenAI Codex prize track. The project optimizes for one polished, memorable mechanic instead of a large feature list: a whimsical AI mushroom companion that makes each forest discovery feel playful, personal, and shareable.
22
+
23
+ Design decisions should prioritize:
24
+
25
+ - **Delight:** create a 10-second hook that makes the player smile.
26
+ - **AI as the experience:** Myco's companion voice should feel central, not like a generic chatbot wrapper.
27
+ - **Originality:** keep the mushroom-companion game strange, cozy, and memorable.
28
+ - **Polish:** maintain a smooth Gradio Space with clear onboarding, responsive UI, and a strong visual identity.
29
+ - **Small scope:** prefer one unforgettable loop over many unfinished mechanics.
30
+
31
  ## First Play Loop
32
 
33
  1. Click **Start Exploring**.
game/engine.py CHANGED
@@ -1,5 +1,12 @@
1
  """Core Myco gameplay actions independent from Gradio."""
2
 
 
 
 
 
 
 
 
3
  from __future__ import annotations
4
 
5
  import random
@@ -24,6 +31,17 @@ def choose_mushroom(catalog: Sequence[Mushroom] | None = None) -> Mushroom:
24
  return random.choice(mushrooms)
25
 
26
 
 
 
 
 
 
 
 
 
 
 
 
27
  def discover_mushroom(collection: CollectionState | None, catalog: Sequence[Mushroom] | None = None):
28
  def discover_mushroom(
29
  collection: CollectionState | None, catalog: Sequence[Mushroom] | None = None
@@ -50,6 +68,7 @@ def discover_mushroom(collection: CollectionState, catalog: Sequence[Mushroom] |
50
  return mushroom, current, history
51
 
52
 
 
53
  def myco_reply(message: str | None, history, current: MushroomState | None):
54
  def myco_reply(message: str | None, history: ChatHistory | None, current: MushroomState | None):
55
  def myco_reply(
@@ -82,6 +101,42 @@ def myco_reply(message: str, history: ChatHistory, current: MushroomState | None
82
  else:
83
  answer = "Let's explore first. The forest usually reveals a mushroom when we move slowly and listen."
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  next_history.append({"role": "assistant", "content": answer})
86
  return "", next_history
87
 
@@ -151,6 +206,17 @@ def study_current(current: MushroomState | None, history: ChatHistory) -> tuple[
151
  f"I studied the {current['name']} closely. New MycoDex note: "
152
  f"magic is now marked as **{studied['magic']}**. Still no tasting without certainty!"
153
  )
 
 
 
 
 
 
 
 
 
 
 
154
  return studied, [*current_history, {"role": "assistant", "content": message}]
155
 
156
 
@@ -175,6 +241,20 @@ def eat_current(current: MushroomState | None, history: ChatHistory | None) -> C
175
  f"Its edible field is still **{mushroom.edible}**, "
176
  "so the winning move is to study or collect it instead of eating it."
177
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  next_history.append({"role": "assistant", "content": message})
179
  return next_history
180
 
@@ -223,6 +303,7 @@ def _safe_history(history: ChatHistory | None) -> ChatHistory:
223
  return list(history or welcome_history())
224
 
225
 
 
226
  def _study_hint(rarity: str):
227
  def _study_hint(rarity: str) -> str:
228
  """Return a premium-feeling but cautious study result by rarity."""
 
1
  """Core Myco gameplay actions independent from Gradio."""
2
 
3
+ import random
4
+
5
+ from game.catalog import load_mushrooms
6
+ from game.state import collection_contains, mushroom_from_state, welcome_history
7
+
8
+
9
+ def choose_mushroom(catalog=None):
10
  from __future__ import annotations
11
 
12
  import random
 
31
  return random.choice(mushrooms)
32
 
33
 
34
+ def discover_mushroom(collection=None, catalog=None):
35
+ """Discover a mushroom and return the updated discovery state."""
36
+ current_collection = _safe_collection(collection)
37
+ mushroom = choose_mushroom(catalog)
38
+ current = mushroom.to_dict()
39
+ history = welcome_history()
40
+ history.append(
41
+ _assistant_message(
42
+ f"We found a {mushroom.name}! Ask me about it, then decide whether to "
43
+ f"eat, collect, or study it. Your MycoDex has {len(current_collection)} entries."
44
+ )
45
  def discover_mushroom(collection: CollectionState | None, catalog: Sequence[Mushroom] | None = None):
46
  def discover_mushroom(
47
  collection: CollectionState | None, catalog: Sequence[Mushroom] | None = None
 
68
  return mushroom, current, history
69
 
70
 
71
+ def myco_reply(message=None, history=None, current=None):
72
  def myco_reply(message: str | None, history, current: MushroomState | None):
73
  def myco_reply(message: str | None, history: ChatHistory | None, current: MushroomState | None):
74
  def myco_reply(
 
101
  else:
102
  answer = "Let's explore first. The forest usually reveals a mushroom when we move slowly and listen."
103
 
104
+ next_history.append(_assistant_message(answer))
105
+ return "", next_history
106
+
107
+
108
+ def collect_current(current=None, collection=None, history=None):
109
+ """Add the current mushroom to the MycoDex if it is not already collected."""
110
+ current_collection = _safe_collection(collection)
111
+ current_history = _safe_history(history)
112
+
113
+ if current is None:
114
+ return current_collection, _append_assistant(
115
+ current_history,
116
+ "Let's discover a mushroom before updating the MycoDex.",
117
+ )
118
+
119
+ if collection_contains(current_collection, current["name"]):
120
+ return current_collection, _append_assistant(
121
+ current_history,
122
+ f"{current['name']} is already safe in your MycoDex.",
123
+ )
124
+
125
+ updated_collection = [*current_collection, current]
126
+ return updated_collection, _append_assistant(
127
+ current_history,
128
+ f"Added {current['name']} to the MycoDex. Nice find!",
129
+ )
130
+
131
+
132
+ def study_current(current=None, history=None):
133
+ """Study the current mushroom to reveal one cautious field observation."""
134
+ current_history = _safe_history(history)
135
+ if current is None:
136
+ return None, _append_assistant(
137
+ current_history,
138
+ "Let's find a mushroom before we study anything.",
139
+ )
140
  next_history.append({"role": "assistant", "content": answer})
141
  return "", next_history
142
 
 
206
  f"I studied the {current['name']} closely. New MycoDex note: "
207
  f"magic is now marked as **{studied['magic']}**. Still no tasting without certainty!"
208
  )
209
+ return studied, _append_assistant(current_history, message)
210
+
211
+
212
+ def eat_current(current=None, history=None):
213
+ """Handle the Eat choice safely with Myco's companion personality."""
214
+ current_history = _safe_history(history)
215
+ if current is None:
216
+ return _append_assistant(
217
+ current_history,
218
+ "Let's discover a mushroom before making snack decisions.",
219
+ )
220
  return studied, [*current_history, {"role": "assistant", "content": message}]
221
 
222
 
 
241
  f"Its edible field is still **{mushroom.edible}**, "
242
  "so the winning move is to study or collect it instead of eating it."
243
  )
244
+ return _append_assistant(current_history, message)
245
+
246
+
247
+ def _assistant_message(content):
248
+ """Return one assistant chat message."""
249
+ return {"role": "assistant", "content": content}
250
+
251
+
252
+ def _append_assistant(history, content):
253
+ """Return chat history with one assistant message appended."""
254
+ return [*_safe_history(history), _assistant_message(content)]
255
+
256
+
257
+ def _safe_collection(collection):
258
  next_history.append({"role": "assistant", "content": message})
259
  return next_history
260
 
 
303
  return list(history or welcome_history())
304
 
305
 
306
+ def _study_hint(rarity):
307
  def _study_hint(rarity: str):
308
  def _study_hint(rarity: str) -> str:
309
  """Return a premium-feeling but cautious study result by rarity."""