Overview Pokémon Nash Study

How the AI is computed

The battle AI on this site does not "think" while you play — every move is read from a table that was computed once, in advance. Here is how that table is built, aimed at a high-school student who likes math. The only tools you need are probability, expected value, and the patience to let an equation solve itself.

1 · One position is a tiny game

Look at a single moment in the battle. Both players choose at the same time — attack, or switch — and only then is the choice revealed. Because you move blind, no single choice is always best: if you always attack, the opponent switches to dodge it; if you always switch, they punish you. This is exactly rock–paper–scissors, and the right answer is to mix — to choose randomly with carefully tuned probabilities.

opp attacksopp switches
you attack0.300.60
you switch0.700.40
Each number is your probability of eventually winning after that pair of choices. There is no "safe" row: the best win probability you can guarantee with a fixed row is 0.40, but the opponent can hold you to 0.60 — the gap means the solution must be a mix.

For a 2×2 game like this there is a formula. With the four entries named a b / c d (top-left to bottom-right), the probability you should attack and the resulting win probability of the position are:

p(attack) = (d − c) / (a − b − c + d)    win prob = (a·d − b·c) / (a − b − c + d)

Here that gives p = 0.5 and win prob = 0.5: attack half the time, and the position is a coin-flip. This mix is the Nash equilibrium of the little game — neither player can do better by deviating, so a mixed strategy is not weakness, it is the exact answer.

2 · Positions point at each other

There is a catch hiding in that table. The number 0.30 for "both attack" is itself "your win probability in the position you reach next" — after the damage is dealt. So the win probability of a position is defined in terms of the win probabilities of other positions. Everything refers to everything else. Writing V(s) for the win probability of position s:

V(s) = the equilibrium win probability of the little matrix whose entries are the (averaged) V of wherever the turn sends you

"Averaged", because the game has dice: critical hits (1 in 24), a damage roll (16 equally likely rolls), and a coin flip for who moves first. Each cell of the matrix is the expected value over all those outcomes — an ordinary weighted average.

3 · Let the equation solve itself

An equation where V appears on both sides looks circular, but it can be solved by repetition. Start from the positions whose win probability is already obvious — someone has fainted, so V = 1 or V = 0. Then sweep over every position and recompute its win probability from the current guesses of its neighbours. Repeat. Each pass pushes the truth one step further back from the decided positions, and the numbers stop moving once they are consistent everywhere. This is value iteration, and the strategy (the switch probabilities) falls out of the same matrix solves.

4 · The trap: games that never end

Two Pokémon can just keep switching, forever, and never take damage. What is the win probability of a game that never ends? If we call it a draw worth 0.5, something breaks: a losing player escapes to 0.5 simply by stalling, and the whole table collapses — every position becomes 0.5 and the AI refuses to fight. A single table can't fix this on its own, because it has no clock: it cannot tell turn 3 from turn 80, so it cannot say "stop stalling, the end is near."

The fix is two small rule changes to the math of the game:

A theorem of Lloyd Shapley (1953) says that with that per-turn ending chance, a game like this always has an optimal strategy that depends only on the position — exactly the single clock-free table we want. Remove the ending chance and the guarantee is gone; the true optimal play would have to count how long the opponent has been stalling, which no single table can do.

5 · The result

Enumerate every position — each side's active Pokémon and both Pokémon's HP, bucketed into 26 levels — and run value iteration to convergence. That yields, for all 3.38 million positions, a probability of switching. We then check it honestly: we let a perfect opponent best-respond to the table and measure how much they gain. The answer is essentially zero — the table is unexploitable in this game.

positions solved: 3,380,000 genuinely mixed: 1,105,681 exploitability: ≈ 0 solve time: ~3.6 min

One honesty note. The playable battles here do not impose the "1% sudden ending" rule — being told a match can just stop feels unfair to a human. So the table is the exact equilibrium of the game with that rule, deployed in the game without it. In ordinary play, which resolves in around ten turns, the ending almost never fires and the AI plays near-optimally anyway. In theory a player who deliberately stalls forever could gain an edge — whether a human can actually pull that off is the next thing to test.

このAIの作り方

このサイトの対戦AIは、あなたと対戦している最中には何も「考えて」いません。すべての手は、 あらかじめ一度だけ計算した表から読み出しているだけです。その表をどう作るのかを、数学が好きな高校生に 向けて説明します。必要なのは確率と期待値、そして「方程式が自分で解けるまで待つ」根気だけです。

1 · 一つの局面は小さなゲーム

