{"id":244,"date":"2025-07-23T02:50:12","date_gmt":"2025-07-23T02:50:12","guid":{"rendered":"https:\/\/deskgadgetreviews.com\/?p=244"},"modified":"2025-07-23T02:50:46","modified_gmt":"2025-07-23T02:50:46","slug":"pokemonai-part2","status":"publish","type":"post","link":"https:\/\/deskgadgetreviews.com\/index.php\/2025\/07\/23\/pokemonai-part2\/","title":{"rendered":"\u30dd\u30b1\u30e2\u30f3\u306ePT\u9078\u5b9aAI\u3092\u4f5c\u308d\u3046\uff01\u3010Part2\u3011"},"content":{"rendered":"\n<p>\u3055\u3066\u3001Part1\u3067\u306fShowdown\u306e\u30ed\u30fc\u30ab\u30eb\u30b5\u30fc\u30d0\u30fc\u3092\u69cb\u7bc9\u3057\u307e\u3057\u305f\u3002<br>\u6b21\u306f\u3001\u81ea\u52d5\u5bfe\u6226\u30b7\u30b9\u30c6\u30e0\u306e\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u3067\u3001\u5f37\u5236\u7684\u306b\u6226\u7e3e\u3092\u6e2c\u308c\u308b\u3068\u3044\u3046\u308f\u3051\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u5b9f\u306fShowdown\u306b\u306f\u3001poke-env\u3068\u3044\u3046Python\u3067\u30d0\u30c8\u30ebAI\u306e\u5b9f\u6a29\u304c\u3067\u304d\u308b\u4fbf\u5229\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u5b58\u5728\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3055\u3066\u3001\u4eca\u56de\u304b\u3089\u306f\u672c\u683c\u7684\u306b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u89e6\u3063\u3066\u3044\u304d\u307e\u3059\u3002<br>\u3053\u3053\u304b\u3089PC\u306e\u6027\u80fd\u304c\u305d\u308c\u306a\u308a\u306b\u5fc5\u8981\u3068\u306a\u3063\u3066\u6765\u308b\u306e\u3067\u3001\u30e1\u30a4\u30f3PC\u3067\u52d5\u4f5c\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002\u3053\u3061\u3089\u306fWindows11\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>Python\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306f3.10\u3092\u4e8b\u524d\u306b\u7528\u610f\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<br>\u30e1\u30a4\u30f3PC\u3067\u4f7f\u3046\u30d5\u30a9\u30eb\u30c0\u3092\u4f5c\u6210\u3057\u3001\u305d\u306e\u30d5\u30a9\u30eb\u30c0\u306b\u79fb\u52d5\u3057\u307e\u3059\u3002\u666e\u6bb5\u4f7f\u3063\u3066\u308b\u30a8\u30af\u30b9\u30d7\u30ed\u30fc\u30e9\uff08Windows\u306e\u30d5\u30a9\u30eb\u30c0\u7ba1\u7406\u7528\u3068\u3057\u3066\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u5165\u3063\u3066\u308b\u3042\u308c\uff09\u306e\u30d1\u30b9\uff08C: > user > desktop \u307f\u305f\u3044\u306a\u306e\uff09\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u3068\u3053\u308d\u3092\u30af\u30ea\u30c3\u30af\u3057\u3001&#8220;cmd&#8220; \u3068\u5165\u529b\u3057\u3066\u305d\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u52d5\u6e08\u307f\u306e\u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u3092\u8868\u793a\u3055\u305b\u307e\u3059\u3002<br>\u3061\u306a\u307f\u306b\u3001\u79c1\u306fD\u30c9\u30e9\u30a4\u30d6\u76f4\u4e0b\u306bPokemonAI\u3068\u3044\u3046\u30d5\u30a9\u30eb\u30c0\u3067\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>py -3.10 -m venv venv<\/code><\/pre>\n\n\n\n<p>\u3068\u5165\u529b\u3057\u30013.10\u306e\u4eee\u60f3\u74b0\u5883\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002<br>\u5b8c\u4e86\u3057\u305f\u3089<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\\venv\\Scripts\\activate<\/code><\/pre>\n\n\n\n<p>\u3067\u3001\u4f5c\u6210\u3057\u305f\u4eee\u60f3\u74b0\u5883\u3092\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(venv) D:\\PokemonAI>python --version\nPython 3.10.11<\/code><\/pre>\n\n\n\n<p>\u3068\u306a\u308c\u3070\u6210\u529f\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u4eca\u5f8c\u306e\u958b\u767a\u74b0\u5883\uff08\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3059\u308b\u74b0\u5883\uff09\u306e\u8d77\u52d5\u65b9\u6cd5<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f5c\u6210\u3057\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u52d5\uff08D:\\PokemonAI\uff09<\/li>\n\n\n\n<li>\u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u3092\u8868\u793a\uff08\u30d1\u30b9\u306e\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u3068\u3053\u308d\u306b &#8220;cmd&#8221;\uff09<\/li>\n\n\n\n<li>\u4eee\u60f3\u74b0\u5883\u306e\u8d77\u52d5\uff08.\\venv\\Scripts\\activate\uff09<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u304c\u5fc5\u9808\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u65e9\u901f\u30b3\u30fc\u30c9\u3092\u66f8\u3053\u3046\uff01\u306e\u524d\u306b\u3001\u5fc5\u8981\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3092\u884c\u3044\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install --upgrade pip\npip install poke-env<\/code><\/pre>\n\n\n\n<p>\u3067\u3001\u6700\u4f4e\u9650\u4f7f\u3046\u305f\u3081\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u307e\u3059\u3002<br>\u6b21\u306b\u63a5\u7d9a\u30c6\u30b9\u30c8\u7528\u306e\u30b9\u30af\u30ea\u30d7\u30c8\uff08Python\u306b\u304a\u3051\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u30b3\u30fc\u30c9\u306e\u3053\u3068\uff09\u3092\u7528\u610f\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p>\u8868\u793a\u304b\u3089\u300c\u62e1\u5f35\u5b50\u3092\u8868\u793a\u300d\u3092ON\u306b\u3057\u305f\u72b6\u614b\u3067\u3001\u30c6\u30ad\u30b9\u30c8\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u65b0\u898f\u4f5c\u6210\u3057\u3001&#8221;poke_test.py&#8221;\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u540d\u304a\u3088\u3073\u62e1\u5f35\u5b50\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br>\u305d\u306e\u5f8c\u3001\u4e0b\u8a18\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u66f8\u304d\u8fbc\u307f\u3001\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import json\nimport asyncio\nimport os\nfrom datetime import datetime\n\nfrom poke_env.player import Player\nfrom poke_env.ps_client.server_configuration import ServerConfiguration\nfrom poke_env import AccountConfiguration\n\n# \u30ed\u30fc\u30ab\u30ebShowdown\u30b5\u30fc\u30d0\u30fc\u306eWebSocket URL\nws_url = \"ws:\/\/192.168.0.193:8058\/showdown\/websocket\" # \u2190\u3061\u3083\u3093\u3068IP\u30a2\u30c9\u30ec\u30b9\u3092\u30ed\u30fc\u30ab\u30eb\u306e\u7269\u306b\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002\nserver_config = ServerConfiguration(ws_url, ws_url)\n\naccount1 = AccountConfiguration(\"bot1\", None)\naccount2 = AccountConfiguration(\"bot2\", None)\n\n# \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306e\u4fdd\u5b58\u30d1\u30b9\u3092\u751f\u6210\ndef get_log_path(username):\n    os.makedirs(\"battle_log\", exist_ok=True)\n    timestamp = datetime.now().strftime(\"%Y%m%d_%H%M%S\")\n    return f\"battle_log\/{username}_{timestamp}.json\"\n\n# \u30ed\u30b0\u8a18\u9332\u4ed8\u304d\u30dc\u30c3\u30c8\nclass LoggingBot(Player):\n    def __init__(self, log_path, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.log_path = log_path\n        self.battle_data = &#91;]\n\n    def choose_move(self, battle):\n        self.battle_data.append({\n            \"turn\": battle.turn,\n            \"opponent\": battle.opponent_username,\n            \"active_pokemon\": {\n                \"species\": battle.active_pokemon.species,\n                \"hp\": battle.active_pokemon.current_hp,\n                \"status\": str(battle.active_pokemon.status)\n            },\n            \"available_moves\": &#91;m.id for m in battle.available_moves],\n            \"opponent_hp\": battle.opponent_active_pokemon.current_hp,\n        })\n        return self.choose_random_move(battle)\n\n    async def save_log(self):\n        with open(self.log_path, \"w\", encoding=\"utf-8\") as f:\n            json.dump(self.battle_data, f, indent=2, ensure_ascii=False)\n\nasync def main():\n    log1 = get_log_path(\"bot1\")\n    log2 = get_log_path(\"bot2\")\n\n    bot1 = LoggingBot(log1, account_configuration=account1, server_configuration=server_config)\n    bot2 = LoggingBot(log2, account_configuration=account2, server_configuration=server_config)\n\n    await bot1.battle_against(bot2, n_battles=3)\n\n    await bot1.save_log()\n    await bot2.save_log()\n\n    print(f\"{bot1.username} won {bot1.n_won_battles}\/3\")\n    print(\"\u30ed\u30b0\u4fdd\u5b58\u5148\uff1a\")\n    print(f\"  - {log1}\")\n    print(f\"  - {log2}\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())<\/code><\/pre>\n\n\n\n<p>\u30b5\u30fc\u30d0\u30fc\u5074\u306ePC\u3067\u3001Showdown\u30b5\u30fc\u30d0\u30fc\u304c\u65e2\u306b\u8d77\u52d5\u3057\u3066\u3044\u308b\u5834\u5408\u505c\u6b62\u3057\u3001<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>node pokemon-showdown start --no-security<\/code><\/pre>\n\n\n\n<p>\u3092\u4f7f\u3063\u3066\u3001\u518d\u5ea6\u8d77\u52d5\u3057\u307e\u3059\u3002<br>\u3053\u308c\u306b\u3088\u308a\u3001\u30ed\u30b0\u30a4\u30f3\u304c\u4e0d\u8981\u3068\u306a\u308a\u3001\u3061\u3083\u3093\u3068bot\u304c\u5bfe\u6226\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4eee\u60f3\u74b0\u5883\u3092\u8d77\u52d5\u4e2d\u306e\u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u3067\u3001\u201dpython poke_test.py\u201d\u3092\u5b9f\u884c\u3057\u3001\u5b9f\u969b\u306b\u52dd\u8ca0\u3092\u3055\u305b\u307e\u3057\u3087\u3046\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3001Part1\u3067\u306fShowdown\u306e\u30ed\u30fc\u30ab\u30eb\u30b5\u30fc\u30d0\u30fc\u3092\u69cb\u7bc9\u3057\u307e\u3057\u305f\u3002\u6b21\u306f\u3001\u81ea\u52d5\u5bfe\u6226\u30b7\u30b9\u30c6\u30e0\u306e\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u3067\u3001\u5f37\u5236\u7684\u306b\u6226\u7e3e\u3092\u6e2c\u308c\u308b\u3068\u3044\u3046\u308f\u3051\u3067\u3059\u3002 \u5b9f\u306fShowdown\u306b\u306f\u3001poke-env\u3068\u3044&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[11,12],"tags":[],"class_list":["post-244","post","type-post","status-publish","format-standard","hentry","category-program","category-pokemonai"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/deskgadgetreviews.com\/index.php\/wp-json\/wp\/v2\/posts\/244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/deskgadgetreviews.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/deskgadgetreviews.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/deskgadgetreviews.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/deskgadgetreviews.com\/index.php\/wp-json\/wp\/v2\/comments?post=244"}],"version-history":[{"count":1,"href":"https:\/\/deskgadgetreviews.com\/index.php\/wp-json\/wp\/v2\/posts\/244\/revisions"}],"predecessor-version":[{"id":248,"href":"https:\/\/deskgadgetreviews.com\/index.php\/wp-json\/wp\/v2\/posts\/244\/revisions\/248"}],"wp:attachment":[{"href":"https:\/\/deskgadgetreviews.com\/index.php\/wp-json\/wp\/v2\/media?parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/deskgadgetreviews.com\/index.php\/wp-json\/wp\/v2\/categories?post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/deskgadgetreviews.com\/index.php\/wp-json\/wp\/v2\/tags?post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}