Skip to content

Commit 5478ede

Browse files
committed
fix: action params format
1 parent 56c7c80 commit 5478ede

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

bots/example.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
[
1616
# This sequence of plays is winning for the first round
1717
# for the seed "EXAMPLE" and the deck "Red Deck" with stake 1.
18-
{"action": Actions.DISCARD_HAND, "args": [2, 3, 4, 6]},
19-
{"action": Actions.DISCARD_HAND, "args": [1, 2, 6, 8]},
20-
{"action": Actions.PLAY_HAND, "args": [2, 3, 5, 6, 7]},
21-
{"action": Actions.PLAY_HAND, "args": [3, 4, 7, 8]},
18+
{"action": Actions.DISCARD_HAND, "args": [[2, 3, 4, 6]]},
19+
{"action": Actions.DISCARD_HAND, "args": [[1, 2, 6, 8]]},
20+
{"action": Actions.PLAY_HAND, "args": [[2, 3, 5, 6, 7]]},
21+
{"action": Actions.PLAY_HAND, "args": [[3, 4, 7, 8]]},
2222
]
2323
)
2424

@@ -103,7 +103,7 @@ def sell_jokers(self, env: dict[str, Any]) -> ActionSchema:
103103
Returns:
104104
ActionCall: Action to sell jokers with empty list.
105105
"""
106-
return {"action": Actions.SELL_JOKER, "args": []}
106+
return {"action": Actions.SELL_JOKER, "args": [[]]}
107107

108108
def rearrange_jokers(self, env: dict[str, Any]) -> ActionSchema:
109109
"""Don't rearrange jokers.
@@ -114,7 +114,7 @@ def rearrange_jokers(self, env: dict[str, Any]) -> ActionSchema:
114114
Returns:
115115
ActionCall: Action to rearrange jokers with empty list.
116116
"""
117-
return {"action": Actions.REARRANGE_JOKERS, "args": []}
117+
return {"action": Actions.REARRANGE_JOKERS, "args": [[]]}
118118

119119
def use_or_sell_consumables(self, env: dict[str, Any]) -> ActionSchema:
120120
"""Don't use consumables.
@@ -125,7 +125,7 @@ def use_or_sell_consumables(self, env: dict[str, Any]) -> ActionSchema:
125125
Returns:
126126
ActionCall: Action to use consumables with empty list.
127127
"""
128-
return {"action": Actions.USE_CONSUMABLE, "args": []}
128+
return {"action": Actions.USE_CONSUMABLE, "args": [[]]}
129129

130130
def rearrange_consumables(self, env: dict[str, Any]) -> ActionSchema:
131131
"""Don't rearrange consumables.
@@ -136,7 +136,7 @@ def rearrange_consumables(self, env: dict[str, Any]) -> ActionSchema:
136136
Returns:
137137
ActionCall: Action to rearrange consumables with empty list.
138138
"""
139-
return {"action": Actions.REARRANGE_CONSUMABLES, "args": []}
139+
return {"action": Actions.REARRANGE_CONSUMABLES, "args": [[]]}
140140

141141
def rearrange_hand(self, env: dict[str, Any]) -> ActionSchema:
142142
"""Don't rearrange hand.
@@ -147,7 +147,7 @@ def rearrange_hand(self, env: dict[str, Any]) -> ActionSchema:
147147
Returns:
148148
ActionCall: Action to rearrange hand with empty list.
149149
"""
150-
return {"action": Actions.REARRANGE_HAND, "args": []}
150+
return {"action": Actions.REARRANGE_HAND, "args": [[]]}
151151

152152

153153
def main() -> None:
@@ -165,7 +165,7 @@ def main() -> None:
165165
# Configure logging with the specified level
166166
configure_bot_logging(args.log)
167167

168-
bot = ExampleBot()
168+
bot = ExampleBot(deck=Decks.BLUE, stake=Stakes.WHITE, seed="EXAMPLE")
169169
bot.running = True
170170
bot.run()
171171

src/balatrobot/base.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ActionSchema(TypedDict):
1313
"""Schema for action dictionary with name and arguments fields."""
1414

1515
action: Actions
16-
args: list[Any] | None
16+
args: list[list[Any] | Any] | None
1717

1818

1919
class Bot(ABC):
@@ -216,10 +216,11 @@ def _action_to_action_str(self, action: ActionSchema) -> str:
216216
# Add arguments if present
217217
args = action.get("args")
218218
if args:
219-
if isinstance(args, list):
220-
result.append(",".join([str(arg) for arg in args]))
221-
else:
222-
result.append(str(args))
219+
for arg in args:
220+
if isinstance(arg, list):
221+
result.append(",".join([str(a) for a in arg]))
222+
else:
223+
result.append(str(arg))
223224

224225
return "|".join(result)
225226

@@ -301,6 +302,7 @@ def run_step(self) -> None:
301302
action = self.chooseaction(env)
302303
if action:
303304
action_str = self._action_to_action_str(action)
305+
self.logger.debug("Sending action: %s", action_str)
304306
self.sock.send(bytes(action_str, "utf-8"))
305307
else:
306308
raise ValueError("All actions must return a value!")

0 commit comments

Comments
 (0)