byte-vortex commited on
Commit
3702be0
·
verified ·
1 Parent(s): caad1dd

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. 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
- """Arcade collision rules that cleanly update score text safely."""
755
- if not current or current.get("game_over") == "Yes" or current.get("picked") == "Yes":
756
- return current, collection
 
 
 
 
757
 
758
- mushrooms = current.get("active_mushrooms", [])
759
- all_picked = True
760
-
761
- for m in mushrooms:
762
- if m.get("picked") == "No":
763
- # Check if Myco stepped on this coordinate
764
- if new_pos_x == m["mush_x"] and new_pos_y == m["mush_y"]:
765
- if m["poison"] == "Yes":
766
- current["game_over"] = "Yes"
767
- current["encounter"] = f"💀 Oh no! Myco stepped directly onto a toxic {m['name']}!"
768
- current["event_title"] = "Poison Shock!"
769
- return current, collection
770
- else:
771
- m["picked"] = "Yes"
772
- current["encounter"] = f"💥 Blip! Collected a rare {m['name']}!"
773
-
774
- # Safely tick up scores inside the state without crashing types
775
- current_score = int(current.get("score_total", "0")) + 15
776
- current["score_total"] = str(current_score)
777
- current["reward_text"] = f"+15 Spores from {m['name']}!"
778
-
779
- collection.append(m)
780
- else:
781
- # This one hasn't been collected yet
782
- all_picked = False
783
-
784
- if all_picked and mushrooms:
785
- current["picked"] = "Yes"
786
- current["encounter"] = "Area clear! Click Search Clearing to spawn the next cluster."
787
- current["event_title"] = "Clearing Purified"
788
-
789
- return current, collection
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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