Spaces:
Runtime error
Runtime error
Thereisnocowlevel
Browse files- backend/game/commands.py +1 -0
- backend/game/engine.py +13 -0
- backend/voice/command_parser.py +1 -0
backend/game/commands.py
CHANGED
|
@@ -26,6 +26,7 @@ class ActionType(str, Enum):
|
|
| 26 |
QUERY = "query"
|
| 27 |
QUERY_UNITS = "query_units" # zone and/or unit_type → returns unit_ids
|
| 28 |
ASSIGN_TO_GROUP = "assign_to_group" # group_index (1-3), unit_ids (from query_units)
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
# Unit selectors understood by the engine
|
|
|
|
| 26 |
QUERY = "query"
|
| 27 |
QUERY_UNITS = "query_units" # zone and/or unit_type → returns unit_ids
|
| 28 |
ASSIGN_TO_GROUP = "assign_to_group" # group_index (1-3), unit_ids (from query_units)
|
| 29 |
+
RESIGN = "resign" # abandon the game, opponent wins
|
| 30 |
|
| 31 |
|
| 32 |
# Unit selectors understood by the engine
|
backend/game/engine.py
CHANGED
|
@@ -1096,6 +1096,8 @@ class GameEngine:
|
|
| 1096 |
return self._cmd_query_units(player, action)
|
| 1097 |
if t == ActionType.ASSIGN_TO_GROUP:
|
| 1098 |
return self._cmd_assign_to_group(player, action)
|
|
|
|
|
|
|
| 1099 |
return ActionResult(
|
| 1100 |
action_type=t, success=False, data={"error": "unknown_action"}
|
| 1101 |
)
|
|
@@ -1491,6 +1493,17 @@ class GameEngine:
|
|
| 1491 |
data={"gi": gi, "n": len(valid_ids)},
|
| 1492 |
)
|
| 1493 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1494 |
# ------------------------------------------------------------------
|
| 1495 |
# Broadcast
|
| 1496 |
# ------------------------------------------------------------------
|
|
|
|
| 1096 |
return self._cmd_query_units(player, action)
|
| 1097 |
if t == ActionType.ASSIGN_TO_GROUP:
|
| 1098 |
return self._cmd_assign_to_group(player, action)
|
| 1099 |
+
if t == ActionType.RESIGN:
|
| 1100 |
+
return self._cmd_resign(player)
|
| 1101 |
return ActionResult(
|
| 1102 |
action_type=t, success=False, data={"error": "unknown_action"}
|
| 1103 |
)
|
|
|
|
| 1493 |
data={"gi": gi, "n": len(valid_ids)},
|
| 1494 |
)
|
| 1495 |
|
| 1496 |
+
def _cmd_resign(self, player: PlayerState) -> ActionResult:
|
| 1497 |
+
"""Player forfeits — opponent is declared winner immediately."""
|
| 1498 |
+
opponent_id = next(
|
| 1499 |
+
(pid for pid in self.state.players if pid != player.player_id), None
|
| 1500 |
+
)
|
| 1501 |
+
if not opponent_id:
|
| 1502 |
+
return ActionResult(action_type="resign", success=False, data={"error": "no_opponent"})
|
| 1503 |
+
self.state.phase = GamePhase.GAME_OVER
|
| 1504 |
+
self.state.winner = opponent_id
|
| 1505 |
+
return ActionResult(action_type="resign", success=True, data={})
|
| 1506 |
+
|
| 1507 |
# ------------------------------------------------------------------
|
| 1508 |
# Broadcast
|
| 1509 |
# ------------------------------------------------------------------
|
backend/voice/command_parser.py
CHANGED
|
@@ -45,6 +45,7 @@ supply_depot, barracks, engineering_bay, refinery, factory, armory, starport
|
|
| 45 |
- query : information sur l'état → aucun champ requis
|
| 46 |
- query_units : lister les IDs d'unités (pour affectation aux groupes) → champs optionnels: target_zone, unit_type
|
| 47 |
- assign_to_group : affecter des unités à un groupe (1, 2 ou 3) → champs: group_index (1-3). Utilise le résultat du query_units précédent si unit_ids vide. Pour "mets mes marines dans le groupe 1", génère d'abord query_units (unit_type: marine) puis assign_to_group (group_index: 1).
|
|
|
|
| 48 |
|
| 49 |
=== SÉLECTEURS D'UNITÉS ===
|
| 50 |
all, all_military, all_marines, all_medics, all_goliaths, all_tanks, all_wraiths, all_scv, idle_scv, most_damaged
|
|
|
|
| 45 |
- query : information sur l'état → aucun champ requis
|
| 46 |
- query_units : lister les IDs d'unités (pour affectation aux groupes) → champs optionnels: target_zone, unit_type
|
| 47 |
- assign_to_group : affecter des unités à un groupe (1, 2 ou 3) → champs: group_index (1-3). Utilise le résultat du query_units précédent si unit_ids vide. Pour "mets mes marines dans le groupe 1", génère d'abord query_units (unit_type: marine) puis assign_to_group (group_index: 1).
|
| 48 |
+
- resign : abandonner la partie (l'adversaire gagne) → aucun champ requis. Utiliser quand le joueur dit "j'abandonne", "je capitule", "je me rends", "I resign", "I give up", etc.
|
| 49 |
|
| 50 |
=== SÉLECTEURS D'UNITÉS ===
|
| 51 |
all, all_military, all_marines, all_medics, all_goliaths, all_tanks, all_wraiths, all_scv, idle_scv, most_damaged
|