# -*- coding: utf-8 -*-
from poke_env.environment.battle import Battle
from poke_env.environment.move import Move
from poke_env.environment.pokemon import Pokemon
from poke_env.environment.status import Status
from poke_env.player.env_player import EnvPlayer
from poke_env.player.env_player import Gen7EnvSinglePlayer

from poke_env.player_configuration import PlayerConfiguration
from poke_env.server_configuration import ServerConfiguration
from unittest.mock import patch


player_configuration = PlayerConfiguration("username", "password")
server_configuration = ServerConfiguration("server.url", "auth.url")


class CustomEnvPlayer(EnvPlayer):
    def embed_battle(self, battle):
        return None

    def _action_to_move(self, action, battle):
        return Gen7EnvSinglePlayer._action_to_move(self, action, battle)

    @property
    def action_space(self):
        return Gen7EnvSinglePlayer._ACTION_SPACE


def test_init():
    player = CustomEnvPlayer(
Example #2
0
import time
import numpy as np

from poke_env.player.player import Player
from poke_env.player.random_player import RandomPlayer
from poke_env.player.utils import cross_evaluate
from poke_env.player_configuration import PlayerConfiguration
from poke_env.server_configuration import ServerConfiguration
from poke_env.server_configuration import ShowdownServerConfiguration


my_player_config = PlayerConfiguration("A80VE", "123456")
# If your server is accessible at my.custom.host:5432, and your authentication
# endpoint is authentication-endpoint.com/action.php?
my_server_config = ServerConfiguration(
    "https://china.psim.us/",
    "authentication-endpoint.com/action.php?"
)


class MaxDamagePlayer(Player):

    def switch(self, battle):
        if (len(battle.available_switches) == 0):
            return self.choose_random_move(battle)
        max_type_adv = -np.inf
        switch = None
        for pokemon in battle.available_switches:
            curr_type_adv = teampreview_performance(
                pokemon, battle.opponent_active_pokemon)
            if (curr_type_adv > max_type_adv):
                max_type_adv = curr_type_adv
Example #3
0
        # Not sure what to do?
        return self.choose_random_move(battle)


# This will work on servers that do not require authentication, which is the
# case of the server launched in our 'Getting Started' section
my_player_config = PlayerConfiguration("my_username", None)

# This object can be used with a player connecting to a server using authentication
# The user 'my_username' must exist and have 'super-secret-password' as his password
my_player_config = PlayerConfiguration("my_username", "super-secret-password")

# If your server is accessible at my.custom.host:5432, and your authentication
# endpoint is authentication-endpoint.com/action.php?
my_server_config = ServerConfiguration(
    "my.custom.host:5432", "authentication-endpoint.com/action.php?")

# You can now use my_server_config with a Player object


# Create a MaxDamagePlayer
class MaxDamagePlayer(Player):
    """
    Player that aims to achieve max damage
    """
    def choose_move(self, battle):
        # If the player can attack, it will
        if battle.available_moves:
            # Finds the best move among available ones
            best_move = max(battle.available_moves,
                            key=lambda move: move.base_power)