Skip to content

Commit 7b1777a

Browse files
assert fixing and improving
1 parent ea5b2f9 commit 7b1777a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/poke_env/player/doubles_env.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def action_to_order(
137137
and battle.force_switch == [True, True]
138138
and 1 <= action[0] <= 6
139139
and 1 <= action[1] <= 6
140-
)
140+
), "invalid action"
141141
order1 = DoublesEnv._action_to_order_individual(action[0], battle, fake, 0)
142142
order2 = DoublesEnv._action_to_order_individual(action[1], battle, fake, 1)
143143
joined_orders = DoubleBattleOrder.join_orders(
@@ -159,6 +159,9 @@ def action_to_order(
159159
def _action_to_order_individual(
160160
action: np.int64, battle: DoubleBattle, fake: bool, pos: int
161161
) -> Optional[BattleOrder]:
162+
assert (
163+
battle.force_switch != [[False, True], [True, False]][pos] or action == 0
164+
), "invalid action"
162165
if action == 0:
163166
order = None
164167
elif action < 7:
@@ -243,7 +246,7 @@ def order_to_action(
243246
and battle.force_switch == [True, True]
244247
and isinstance(order.first_order, Pokemon)
245248
and isinstance(order.second_order, Pokemon)
246-
)
249+
), "invalid order"
247250
action1 = DoublesEnv._order_to_action_individual(
248251
order.first_order, battle, fake, 0
249252
)
@@ -261,6 +264,9 @@ def order_to_action(
261264
def _order_to_action_individual(
262265
order: Optional[BattleOrder], battle: DoubleBattle, fake: bool, pos: int
263266
) -> np.int64:
267+
assert (
268+
battle.force_switch != [[False, True], [True, False]][pos] or order is None
269+
), "invalid order"
264270
if order is None:
265271
action = 0
266272
elif isinstance(order, DefaultBattleOrder):

0 commit comments

Comments
 (0)