宝可梦队伍优化
Pokémon Team Optimization

原始链接: https://nchagnet.pages.dev/blog/pokemon-team-optimization/

## 宝可梦队伍优化:一种科学方法 一位科学家出于对宝可梦的终身热爱,重温了游戏,并发现他们成年后的视角和分析思维改变了游戏体验。他们没有沉浸在怀旧的乐趣中,而是专注于最大化队伍的性能。这促使他们开展了一个项目,运用运筹学技术来构建“完美”的宝可梦队伍。 目标是最大化队伍的总基础数值,同时确保对所有宝可梦类型具有抵抗力,并受到队伍规模(1-6只宝可梦)和避免重复的限制。这被构建为一个混合整数规划(MIP)问题,使用决策变量来表示宝可梦的选择。虽然看似简单,但类型抵抗约束需要巧妙地使用辅助变量来保持线性并可求解。 使用PuLP Python库,该模型被实现并用宝可梦数据进行了测试。结果表明,由于其高数值,传奇宝可梦和准传奇宝可梦更受欢迎。移除这些宝可梦后,揭示了容易获得的宝可梦的强大组合,证明了该模型识别有效队伍的能力。 该项目强调了运筹学方法——通常用于物流和调度——可以应用于甚至具有趣味性的场景,提供了一种令人着迷的怀旧与分析性问题解决的结合。代码可在Github上获取,供任何想要构建自己优化队伍的人使用。

黑客新闻 新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 宝可梦队伍优化 (nchagnet.pages.dev) 10 分,来自 nchagnet 2 小时前 | 隐藏 | 过去 | 收藏 | 讨论 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请YC | 联系 搜索:
相关文章

原文

I grew up as a big Pokémon fan, watching the anime on TV (even the movies), playing it on my Gameboy color (which was Pikachu-themed too), collecting the cards. I had figurines, posters, blankets, plushies, everything. Truth be told, it was mostly that once my family figured out I liked it, they had just found an endless resource of Christmas and birthday gifts. And 6-year-old me was not complaining.

I do remember the games fondly. I played generations I-IV religiously. However, I was soured by the soft reboot of generation V, and as I was on the cusp of teenagehood, I kind of gave up on it. Fast forward 10 years and I rediscovered the joy of it: playing through my favorite games again as an adult was a blast!

However I quickly realized I had lost some of the magic by not being a kid anymore, and it took me a bit to realize why. I was not only much older than the target audience, but I was also working as a scientist. I was just constantly trying to min-max my way through the game. I was always hunting for Pokémon with better abilities, better type coverage, analyzing synergy between moves… If you’ve ever played a mainline Pokémon game before, you must know how utterly unnecessary this is. Twenty years ago, I would have just powered through on Blastoise or Typhlosion alone. But adult-me likes to have a balanced team, always ready for any encounter. So, at the peak of this frenzy, I decided to build a little tool to help myself over-engineer a team. And in this post, I’ll guide you through how I did it.

Formulating the problem as a Mixed-Integer Problem (MIP)

Before we can move on to the formulation part, what is it exactly that we’re trying to optimize?

If you’ve read this far, I assume you at least are familiar with what Pokémon is. At its core, it’s a turn-based game where you have a party of at most 6 “POcKEt MONsters” (or, Pokémon), which fight for you. There are currently 1025 Pokémon split into 9 generations. Each Pokémon belongs to one or two types (Fire, Water, Grass, etc.) and can learn up to 4 moves, each of which has its own type. Each type has its own strengths and weaknesses against other types. For example, water is strong against fire, so a Pokémon using a water attack against a fire Pokémon gets a 2x multiplicative factor.

Pokemon type matchup table

Pokémon type matchup table - Aussie Evil and OmegaFallon, CC0, via Wikimedia Commons

Each Pokémon also has stats, like attack, defense, speed, etc., but in this post we’ll only consider the overall base stat as an indicator of a strong Pokémon. There are a lot of other important details I won’t get into (e.g., there is a Same Type Attack Bonus (STAB), a physical/special split, etc.) but these all contribute to making the gameplay rich and complex. For now, I’m interested in finding the best teams of Pokémon such that:

  1. the total base stat is as high as possible,
  2. for each type AA, the team has a Pokémon resistant to it.

In optimization terms, 1. is called the objective while 2. is a constraint. Other notable constraints of the problem are:

  • a Pokémon can be chosen at most once,
  • the total amount of chosen Pokémon is at least 1 and at most 6.

We could solve some variation of the same problem by swapping/combining 2. with

  1. “for each type AA, the team has a Pokémon super effective to it”.

Ideally, you would want a more complex version 2. which would be

  1. “for each type AA, the team has a Pokémon resistant to it which can learn a super effective attack against it”.

But that’s a lot more complicated so for now let’s stick with 2. To recap, we have an objective and some constraints, what we need now are decision variables which will encode the solution. Mathematically, we can denote by xnx_n

argmaxxnbnxn , such that 1nxn6 and xn{0,1} .\mathrm{argmax}_{x} \sum_n b_n x_n~, \text{ such that } 1 \leq \sum_n x_n \leq 6 \text{ and } x_n \in \{ 0, 1 \}~.
联系我们 contact @ memedata.com