Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- game/engine.py +68 -36
game/engine.py
CHANGED
|
@@ -750,43 +750,75 @@ def eat_current(current=None, collection=None, history=None):
|
|
| 750 |
return coll, _append(hist, "assistant", reply)
|
| 751 |
|
| 752 |
|
| 753 |
-
def check_auto_pickup(new_pos_x, new_pos_y, current, collection):
|
| 754 |
-
"""
|
| 755 |
-
if
|
| 756 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 757 |
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 790 |
|
| 791 |
|
| 792 |
# Myco narrative
|
|
|
|
| 750 |
return coll, _append(hist, "assistant", reply)
|
| 751 |
|
| 752 |
|
| 753 |
+
def check_auto_pickup(new_pos_x, new_pos_y, current, collection, active_mushrooms=None):
|
| 754 |
+
"""
|
| 755 |
+
Check if Myco stepped on any mushroom in active_mushrooms.
|
| 756 |
+
Returns (current, collection, active_mushrooms) — all three updated.
|
| 757 |
+
"""
|
| 758 |
+
if active_mushrooms is None:
|
| 759 |
+
# Fallback: try reading from current dict (legacy path)
|
| 760 |
+
active_mushrooms = (current or {}).get("active_mushrooms", [])
|
| 761 |
|
| 762 |
+
if not active_mushrooms:
|
| 763 |
+
return current, collection, []
|
| 764 |
+
|
| 765 |
+
if current and (current.get("game_over") == "Yes" or current.get("picked") == "Yes"):
|
| 766 |
+
return current, collection, active_mushrooms
|
| 767 |
+
|
| 768 |
+
updated_mushrooms = list(active_mushrooms)
|
| 769 |
+
hit = None
|
| 770 |
+
|
| 771 |
+
for m in updated_mushrooms:
|
| 772 |
+
if m.get("picked") == "Yes":
|
| 773 |
+
continue
|
| 774 |
+
if int(m.get("mush_x", -1)) == int(new_pos_x) and \
|
| 775 |
+
int(m.get("mush_y", -1)) == int(new_pos_y):
|
| 776 |
+
hit = m
|
| 777 |
+
break
|
| 778 |
+
|
| 779 |
+
if hit is None:
|
| 780 |
+
return current, collection, updated_mushrooms
|
| 781 |
+
|
| 782 |
+
# Myco stepped on a mushroom
|
| 783 |
+
if hit.get("poison") == "Yes":
|
| 784 |
+
# Game over
|
| 785 |
+
updated_current = dict(current or {})
|
| 786 |
+
updated_current["game_over"] = "Yes"
|
| 787 |
+
updated_current["health"] = "0"
|
| 788 |
+
updated_current["encounter"] = f"💀 Myco stepped on toxic {hit['name']}! Game Over!"
|
| 789 |
+
updated_current["event_title"] = "Poison Shock!"
|
| 790 |
+
updated_current["reward_text"] = f"Poison! {POISON_PENALTY} spores · Game Over"
|
| 791 |
+
updated_current["score_total"] = str(max(0, _score_collection(collection) + POISON_PENALTY))
|
| 792 |
+
# Mark it picked so it disappears from scene
|
| 793 |
+
updated_mushrooms = [
|
| 794 |
+
{**m, "picked": "Yes"} if m.get("name") == hit.get("name") else m
|
| 795 |
+
for m in updated_mushrooms
|
| 796 |
+
]
|
| 797 |
+
return updated_current, collection, updated_mushrooms
|
| 798 |
+
|
| 799 |
+
# Safe mushroom — collect it
|
| 800 |
+
score_delta = RARITY_SCORE.get(hit.get("rarity", "Common"), 10)
|
| 801 |
+
new_score = _score_collection(collection) + score_delta
|
| 802 |
+
updated_mushrooms = [
|
| 803 |
+
{**m, "picked": "Yes"} if m.get("name") == hit.get("name") else m
|
| 804 |
+
for m in updated_mushrooms
|
| 805 |
+
]
|
| 806 |
+
collection = list(collection) + [hit]
|
| 807 |
+
|
| 808 |
+
updated_current = dict(current or {})
|
| 809 |
+
updated_current["score_total"] = str(new_score)
|
| 810 |
+
updated_current["encounter"] = f"💥 Collected {hit['name']}! +{score_delta} spores!"
|
| 811 |
+
updated_current["reward_text"] = f"+{score_delta} spores · {hit.get('rarity','Common')}"
|
| 812 |
+
updated_current["event_title"] = "Pickup!"
|
| 813 |
+
|
| 814 |
+
# Check if all mushrooms are now picked
|
| 815 |
+
remaining = [m for m in updated_mushrooms if m.get("picked") != "Yes"]
|
| 816 |
+
if not remaining:
|
| 817 |
+
updated_current["picked"] = "Yes"
|
| 818 |
+
updated_current["encounter"] = "Area clear! Search the next clearing!"
|
| 819 |
+
updated_current["event_title"] = "Clearing Purified"
|
| 820 |
+
|
| 821 |
+
return updated_current, collection, updated_mushrooms
|
| 822 |
|
| 823 |
|
| 824 |
# Myco narrative
|