Spaces:
Running
Running
Updated the board visialization for the gradio display
Browse files
src/game_reasoning_arena/arena/envs/kuhn_poker_env.py
CHANGED
@@ -32,6 +32,54 @@ class KuhnPokerEnv(OpenSpielEnv):
|
|
32 |
"""
|
33 |
super().__init__(game, game_name, player_types, max_game_rounds, seed)
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
def _state_to_observation(self) -> Dict[int, Dict[str, Any]]:
|
36 |
"""Returns the observation for each agent in the game.
|
37 |
|
|
|
32 |
"""
|
33 |
super().__init__(game, game_name, player_types, max_game_rounds, seed)
|
34 |
|
35 |
+
def render_board(self, agent_id=0) -> str:
|
36 |
+
"""Return a human-readable summary of the current
|
37 |
+
Kuhn Poker state for Gradio display."""
|
38 |
+
state = self.state
|
39 |
+
if state.is_chance_node():
|
40 |
+
return "Cards are being dealt..."
|
41 |
+
|
42 |
+
legal_actions = state.legal_actions(agent_id)
|
43 |
+
tensor_observation = state.observation_tensor(agent_id)
|
44 |
+
private_card = self.extract_private_card_from_tensor(
|
45 |
+
tensor_observation
|
46 |
+
)
|
47 |
+
betting_history = self._get_betting_history(state)
|
48 |
+
total_pot = sum(tensor_observation[-2:])
|
49 |
+
player_contribution = tensor_observation[-2 + agent_id]
|
50 |
+
move_number = state.move_number()
|
51 |
+
|
52 |
+
# Detect if an opponent has already bet
|
53 |
+
previous_actions = state.history()
|
54 |
+
opponent_has_bet = 1 in previous_actions
|
55 |
+
|
56 |
+
# Define action labels dynamically based on game context
|
57 |
+
if opponent_has_bet:
|
58 |
+
action_labels = {
|
59 |
+
0: "Fold (give up and lose the pot)",
|
60 |
+
1: "Call (match the opponent's bet)"
|
61 |
+
}
|
62 |
+
else:
|
63 |
+
action_labels = {
|
64 |
+
0: "Check (stay in the game without betting)",
|
65 |
+
1: "Bet (add a chip to the pot)"
|
66 |
+
}
|
67 |
+
|
68 |
+
lines = [
|
69 |
+
f"Kuhn Poker — Player {agent_id}",
|
70 |
+
f"Private card: {private_card}",
|
71 |
+
f"Move number: {move_number}",
|
72 |
+
f"Betting history: {betting_history}",
|
73 |
+
f"Total pot: {total_pot} chips",
|
74 |
+
f"Your contribution: {player_contribution} chips",
|
75 |
+
"Available actions:"
|
76 |
+
]
|
77 |
+
for action in legal_actions:
|
78 |
+
lines.append(
|
79 |
+
f" {action}: {action_labels.get(action, str(action))}"
|
80 |
+
)
|
81 |
+
return "\n".join(lines)
|
82 |
+
|
83 |
def _state_to_observation(self) -> Dict[int, Dict[str, Any]]:
|
84 |
"""Returns the observation for each agent in the game.
|
85 |
|