Пример #1
0
    def setUp(self):
        self.battle = Battle(None)
        self.battle.user.name = 'p1'
        self.battle.opponent.name = 'p2'

        self.opponent_active = Pokemon('caterpie', 100)
        self.battle.opponent.active = self.opponent_active
Пример #2
0
async def parse_message(ps_websocket_client, msg, battles):
    split_msg = msg.split('|')

    if split_msg[1].strip() == 'updatechallenges':
        await ps_websocket_client.accept_challenge(split_msg, battles)
        return

    if split_msg[1].strip() == 'init' and split_msg[2].strip() == 'battle':
        battle = None
        for curr in battles:
            if curr.battle_tag == 'pending':
                battle = curr
                battle.battle_tag = split_msg[0].replace('>', '').strip()
                user_name = split_msg[-1].replace('☆', '').strip()
                battle.opponent.account_name = split_msg[4].replace(
                    user_name, '').replace('vs.', '').strip()
                battle.opponent.name = 'pending'
                break
        if battle == None:
            logger.debug("ERROR: can't find pending slot")
        return

    if 'battle' in split_msg[0]:
        battle = None
        i = 0
        for curr in battles:
            if curr.battle_tag == split_msg[0].replace('>', '').strip():
                battle = curr
                break
            i += 1
        if battle == None:
            logger.debug("ERROR: can't find battle slot")
            return
        if battle.opponent.name == 'pending':
            await initialize_battle(ps_websocket_client, battle, split_msg)
        elif battle.started == False:
            if battle.battle_type == constants.STANDARD_BATTLE:
                await run_start_standard_battle(ps_websocket_client, battle,
                                                msg)
                return
            else:
                await run_start_random_battle(ps_websocket_client, battle, msg)
                return
        else:
            ended = await pokemon_battle(ps_websocket_client, battle, msg)
            if (ended):
                battles[i] = Battle('empty')
            return

    if split_msg[1].strip() == 'pm' and '$' in split_msg[4]:
        await ps_websocket_client.parse_command(split_msg, battles)
        return
Пример #3
0
async def _initialize_battle_with_tag(ps_websocket_client: PSWebsocketClient):
    battle_tag, opponent_name = await get_battle_tag_and_opponent(ps_websocket_client)
    while True:
        msg = await ps_websocket_client.receive_message()
        split_msg = msg.split('|')
        if split_msg[1].strip() == 'request' and split_msg[2].strip():
            user_json = json.loads(split_msg[2].strip('\''))
            user_id = user_json[constants.SIDE][constants.ID]
            opponent_id = constants.ID_LOOKUP[user_id]
            battle = Battle(battle_tag)
            battle.opponent.name = opponent_id
            battle.opponent.account_name = opponent_name
            return battle, opponent_id, user_json
Пример #4
0
    def setUp(self):
        self.battle = Battle(None)
        self.battle.user.name = 'p1'
        self.battle.opponent.name = 'p2'

        self.user_active = Pokemon('caterpie', 100)
        self.opponent_active = Pokemon('caterpie', 100)

        # manually set hp to 200 for testing purposes
        self.opponent_active.max_hp = 200
        self.opponent_active.hp = 200

        self.battle.opponent.active = self.opponent_active
        self.battle.user.active = self.user_active
Пример #5
0
    def setUp(self):
        self.battle = Battle(None)
        self.battle.user.name = 'p1'
        self.battle.opponent.name = 'p2'

        self.opponent_active = Pokemon('caterpie', 100)
        self.battle.opponent.active = self.opponent_active
        self.battle.opponent.active.ability = None

        self.user_active = Pokemon('weedle', 100)
        self.battle.user.active = self.user_active

        self.username = "******"

        self.battle.username = self.username
