{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/chatgpt-game-autotest-card-game-move-decision/",
  "atlas": "https://www.pystone.net/?node=chatgpt-game-autotest-card-game-move-decision#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/chatgpt-game-autotest-card-game-move-decision.md",
  "context": "https://www.pystone.net/notes/chatgpt-game-autotest-card-game-move-decision.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:chatgpt-game-autotest-card-game-move-decision",
  "slug": "chatgpt-game-autotest-card-game-move-decision",
  "title": "【ChatGPT】游戏自动化测试实践案例 - 卡牌游戏出牌决策",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "【ChatGPT】游戏自动化测试实践案例 卡牌游戏出牌决策",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "99-资料来源、摘录与归档",
  "tags": [],
  "mocs": [],
  "contentHash": "cc8ebd02447c23d9051cd038578fd02c4d4d936469c1f9effdb0a3e4b5c0321c",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "【ChatGPT】游戏自动化测试实践案例 - 卡牌游戏出牌决策",
      "anchor": "chatgpt游戏自动化测试实践案例---卡牌游戏出牌决策",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-card-game-move-decision/#chatgpt%E6%B8%B8%E6%88%8F%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E5%AE%9E%E8%B7%B5%E6%A1%88%E4%BE%8B---%E5%8D%A1%E7%89%8C%E6%B8%B8%E6%88%8F%E5%87%BA%E7%89%8C%E5%86%B3%E7%AD%96"
    },
    {
      "depth": 2,
      "text": "初始化 Poco",
      "anchor": "初始化-poco",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-card-game-move-decision/#%E5%88%9D%E5%A7%8B%E5%8C%96-poco"
    },
    {
      "depth": 2,
      "text": "编写决策函数，根据游戏中的卡牌组合进行决策",
      "anchor": "编写决策函数根据游戏中的卡牌组合进行决策",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-card-game-move-decision/#%E7%BC%96%E5%86%99%E5%86%B3%E7%AD%96%E5%87%BD%E6%95%B0%E6%A0%B9%E6%8D%AE%E6%B8%B8%E6%88%8F%E4%B8%AD%E7%9A%84%E5%8D%A1%E7%89%8C%E7%BB%84%E5%90%88%E8%BF%9B%E8%A1%8C%E5%86%B3%E7%AD%96"
    },
    {
      "depth": 2,
      "text": "使用 Poco 进行 RPC 调用，获取游戏中的卡牌组合",
      "anchor": "使用-poco-进行-rpc-调用获取游戏中的卡牌组合",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-card-game-move-decision/#%E4%BD%BF%E7%94%A8-poco-%E8%BF%9B%E8%A1%8C-rpc-%E8%B0%83%E7%94%A8%E8%8E%B7%E5%8F%96%E6%B8%B8%E6%88%8F%E4%B8%AD%E7%9A%84%E5%8D%A1%E7%89%8C%E7%BB%84%E5%90%88"
    },
    {
      "depth": 2,
      "text": "使用决策函数进行决策",
      "anchor": "使用决策函数进行决策",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-card-game-move-decision/#%E4%BD%BF%E7%94%A8%E5%86%B3%E7%AD%96%E5%87%BD%E6%95%B0%E8%BF%9B%E8%A1%8C%E5%86%B3%E7%AD%96"
    },
    {
      "depth": 2,
      "text": "根据决策结果，在游戏界面上操作卡牌# 假设卡牌 UI 元素的名称是 \"card0\", \"card1\", \"card2\" 等",
      "anchor": "根据决策结果在游戏界面上操作卡牌-假设卡牌-ui-元素的名称是-card0-card1-card2-等",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-card-game-move-decision/#%E6%A0%B9%E6%8D%AE%E5%86%B3%E7%AD%96%E7%BB%93%E6%9E%9C%E5%9C%A8%E6%B8%B8%E6%88%8F%E7%95%8C%E9%9D%A2%E4%B8%8A%E6%93%8D%E4%BD%9C%E5%8D%A1%E7%89%8C-%E5%81%87%E8%AE%BE%E5%8D%A1%E7%89%8C-ui-%E5%85%83%E7%B4%A0%E7%9A%84%E5%90%8D%E7%A7%B0%E6%98%AF-card0-card1-card2-%E7%AD%89"
    },
    {
      "depth": 2,
      "text": "选择卡牌并出牌",
      "anchor": "选择卡牌并出牌",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-card-game-move-decision/#%E9%80%89%E6%8B%A9%E5%8D%A1%E7%89%8C%E5%B9%B6%E5%87%BA%E7%89%8C"
    },
    {
      "depth": 2,
      "text": "按照卡牌效果（伤害 + 防御）和卡牌消耗（如法力、能量等）之比从高到低对卡牌进行排序 sortedcards =",
      "anchor": "按照卡牌效果伤害-防御和卡牌消耗如法力能量等之比从高到低对卡牌进行排序-sortedcards",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-card-game-move-decision/#%E6%8C%89%E7%85%A7%E5%8D%A1%E7%89%8C%E6%95%88%E6%9E%9C%E4%BC%A4%E5%AE%B3-%E9%98%B2%E5%BE%A1%E5%92%8C%E5%8D%A1%E7%89%8C%E6%B6%88%E8%80%97%E5%A6%82%E6%B3%95%E5%8A%9B%E8%83%BD%E9%87%8F%E7%AD%89%E4%B9%8B%E6%AF%94%E4%BB%8E%E9%AB%98%E5%88%B0%E4%BD%8E%E5%AF%B9%E5%8D%A1%E7%89%8C%E8%BF%9B%E8%A1%8C%E6%8E%92%E5%BA%8F-sortedcards"
    },
    {
      "depth": 2,
      "text": "选择第一张玩家可以使用的卡牌",
      "anchor": "选择第一张玩家可以使用的卡牌",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-card-game-move-decision/#%E9%80%89%E6%8B%A9%E7%AC%AC%E4%B8%80%E5%BC%A0%E7%8E%A9%E5%AE%B6%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8%E7%9A%84%E5%8D%A1%E7%89%8C"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:sources-excerpts-archive",
      "title": "资料来源、摘录与归档",
      "url": "https://www.pystone.net/notes/sources-excerpts-archive/",
      "atlas": "https://www.pystone.net/?node=sources-excerpts-archive#knowledge-atlas",
      "label": "资料来源、摘录与归档",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "02-AI对话与研究原始输出中的“【ChatGPT】游戏自动化测试实践案例 - 卡牌游戏出牌决策”导航项",
      "citation": "https://www.pystone.net/notes/sources-excerpts-archive/#02-ai%E5%AF%B9%E8%AF%9D%E4%B8%8E%E7%A0%94%E7%A9%B6%E5%8E%9F%E5%A7%8B%E8%BE%93%E5%87%BA"
    }
  ],
  "contentMarkdown": "# 【ChatGPT】游戏自动化测试实践案例 - 卡牌游戏出牌决策\n\n> [!note] ChatGPT 问答录\n> 本文保存一次 ChatGPT 问答原始输出，仅作为资料来源；其中结论未自动视为已验证知识，使用前应结合可靠来源复核。\n\n\n> 创建时间：2023/6/11 20:48\n\n使用 Poco 进行 RPC 调用：\n\npython\n\nfrom airtest.core.api import connect_device\n\nfrom poco.drivers.unity3d import UnityPoco\n\ndevice = connect_device(\"Android:///\")\n\n## 初始化 Poco\n\npoco = UnityPoco(device)\n\n## 编写决策函数，根据游戏中的卡牌组合进行决策\n\ndef make_decision(card_combination): # 在此函数中编写决策逻辑，返回选择出的牌 # 作为示例，选择第一张牌\n\nchosen_card = card_combination[0]\n\nreturn chosen_card\n\n## 使用 Poco 进行 RPC 调用，获取游戏中的卡牌组合\n\ncard_combination = poco.agent.rpc(\"GetCardCombination\")\n\n## 使用决策函数进行决策\n\nchosen_card = make_decision(card_combination)\n\n## 根据决策结果，在游戏界面上操作卡牌# 假设卡牌 UI 元素的名称是 \"card_0\", \"card_1\", \"card_2\" 等\n\ncard_ui_name = f\"card_{chosen_card}\"\n\ncard_ui = poco(card_ui_name)\n\n## 选择卡牌并出牌\n\ncard_ui.click()\n\n* * *\n\n出牌决策示例：\n\n首先，假设每张卡牌具有以下属性：\n\n  * name: 卡牌名称\n\n  * cost: 卡牌消耗（如法力、能量等）\n\n  * damage: 卡牌造成的伤害\n\n  * defense: 卡牌提供的防御\n\n同时，假设我们可以获取到当前游戏状态，包括玩家的剩余资源（如法力、能量等）。\n\npython\n\nclass Card: def __init__(self, name, cost, damage, defense): self.name = name\n\nself.cost = cost\n\nself.damage = damage\n\nself.defense = defense\n\ndef make_decision(card_combination, player_remaining_resource):\n\n## 按照卡牌效果（伤害 + 防御）和卡牌消耗（如法力、能量等）之比从高到低对卡牌进行排序 sorted_cards =\n\nsorted(card_combination, key=lambda card: (card.damage + card.defense) / card.cost, reverse=True)\n\n## 选择第一张玩家可以使用的卡牌\n\nchosen_card = None\n\nfor card in sorted_cards:\n\nif card.cost <= player_remaining_resource:\n\nchosen_card = card\n\nbreak # 如果没有合适的卡牌，选择第一张卡牌 if chosen_card is None:\n\nchosen_card = card_combination[0]\n\nreturn chosen_card\n\n在这个示例中，我们首先对卡牌组合进行排序，优先考虑效果与消耗比较高的卡牌。然后，我们选择第一张玩家可以使用的卡牌。如果没有合适的卡牌，我们会选择第一张卡牌作为备选。\n\n请注意，这个示例仅供参考。您需要根据您的游戏规则和策略调整决策函数。同时，您需要修改之前的代码示例，以便正确处理卡牌对象和游戏状态。\n\n例如，您可以将游戏中的卡牌组合状态表示为 Card 类的对象列表，并将玩家剩余资源作为参数传递给 make_decision 函数。您还需要相应地修改游戏中的 RPC 函数，以返回卡牌对象列表而非字符串列表。\n"
}
