0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ポケモンタイプ相性表

Last updated at Posted at 2025-10-17

参考
https://www.pokemon.co.jp/ex/sun_moon/fight/161215_01.html

ポケモンの防御側から見たタイプ相性表です

例:ギャラドス 水・飛行タイプ

["×4"]=>電気
["×0.5"]=>炎・水・格闘・鋼
["×0"]=>地面

コード

<?php

function getTypeDefenseTable(...$typeIds) {
    // 引数が空またはnullの場合はnullを返す
    if (empty($typeIds) || (count($typeIds) === 1 && (is_null($typeIds[0]) || $typeIds[0] === ''))) {
        return null;
    }
    
    // 引数が1つで文字列(カンマ区切り)の場合は配列に変換
    if (count($typeIds) === 1 && is_string($typeIds[0]) && strpos($typeIds[0], ',') !== false) {
        $typeIds = array_map('intval', explode(',', $typeIds[0]));
    }
    
    // 有効なタイプIDが存在しない場合はnullを返す
    $validTypeIds = array_filter($typeIds, function($id) {
        return is_numeric($id) && $id >= 1 && $id <= 18;
    });
    if (empty($validTypeIds)) {
        return null;
    }
    
    // 有効なタイプIDのみを使用
    $typeIds = array_map('intval', $validTypeIds);
    
    // 防御側から見た倍率
    $defenseChart = [
     1 => ['×2' => [7],           '×0.5' => [], '×0' => [14]], // ノーマル
     2 => ['×2' => [3,9,13],      '×0.5' => [2,5,6,12,17,18], '×0' => []], // ほのお
     3 => ['×2' => [4,5],         '×0.5' => [2,3,6,17],       '×0' => []], // みず
     4 => ['×2' => [9],           '×0.5' => [4, 10, 17],      '×0' => []], // でんき
     5 => ['×2' => [2,6,8,10,12], '×0.5' => [3,4,5,9],        '×0' => []], // くさ
     6 => ['×2' => [2,7,13,17],   '×0.5' => [6],              '×0' => []], // こおり
     7 => ['×2' => [10,11,18],    '×0.5' => [12,13,16],     '×0' => []], // かくとう
     8 => ['×2' => [9,11],        '×0.5' => [5,8,12,17,18], '×0' => []], // どく
     9 => ['×2' => [3,5,6],       '×0.5' => [8,13],          '×0' => [4]], // じめん
     10 => ['×2' => [4,6,13],     '×0.5' => [5,7,13],       '×0' => [9]], // ひこう
     11 => ['×2' => [12,14,16],   '×0.5' => [7,11],          '×0' => []], // エスパー
     12 => ['×2' => [2,10,13],    '×0.5' => [5,7,9],        '×0' => []], // むし
     13 => ['×2' => [3,5,7,9,17], '×0.5' => [1,2,8,10],       '×0' => []], // いわ
     14 => ['×2' => [14,16],      '×0.5' => [8,12],          '×0' => [1]], // ゴースト
     15 => ['×2' => [6,15,18],    '×0.5' => [2,3,4,5],     '×0' => []], // ドラゴン
     16 => ['×2' => [7,12,18],    '×0.5' => [14,16],         '×0' => [11]], // あく
     17 => ['×2' => [2,7,9],      '×0.5' => [1,5,6,10,11,12,13,15,17,18], '×0' => [8]],//鋼
     18 => ['×2' => [8,17],       '×0.5' => [7,12,16], '×0' => [15]] // フェアリー
    ];

    $typeNames = [
        1 => 'ノーマル', 2 => 'ほのお', 3 => 'みず', 4 => 'でんき', 5 => 'くさ',
        6 => 'こおり', 7 => 'かくとう', 8 => 'どく', 9 => 'じめん', 10 => 'ひこう',
        11 => 'エスパー', 12 => 'むし', 13 => 'いわ', 14 => 'ゴースト', 15 => 'ドラゴン',
        16 => 'あく', 17 => 'はがね', 18 => 'フェアリー'
    ];

    // 攻撃タイプごとに最終倍率を計算
    $finalMultipliers = [];
    for ($atk = 1; $atk <= 18; $atk++) {
        $mult = 1.0;
        foreach ($typeIds as $defType) {
            if (!isset($defenseChart[$defType])) continue;
            $effect = $defenseChart[$defType];
            if (in_array($atk, $effect['×0'] ?? [])) {
                $mult = 0;
                break;
            }
            if (in_array($atk, $effect['×2'] ?? [])) $mult *= 2;
            if (in_array($atk, $effect['×0.5'] ?? [])) $mult *= 0.5;
        }
        $finalMultipliers[$atk] = $mult;
    }

    // 倍率ごとに分類
    $groups = [
        '×4' => [],
        '×2' => [],
        '×0.5' => [],
        '×0.25' => [],
        '×0' => []
    ];

    foreach ($finalMultipliers as $atk => $mult) {
        if ($mult == 4) $groups['×4'][] = $typeNames[$atk];
        elseif ($mult == 2) $groups['×2'][] = $typeNames[$atk];
        elseif ($mult == 0.5) $groups['×0.5'][] = $typeNames[$atk];
        elseif ($mult == 0.25) $groups['×0.25'][] = $typeNames[$atk];
        elseif ($mult == 0) $groups['×0'][] = $typeNames[$atk];
    }

    // HTML生成

    return $groups;
}




echo('<pre>');var_dump(getTypeDefenseTable(3,10));echo('</pre>');



結果

array(5) {
  ["×4"]=>
  array(1) {
    [0]=>
    string(9) "でんき"
  }
  ["×2"]=>
  array(0) {
  }
  ["×0.5"]=>
  array(4) {
    [0]=>
    string(9) "ほのお"
    [1]=>
    string(6) "みず"
    [2]=>
    string(12) "かくとう"
    [3]=>
    string(9) "はがね"
  }
  ["×0.25"]=>
  array(0) {
  }
  ["×0"]=>
  array(1) {
    [0]=>
    string(9) "じめん"
  }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?