Пример #6
0
async def showdown():
    env = Env()
    env.read_env()
    config.log_to_file = env.bool("LOG_TO_FILE", config.log_to_file)
    config.save_replay = env.bool("SAVE_REPLAY", config.save_replay)
    config.decision_method = env("DECISION_METHOD", config.decision_method)
    config.use_relative_weights = env.bool("USE_RELATIVE_WEIGHTS",
                                           config.use_relative_weights)
    config.gambit_exe_path = env("GAMBIT_PATH", config.gambit_exe_path)
    config.search_depth = int(env("MAX_SEARCH_DEPTH", config.search_depth))
    config.greeting_message = env("GREETING_MESSAGE", config.greeting_message)
    config.battle_ending_message = env("BATTLE_OVER_MESSAGE",
                                       config.battle_ending_message)
    logger.setLevel(env("LOG_LEVEL", "DEBUG"))
    websocket_uri = env("WEBSOCKET_URI", "sim.smogon.com:8000")
    username = env("PS_USERNAME")
    password = env("PS_PASSWORD", "")
    bot_mode = env("BOT_MODE")
    team_name = env("TEAM_NAME", None)
    pokemon_mode = env("POKEMON_MODE", constants.DEFAULT_MODE)

    apply_mods(pokemon_mode)
    original_pokedex = deepcopy(pokedex)
    original_move_json = deepcopy(all_move_json)

    ps_websocket_client = await PSWebsocketClient.create(
        username, password, websocket_uri)
    await ps_websocket_client.login()

    battles = []
    for i in range(5):
        battles.append(Battle('empty'))

    while True:
        msg = await ps_websocket_client.receive_message()
        """ loop = asyncio.get_event_loop()
        t = threading.Thread(target = thr, args=(ps_websocket_client, msg, battles))
        t.start() """

        await parse_message(ps_websocket_client, msg, battles)
Пример #7
0
 def setUp(self):
     self.battle = Battle(None)
     self.battle.user.active = Pokemon('Pikachu', 100)
     self.battle.opponent.active = Pokemon('Pikachu', 100)