対戦のある一瞬を切り取ります。両プレイヤーは同時に手を選び — 攻撃か、交代か — 選んでから 初めて相手の手が公開されます。相手が見えないまま動くので、どれか一つの手が常に最善ということはありません。 いつも攻撃すれば相手は交代でかわし、いつも交代すれば相手はそこを咎める。これはまさにじゃんけんで、 正解は混ぜること — 確率をうまく調整してランダムに選ぶことです。

相手 攻撃相手 交代
自分 攻撃0.300.60
自分 交代0.700.40
各数字は、その手の組み合わせの後の自分の最終的な勝率です。「安全な行」はありません。 行を固定したとき保証できる自分の勝率は最大でも0.40ですが、相手はあなたを0.60に抑えられる — この差が、 解が混合戦略でなければならないことを意味します。

このような2×2のゲームには公式があります。4つの数字を a b / c d(左上から右下)と 名づけると、自分が攻撃すべき確率と、その局面の勝率は次で求まります:

p(攻撃) = (d − c) / (a − b − c + d)    勝率 = (a·d − b·c) / (a − b − c + d)

ここでは p = 0.5勝率 = 0.5 になります。半分の確率で攻撃し、局面は五分。 この混合が、この小さなゲームのナッシュ均衡です — どちらもここから外れて得することはできないので、 混合戦略は弱さではなく、厳密な正解なのです。

2 · 局面は互いを指し示す

この表には仕掛けが隠れています。「両者攻撃」の 0.30 という数字自体、実は「ダメージが入った後に 次に到達する局面での自分の勝率」です。つまりある局面の勝率は、他の局面の勝率で定義されている。 すべてがすべてを参照しています。局面 s の勝率を V(s) と書くと:

V(s) = 「その手番で行き着く先の V(を平均したもの)」を成分とする 小さな行列の均衡での勝率(ナッシュ勝率)

「平均」というのは、このゲームにサイコロがあるからです — 急所(24分の1)、ダメージ乱数(等確率の16通り)、 どちらが先に動くかのコイン。行列の各マスは、それらすべての結果にわたる期待値、ただの加重平均です。

3 · 方程式を自分で解かせる

V が両辺に現れる方程式は堂々巡りに見えますが、繰り返しで解けます。まず勝率が 明らかな局面から始めます — 誰かが倒れていれば V = 1V = 0。次に すべての局面を掃いて、今の隣接局面の勝率の見積もりから各局面の勝率を計算し直す。これを繰り返す。 一巡ごとに、決着済みの局面から真実が一歩ずつ手前へ伝わり、全体が整合すると数字は動かなくなります。 これが価値反復で、戦略(交代確率)も同じ行列を解く過程から出てきます。

4 · 罠 — 終わらない対戦

2匹のポケモンは、ただ永遠に交代し続けて、一度もダメージを受けないこともできます。では、決して 終わらない対戦の勝率は何でしょう? これを引き分け=0.5とすると、何かが壊れます。負けているプレイヤーが 交代し続けるだけで0.5に逃げられ、表全体が崩壊して — すべての局面が0.5になり、AIは戦うのを やめてしまう。1枚の表だけではこれを直せません。時計を持たないからです。3ターン目と80ターン目を 区別できないので、「交代をやめろ、もう終わりが近い」と言えないのです。

直し方は、ゲームの数学への2つの小さなルール変更です:

ロイド・シャープレイの定理(1953)は、その「毎ターン終わる確率」があれば、 こうしたゲームには必ず「局面だけで決まる最適戦略」が存在すると言います — まさに私たちが欲しい、 時計のいらない1枚の表です。終わる確率を取り除くとこの保証は消え、本当の最適手は「相手が何ターン 交代し続けているか」を数える必要が出てきて、1枚の表では表せなくなります。

5 · 結果

すべての局面 — 各陣営の場のポケモンと、両ポケモンのHP(26段階に離散化)— を列挙し、価値反復を 収束まで回します。すると338万すべての局面について交代確率が得られます。そして正直に検算します。 完璧な相手に表へベストレスポンスさせ、どれだけ得できるかを測る。答えは実質ゼロ — この表はこのゲームでexploit不能(付け入る隙がない)です。

解いた局面: 3,380,000 実際に混合: 1,105,681 付け入る隙: ≈ 0 計算時間: 約3.6分

一つ正直に。ここで遊べる対戦には「1%で突然終了」ルールは入れていません — 対戦が突然止まると言われても人間には不自然だからです。つまり表は、そのルールありのゲームの 厳密な均衡を、ルールなしのゲームに載せています。普通の対戦は10ターンほどで決着するので終了は ほとんど発火せず、AIはそれでもほぼ最適に指します。理論上は、意図的に永遠に交代し続けるプレイヤーが 有利を取れる余地があります — それを人間が実際にやり遂げられるかどうかが、次に確かめることです。