-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_remote.py
65 lines (54 loc) · 2.86 KB
/
run_remote.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import argparse
import os
import asyncio
from poke_env import PlayerConfiguration, ShowdownServerConfiguration
from src.players.baseline_player import MaxBasePowerPlayer, BestDamagePlayer
from src.players.RuleBasedPlayer import RuleBasedPlayer
from src.players.MiniMaxPlayer import MiniMaxPlayer
from src.utilities import challenge_player, send_player_on_ladder
from src.minimax.heuristic.TeamHeuristic import TeamHeuristic
def parse_arguments(known=False):
parser = argparse.ArgumentParser()
parser.add_argument("--user", type=str, default="", help="the bot's username")
parser.add_argument("--password", type=str, default="", help="the bot's password")
parser.add_argument("--matches", type=int, default=1, help="the number of challenges that the bot will accept")
parser.add_argument("--player", type=str, default="RB",
help="the bot's playstyle, MBP MaxBasePower, BD BestDamage, RB RuleBased, MM MiniMax")
parser.add_argument("--ladder", action="store_true", help="let the bot play on the ladder")
parser.add_argument("--verbose", action="store_true", help="let the bot print its status at each turn")
parser.add_argument("--save", action="store_true", help="save the battle results in a csv file")
opt = parser.parse_known_args()[0] if known else parser.parse_args()
return opt
async def run_bot_online():
opt_parser = parse_arguments()
bot_username = opt_parser.user
bot_password = opt_parser.password
n_matches = opt_parser.matches
playstyle = opt_parser.player
save_results = opt_parser.save
if bot_username == "":
bot_username = os.getenv("BotAIF_username")
if bot_password == "":
bot_password = os.getenv("BotAIF_password")
player_config = PlayerConfiguration(bot_username, bot_password)
if playstyle == "MBP":
player = MaxBasePowerPlayer(player_configuration=player_config,
server_configuration=ShowdownServerConfiguration)
elif playstyle == "BD":
player = BestDamagePlayer(player_configuration=player_config, server_configuration=ShowdownServerConfiguration)
elif playstyle == "RB":
player = RuleBasedPlayer(player_configuration=player_config, server_configuration=ShowdownServerConfiguration)
elif playstyle == "MM":
heuristic = TeamHeuristic()
player = MiniMaxPlayer(player_configuration=player_config, server_configuration=ShowdownServerConfiguration,
heuristic=heuristic, max_depth=2)
else:
raise ValueError
player.verbose = opt_parser.verbose
if opt_parser.ladder:
await send_player_on_ladder(player, n_matches, True, save_results)
else:
await challenge_player(player, None, n_matches, False, save_results)
if __name__ == '__main__':
run_bot = asyncio.new_event_loop()
run_bot.run_until_complete(run_bot_online())