Пример #8
0
class TestBattle(unittest.TestCase):
    def setUp(self):
        self.battle = Battle(None)
        self.battle.user.active = Pokemon('Pikachu', 100)
        self.battle.opponent.active = Pokemon('Pikachu', 100)

    def test_gets_only_move_for_both_sides(self):
        self.battle.user.active.moves = [Move('thunderbolt')]
        self.battle.opponent.active.moves = [Move('thunderbolt')]

        expected_options = ['thunderbolt'], ['thunderbolt']

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_gets_multiple_moves_for_both_sides(self):
        self.battle.user.active.moves = [
            Move('thunderbolt'),
            Move('agility'),
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('thunderbolt'),
            Move('swift'),
            Move('dragondance'),
            Move('stealthrock'),
        ]

        expected_options = (['thunderbolt', 'agility', 'tackle', 'charm'], [
            'thunderbolt', 'swift', 'dragondance', 'stealthrock'
        ])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_gets_one_switch_and_splash(self):
        self.battle.user.active.moves = []
        self.battle.opponent.active.moves = []

        self.battle.user.reserve = [Pokemon('caterpie', 100)]
        self.battle.opponent.reserve = [Pokemon('caterpie', 100)]

        expected_options = (['switch caterpie'], ['splash', 'switch caterpie'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_gets_multiple_switches_and_splash(self):
        self.battle.user.active.moves = []
        self.battle.opponent.active.moves = []

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = (['switch caterpie', 'switch spinarak'],
                            ['splash', 'switch caterpie', 'switch houndour'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_gets_multiple_switches_and_multiple_moves(self):
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('thunderbolt'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = ([
            'tackle', 'charm', 'switch caterpie', 'switch spinarak'
        ], ['tackle', 'thunderbolt', 'switch caterpie', 'switch houndour'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_ignores_moves_and_gives_opponent_no_option_when_user_active_is_dead(
            self):
        self.battle.user.active.hp = 0
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('thunderbolt'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = (['switch caterpie', 'switch spinarak'], ['splash'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_ignores_moves_and_gives_opponent_no_option_when_force_switch_is_true(
            self):
        self.battle.force_switch = True
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('thunderbolt'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = (['switch caterpie', 'switch spinarak'], ['splash'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_gives_no_options_for_user_and_only_switches_for_opponent_when_wait_is_true(
            self):
        self.battle.wait = True
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('thunderbolt'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = (['splash'], ['switch caterpie', 'switch houndour'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_gives_no_options_for_user_and_only_switches_for_opponent_when_opponent_active_is_dead(
            self):
        self.battle.opponent.active.hp = 0
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('thunderbolt'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = (['splash'], ['switch caterpie', 'switch houndour'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_double_fainted_active_pokemon(self):
        self.battle.user.active.hp = 0
        self.battle.opponent.active.hp = 0
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('thunderbolt'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = (['switch caterpie', 'switch spinarak'],
                            ['switch caterpie', 'switch houndour'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_opponent_has_no_moves_results_in_splash_or_switches(self):
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = []

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [Pokemon('caterpie', 100)]

        expected_options = ([
            'tackle', 'charm', 'switch caterpie', 'switch spinarak'
        ], [
            'splash',
            'switch caterpie',
        ])

        self.assertEqual(expected_options, self.battle.get_all_options())
Пример #9
0
class TestBattle(unittest.TestCase):
    def setUp(self):
        self.battle = Battle(None)
        self.battle.user.active = Pokemon('Pikachu', 100)
        self.battle.opponent.active = Pokemon('Pikachu', 100)

    def test_gets_only_move_for_both_sides(self):
        self.battle.user.active.moves = [Move('thunderbolt')]
        self.battle.opponent.active.moves = [Move('thunderbolt')]

        expected_options = ['thunderbolt'], ['thunderbolt']

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_gets_multiple_moves_for_both_sides(self):
        self.battle.user.active.moves = [
            Move('thunderbolt'),
            Move('agility'),
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('thunderbolt'),
            Move('swift'),
            Move('dragondance'),
            Move('stealthrock'),
        ]

        expected_options = (['thunderbolt', 'agility', 'tackle', 'charm'], [
            'thunderbolt', 'swift', 'dragondance', 'stealthrock'
        ])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_gets_one_switch_and_splash(self):
        self.battle.user.active.moves = []
        self.battle.opponent.active.moves = []

        self.battle.user.reserve = [Pokemon('caterpie', 100)]
        self.battle.opponent.reserve = [Pokemon('caterpie', 100)]

        expected_options = (['switch caterpie'], ['splash', 'switch caterpie'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_gets_multiple_switches_and_splash(self):
        self.battle.user.active.moves = []
        self.battle.opponent.active.moves = []

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = (['switch caterpie', 'switch spinarak'],
                            ['splash', 'switch caterpie', 'switch houndour'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_gets_multiple_switches_and_multiple_moves(self):
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('thunderbolt'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = ([
            'tackle', 'charm', 'switch caterpie', 'switch spinarak'
        ], ['tackle', 'thunderbolt', 'switch caterpie', 'switch houndour'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_ignores_moves_and_gives_opponent_no_option_when_user_active_is_dead(
            self):
        self.battle.user.active.hp = 0
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('thunderbolt'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = (['switch caterpie', 'switch spinarak'], ['splash'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_ignores_moves_and_gives_opponent_no_option_when_force_switch_is_true(
            self):
        self.battle.force_switch = True
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('thunderbolt'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = (['switch caterpie', 'switch spinarak'], ['splash'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_gives_no_options_for_user_and_only_switches_for_opponent_when_wait_is_true(
            self):
        self.battle.wait = True
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('thunderbolt'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = (['splash'], ['switch caterpie', 'switch houndour'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_gives_no_options_for_user_and_only_switches_for_opponent_when_opponent_active_is_dead(
            self):
        self.battle.opponent.active.hp = 0
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('thunderbolt'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = (['splash'], ['switch caterpie', 'switch houndour'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_double_fainted_active_pokemon(self):
        self.battle.user.active.hp = 0
        self.battle.opponent.active.hp = 0
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('thunderbolt'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('houndour', 100)
        ]

        expected_options = (['switch caterpie', 'switch spinarak'],
                            ['switch caterpie', 'switch houndour'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_opponent_has_no_moves_results_in_splash_or_switches(self):
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]
        self.battle.opponent.active.moves = []

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [Pokemon('caterpie', 100)]

        expected_options = ([
            'tackle', 'charm', 'switch caterpie', 'switch spinarak'
        ], [
            'splash',
            'switch caterpie',
        ])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_opponent_has_moves_when_uturn_moves_first(self):
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
            Move('uturn'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [Pokemon('caterpie', 100)]

        # using uturn on the previous turn would cause force_switch to be True
        self.battle.force_switch = True

        self.battle.turn = 5

        self.battle.user.last_used_move = LastUsedMove(
            move='uturn',
            pokemon_name='pikachu',
            turn=5,
        )

        # the opponent's last move would have been from the turn before (turn 4), meaning it hasn't moved yet
        self.battle.opponent.last_used_move = LastUsedMove(
            move='tackle', pokemon_name='pikachu', turn=4)

        expected_options = (['switch caterpie', 'switch spinarak'], [
            'tackle',
            'charm',
        ])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_opponent_has_no_moves_when_uturn_moves_second(self):
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
            Move('uturn'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [Pokemon('caterpie', 100)]

        # using uturn on the previous turn would cause force_switch to be True
        self.battle.force_switch = True

        self.battle.turn = 5

        self.battle.user.last_used_move = LastUsedMove(
            move='uturn',
            pokemon_name='pikachu',
            turn=5,
        )

        self.battle.opponent.last_used_move = LastUsedMove(
            move='tackle', pokemon_name='pikachu', turn=5)

        expected_options = (['switch caterpie', 'switch spinarak'], ['splash'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_opponent_has_no_moves_when_uturn_happens_after_switch(self):
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
            Move('uturn'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [Pokemon('caterpie', 100)]

        # using uturn on the previous turn would cause force_switch to be True
        self.battle.force_switch = True

        self.battle.turn = 5

        self.battle.user.last_used_move = LastUsedMove(
            move='uturn',
            pokemon_name='pikachu',
            turn=5,
        )

        self.battle.opponent.last_used_move = LastUsedMove(
            move='switch pikachu', pokemon_name=None, turn=5)

        expected_options = (['switch caterpie', 'switch spinarak'], ['splash'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_opponent_has_no_moves_when_uturn_kills_and_opponent_has_not_moved_yet(
            self):
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
            Move('uturn'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [Pokemon('caterpie', 100)]

        # using uturn on the previous turn would cause force_switch to be True
        self.battle.force_switch = True

        # opponent has died from uturn
        self.battle.opponent.active.hp = 0

        self.battle.turn = 5

        self.battle.user.last_used_move = LastUsedMove(
            move='uturn',
            pokemon_name='pikachu',
            turn=5,
        )

        # the opponent's last move would have been from the turn before (turn 4), meaning it hasn't moved yet
        self.battle.opponent.last_used_move = LastUsedMove(
            move='tackle', pokemon_name='pikachu', turn=4)

        expected_options = (['switch caterpie', 'switch spinarak'], ['splash'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_opponent_has_no_moves_when_uturn_kills_and_opponent_has_already_moved(
            self):
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
            Move('uturn'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [Pokemon('caterpie', 100)]

        # using uturn on the previous turn would cause force_switch to be True
        self.battle.force_switch = True

        # opponent has died from uturn
        self.battle.opponent.active.hp = 0

        self.battle.turn = 5

        self.battle.user.last_used_move = LastUsedMove(
            move='uturn',
            pokemon_name='pikachu',
            turn=5,
        )

        # the opponent's last move would have been from the turn before (turn 4), meaning it hasn't moved yet
        self.battle.opponent.last_used_move = LastUsedMove(
            move='tackle', pokemon_name='pikachu', turn=5)

        expected_options = (['switch caterpie', 'switch spinarak'], ['splash'])

        self.assertEqual(expected_options, self.battle.get_all_options())

    def test_opponent_has_no_moves_when_uturn_kills_and_opponent_has_already_switched_in(
            self):
        self.battle.user.active.moves = [
            Move('tackle'),
            Move('charm'),
            Move('uturn'),
        ]
        self.battle.opponent.active.moves = [
            Move('tackle'),
            Move('charm'),
        ]

        self.battle.user.reserve = [
            Pokemon('caterpie', 100),
            Pokemon('spinarak', 100)
        ]
        self.battle.opponent.reserve = [Pokemon('caterpie', 100)]

        # using uturn on the previous turn would cause force_switch to be True
        self.battle.force_switch = True

        # opponent has died from uturn
        self.battle.opponent.active.hp = 0

        self.battle.turn = 5

        self.battle.user.last_used_move = LastUsedMove(
            move='uturn',
            pokemon_name='pikachu',
            turn=5,
        )

        # the opponent's last move would have been from the turn before (turn 4), meaning it hasn't moved yet
        self.battle.opponent.last_used_move = LastUsedMove(
            move='switch pikachu', pokemon_name=None, turn=5)

        expected_options = (['switch caterpie', 'switch spinarak'], ['splash'])

        self.assertEqual(expected_options, self.battle.get_all_options())
Пример #10
0
 def setUp(self):
     self.battle = Battle(None)
     self.battle.user.active = Pokemon("pikachu", 100)
     self.request_json = {
         "active": [{
             "moves": [{
                 "move": "Storm Throw",
                 "id": "stormthrow",
                 "pp": 16,
                 "maxpp": 16,
                 "target": "normal",
                 "disabled": False
             }, {
                 "move": "Ice Punch",
                 "id": "icepunch",
                 "pp": 24,
                 "maxpp": 24,
                 "target": "normal",
                 "disabled": False
             }, {
                 "move": "Bulk Up",
                 "id": "bulkup",
                 "pp": 32,
                 "maxpp": 32,
                 "target": "self",
                 "disabled": False
             }, {
                 "move": "Knock Off",
                 "id": "knockoff",
                 "pp": 32,
                 "maxpp": 32,
                 "target": "normal",
                 "disabled": False
             }]
         }],
         "side": {
             "name":
             "NiceNameNerd",
             "id":
             "p1",
             "pokemon": [{
                 "ident":
                 "p1: Throh",
                 "details":
                 "Throh, L83, M",
                 "condition":
                 "335/335",
                 "active":
                 True,
                 "stats": {
                     "atk": 214,
                     "def": 189,
                     "spa": 97,
                     "spd": 189,
                     "spe": 122
                 },
                 "moves": ["stormthrow", "icepunch", "bulkup", "knockoff"],
                 "baseAbility":
                 "moldbreaker",
                 "item":
                 "leftovers",
                 "pokeball":
                 "pokeball",
                 "ability":
                 "moldbreaker"
             }, {
                 "ident":
                 "p1: Empoleon",
                 "details":
                 "Empoleon, L77, F",
                 "condition":
                 "256/256",
                 "active":
                 False,
                 "stats": {
                     "atk": 137,
                     "def": 180,
                     "spa": 215,
                     "spd": 200,
                     "spe": 137
                 },
                 "moves": ["icebeam", "grassknot", "scald", "flashcannon"],
                 "baseAbility":
                 "torrent",
                 "item":
                 "choicespecs",
                 "pokeball":
                 "pokeball",
                 "ability":
                 "torrent"
             }, {
                 "ident":
                 "p1: Emboar",
                 "details":
                 "Emboar, L79, M",
                 "condition":
                 "303/303",
                 "active":
                 False,
                 "stats": {
                     "atk": 240,
                     "def": 148,
                     "spa": 204,
                     "spd": 148,
                     "spe": 148
                 },
                 "moves":
                 ["headsmash", "superpower", "flareblitz", "grassknot"],
                 "baseAbility":
                 "reckless",
                 "item":
                 "assaultvest",
                 "pokeball":
                 "pokeball",
                 "ability":
                 "reckless"
             }, {
                 "ident":
                 "p1: Zoroark",
                 "details":
                 "Zoroark, L77, M",
                 "condition":
                 "219/219",
                 "active":
                 False,
                 "stats": {
                     "atk": 166,
                     "def": 137,
                     "spa": 229,
                     "spd": 137,
                     "spe": 206
                 },
                 "moves":
                 ["sludgebomb", "darkpulse", "flamethrower", "focusblast"],
                 "baseAbility":
                 "illusion",
                 "item":
                 "choicespecs",
                 "pokeball":
                 "pokeball",
                 "ability":
                 "illusion"
             }, {
                 "ident":
                 "p1: Reuniclus",
                 "details":
                 "Reuniclus, L78, M",
                 "condition":
                 "300/300",
                 "active":
                 False,
                 "stats": {
                     "atk": 106,
                     "def": 162,
                     "spa": 240,
                     "spd": 178,
                     "spe": 92
                 },
                 "moves": ["calmmind", "shadowball", "psyshock", "recover"],
                 "baseAbility":
                 "magicguard",
                 "item":
                 "lifeorb",
                 "pokeball":
                 "pokeball",
                 "ability":
                 "magicguard"
             }, {
                 "ident":
                 "p1: Moltres",
                 "details":
                 "Moltres, L77",
                 "condition":
                 "265/265",
                 "active":
                 False,
                 "stats": {
                     "atk": 159,
                     "def": 183,
                     "spa": 237,
                     "spd": 175,
                     "spe": 183
                 },
                 "moves": ["fireblast", "toxic", "hurricane", "roost"],
                 "baseAbility":
                 "flamebody",
                 "item":
                 "leftovers",
                 "pokeball":
                 "pokeball",
                 "ability":
                 "flamebody"
             }]
         },
         "rqid":
         2
     }