RのWeb制作

Webサービス制作のための技術情報を。データ分析(Python、機械学習コンペ他)や自作野球ゲームMeisyoのこと中心。

Web制作 Meisyo

[Meisyo]ソースコードから学ぶ試合の基礎設計1

投稿日:

ワンボタンで監督始点の高校野球の試合を楽しめる名将と呼ばれた者達。その試合中には、多くのアルゴリズムが活躍しています。

ここでは、試合の設計を理解することで強いチームを作る指針を記載しておきます。

ソースコードからMeisyoの基礎設計を学び、どこに確定・不確定要素があるのか把握することで一歩先のゲームが楽しめます。

全ソースコード(2018.09.22)

3000行近くあり長過ぎるので見るのはあまりおすすめしません。次の概要で説明します。

        // 試合前ゲームデータ設定
        $G = []; // ゲームデータ
        $G['id_o'] = $OD['id'];
        $G['id_u'] = $UD['id'];

        # 基礎係数
        $G['c_g'] = 9.81;		#重力加速度
        $G['c_cor'] = 0.45;		#反発係数

        # 道具設定
        $G['bl_r'] = 3.65;		#ボール 半径(cm)
        $G['bl_wg'] = 142;		#ボール 重量(g)
        $G['bt_r'] = 3.3;		#バット 半径(cm)
        $G['bt_center'] = 95;	#バット 根元から芯まで(cm)
        $G['bt_meet'] = 7;		#バット ミートポイント幅(cm)
        $G['bt_wg'] = 900;		#バット 重量(g)

        # ランナー
        $G['rn_c'] = 7;			#ランナー打撃時リード基礎値(m)

        # 球場
        $G['bp_name'] = '地方球場';
        $G['bp_fe_c'] = 115;	#フェンス センター(m)
        $G['bp_fe_w'] = 100;	#フェンス 両翼(m)
        $G['bp_fe_h'] = 5;		#フェンス 高さ(m)
        $G['bp_cor'] = 0.31;	#グランド 反発係数
        $G['bp_corf'] = 0.35;	#フェンス 反発係数
        $G['bp_corz'] = 0.95;	#摩擦

        # 守備位置(x,y)(m)
        $G['bp_dpos'] = [
            '1' => '0,15', '2' => '0,-0.5', '3' => '15.40,17.40',
            '4' => '11.7,31.10', '5' => '-15.40,17.40', '6' => '-11.7,31.10',
            '7' => '-36.79,64.67', '8' => '0,80', '9' => '36.79,64.47'
        ];

        # ベース位置(x,y)(m)
        $G['base_l'] = 27.431;
        $G['base_hdg'] = $G['base_l'] * cos(deg2rad(45));
        $G['bp_base'] = [
            '0' => '0,0',
            '1' => $G['base_hdg'] . ',' . $G['base_hdg'],
            '2' => '0,' . ($G['base_hdg']*2),
            '3' => (-$G['base_hdg']) . ',' . $G['base_hdg']
        ];
        $G['base'] = $G['baseH'] = $G['baseG'] = $G['base_no'] = $G['base_cid'] = [
            '1' => '',
            '2' => '',
            '3' => ''
        ];

        # 試合データ
        $G['in'] = 1;		#イニング
        $G['side'] = 'o';	#攻撃サイド o,u
        $G['c_s'] = 0;		#カウント ストライク
        $G['c_b'] = 0;		#カウント ボール
        $G['c_o'] = 0;		#カウント アウト
        $G['in_c'] = 0;		#イニング開始確認用
        $G['in_op'] = 'u';	#イニング反対

        # 打順
        $G['bt_o'] = $G['bt_u'] = $G['bt_n'] = 0;
        $G['pc_o'] = $G['pc_u'] = $G['pc_n'] = 0;

        # 得点等集計
        $G['pt_o'] = $G['pt_u'] = 0;			#得点(総)
        $G['pt_o_in'] = $G['pt_u_in'] = [];		#得点(イニング)
        $G['hit_o'] = $G['hit_u'] = 0;			#ヒット(総)
        $G['hit_o_in'] = $G['hit_u_in'] = [];	#ヒット(イニング)
        $G['er_o'] = $G['er_u'] = 0;			#エラー(総)

        # 動的データ定義
        $G['pc'] = $G['bt'] = $G['df'] = $G['at'] = []; // 各データ格納
        $G['at_ar'] = $G['df_ar'] = []; // カード情報
        $G['at_b'] = $G['df_b'] = $G['at_bc'] = $G['df_bc'] = []; // 打順データ(基本、c:交代データ)
        $G['at_d'] = $G['df_d'] = []; // 守備位置データ
        $G['pc_id'] = null;
        $G['pt_oH'] = $G['pt_uH'] = 0; // 点数データ(以前)
        $G['j_bc'] = $G['get_pt'] = 0;
        $G['pc_pc'] = []; // 投手配球ログ
        $G['pc_hp'] = []; // HP対応
        $G['pc_pc']['o'] = $G['pc_pc']['u'] = [];

        # BT
        $G['bt_res'] = $G['pc_res'] = [];
        $G['bt_res']['o'] = $G['bt_res']['u'] = [];
        $G['pc_res']['o'] = $G['pc_res']['u'] = [];
        $G['btr_o'] = $G['btr_u'] = 0;

        # その他
        $G['sv_l_o'] = $G['sv_r_o'] = $G['sv_l_u'] = $G['sv_r_u'] = null;
        $G['win_side'] = $G['win_id'] = $G['lose_id'] = null;

        //------------------------------------------------------------//
        // 試合開始
        //------------------------------------------------------------//
        $html .= "<div class=desc><b style='color:red;'>プレイボール!</b>";
        $html .= "<table class='score_board' width=100% style='border:none;'>\n";
        $html .= "<tr>";
        $html .= "<td rowspan=2><img src='" . $this->_disp_flag($OD['team_flag']) . "' style='height:60px; width:60px; vertical-align:middle;'>&nbsp;<img src='" . $this->_disp_icon($OD['mn_img']) . "' style='height:30px; width:30px; vertical-align:middle;'></td>";
        $html .= "<td colspan=3><font style='font-size:40px;'>{$G['pt_o']}&nbsp;-&nbsp;{$G['pt_u']}</font></td>";
        $html .= "<td rowspan=2><img src='" . $this->_disp_icon($UD['mn_img']) . "' style='height:30px; width:30px; vertical-align:middle;'>&nbsp;<img src='" . $this->_disp_flag($UD['team_flag']) . "' style='height:60px; width:60px; vertical-align:middle;'></td></tr>";
        $html .= "<tr><td width=100>&lt;&lt;</td><td width=150>1回オモテ</td><td width=100>&nbsp;</td></tr>";
        $html .= "</table></div>\n";

        // while
        $G['i'] = 0;
        while($G['i'] < 1000) // $G['i'] < 1000
        {
            //------------------------------------------------------------//
            // イニング開始
            //------------------------------------------------------------//
            if(!$G['in_c'])
            {
                # 得点取得
                $G['pt_oH'] = $G['pt_o'];
                $G['pt_uH'] = $G['pt_u'];

                # 選手読み込み
                if($G['side'] == 'o')
                {
                    # 守備=>U
                    $G['df'] = $UD;
                    $G['df_ar'] = $UCs;
                    $G['df_b'] = $UD_B; $G['df_bc'] = $UD_BC;
                    $G['df_d'] = $UD_D;
                    # 攻撃=>O
                    $G['at'] = $OD;
                    $G['at_ar'] = $OCs;
                    $G['at_b'] = $OD_B; $G['at_bc'] = $OD_BC;
                    $G['at_d'] = $OD_D;
                    # 表示
                    $G['in_op'] = 'u'; # イニング反対
                    $html .= "<div class='game_o'>";
                }
                else
                {
                    # 守備=>O
                    $G['df'] = $OD;
                    $G['df_ar'] = $OCs;
                    $G['df_b'] = $OD_B; $G['df_bc'] = $OD_BC;
                    $G['df_d'] = $OD_D;
                    # 攻撃=>U
                    $G['at'] = $UD;
                    $G['at_ar'] = $UCs;
                    $G['at_b'] = $UD_B; $G['at_bc'] = $UD_BC;
                    $G['at_d'] = $UD_D;
                    # 表示
                    $G['in_op'] = 'o'; # イニング反対
                    $html .= "<div class='game_u'>";
                }
                # 投手読み込み
                $G['pc'] = $G['df_ar'][$G['df_d'][1]];
                $G['pc_id'] = $G['pc']['id'];
                # 打者読み込み
                $G['bt'] = $G['at_ar'][$G['at_b'][$G['bt_n']]];
                $G['team_sb'] = $G['at']['team_sb'];
                # イニング交代チェックOK
                $G['in_c'] = 1;
            }

            //------------------------------------------------------------//
            // 投手設定
            //------------------------------------------------------------//
            // 配球結果呼び出し
            $G['pc_bb'] = ['0'=>0, '1'=>0, '2'=>0, '3'=>0];
            if(empty($G['pc_pc'][$G['in_op']][$G['pc_id']])){ $G['pc_pc'][$G['in_op']][$G['pc_id']] = ['0'=>0,'1'=>0,'2'=>0,'3'=>0]; }
            $G['pc_bb'] = $G['pc_pc'][$G['in_op']][$G['pc_id']];

            // 起用法呼び出し
            $G['pc_ptype'] = explode(",", $G['pc']['pc_type']);
            // 投手HPパーセント計算
            $G['pc_hp_per'] = $this->_game_pc_hpp($G['pc']['S_p_st'], $G['pc']['hp'], ($G['pc_bb'][0] + $G['pc_bb'][1] + $G['pc_bb'][2] + $G['pc_bb'][3]));

            //------------------------------------------------------------//
            // 塁設定
            //------------------------------------------------------------//
            $G['baseH'] = $G['base']; // 移動前保存
            for($i=1; $i<=3; $i++)
            {
                if(!empty($G['baseH'][$i]))
                {
                    $G['baseG'] = explode(",", $G['baseH'][$i]);
                    $G['base_no'][$i] = $G['baseG'][0];
                    $G['base_cid'][$i] = $G['baseG'][1];
                    # ランナー設定
                    $G['rn'][$i] = $G['at_ar'][$G['baseG'][0]];
                    //$html .= "({$i}){$G['rn'][$i]['name']}\n";
                }
                else
                {
                    $G['rn'][$i] = [];
                }
            }

            //------------------------------------------------------------//
            // 交代 / 打者・状況説明表示
            //------------------------------------------------------------//
            if($G['c_s'] == 0 && $G['c_b'] == 0)
            {
                //------------------------------//
                // 継投
                //------------------------------//
                $G['ch_pc'] = $G['ch_pc_ar'] = [];
                foreach($G['df_ar'] as $id => $CD)
                {
                    if(!$CD['game'] && $CD['g_bench'] && $CD['type'] == 'P')
                    {
                        $CD_PTYPE = explode(",", $CD['pc_type']); // 起用法呼び出し
                        $ch_pc_per = $this->_game_pc_hpp($CD['S_p_st'], $CD['hp']);
                        if($G['in'] < $CD_PTYPE[3] || $G['in'] > $CD_PTYPE[5] || $ch_pc_per < $CD_PTYPE[2] || !$CD_PTYPE[0]){ continue; }

                        // 条件一致(SV別)
                        if($CD_PTYPE[0] == 'SV' && $G['side'] != $G['win_side'] && $G['win_side'] && ((abs($G['pt_o'] - $G['pt_u']) <= 3 && $G['c_o'] == 0) || (abs($G['pt_o'] - $G['pt_u']) < count($G['base']) + 2) || ((9 - $G['in']) * 3 + 3 - $G['c_o'] >= 9))) // SV
                        {
                            $html .= "<!--SV:{$CD['name']}-->";
                        }
                        else
                        {
                            if($G['in'] >= $G['pc_ptype'][5] || $G['pc_hp_per'] <= $G['pc_ptype'][4]) // 交代投手確認
                            {
                                // 条件一致
                                if($CD_PTYPE[0] == 'R')
                                {
                                    $html .= "<!--継投:{$CD['name']}-->";
                                }
                                elseif($CD_PTYPE[0] == 'P' && (!empty($G['base'][2]) || !empty($G['base'][3])))
                                {
                                    $html .= "<!--ピンチ:{$CD['name']}-->";
                                }
                                elseif($CD_PTYPE[0] == 'L' && $G['side'] == $G['win_side'] && $G['win_side'])
                                {
                                    $html .= "<!--敗戦:{$CD['name']}-->";
                                }
                                elseif($CD_PTYPE[0] == 'W' && $G['side'] != $G['win_side'] && $G['win_side'] && abs($G['pt_o'] - $G['pt_u']) <= 3)
                                {
                                    $html .= "<!--接戦:{$CD['name']}-->";
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                        $G['ch_pc_ar'][$CD_PTYPE[0]] = $CD['id']; // 継投リスト化
                    }
                }

                // 継投リストがあれば表示
                if(count($G['ch_pc_ar']) > 0)
                {
                    asort($G['ch_pc_ar']);
                    foreach($G['ch_pc_ar'] as $ap => $ch_id) // 優先度=>id
                    {
                        $CD_C = $G['df_ar'][$G['pc']['id']]; // 交代id
                        $CD_S = $G['df_ar'][$ch_id]; // 出場id
                        $CD_S['g_pos'] = $CD_C['g_pos'];

                        // PC
                        $G['pc'] = $CD_S;
                        $G['pc_id'] = $G['pc']['id'];
                        $G['pc_ptype'] = explode(",", $G['pc']['pc_type']);
                        $G['pc_hp_per'] = $this->_game_pc_hpp($G['pc']['S_p_st'], $G['pc']['hp'], 0);

                        $html .= "<strong>ここで投手の交代です。" .$this->_disp_name($CD_C). "に代わり" .$this->_disp_name($CD_S). "。</strong><br>\n";
                        // 交代ログ
                        $this->_game_pl_change($G, $G['df'], $G['df_ar'], $G['df_d'], $G['df_b'], $G['df_bc'], $CD_C, $CD_S, $G['in_op'], 'df', 'R');
                        break;
                    }
                }
                //------------------------------//
                // 代打/代走
                //------------------------------//
                $G['ch_bt'] = $G['ch_bt_ar'] = [];
                foreach($G['at_ar'] as $id => $CD)
                {
                    if(!$CD['game'] && $CD['g_bench'] && !$CD['g_pos'] && $CD['type'] == 'B')
                    {
                        $CD_BTYPE = explode(",", $CD['bt_type']); // 起用法呼び出し
                        if($G['in'] < $CD_BTYPE[3] || empty($CD_BTYPE[3])){ continue; }
                        // 代打
                        if($CD_BTYPE[5] && ($G['bt']['id'] == $CD_BTYPE[4] || ($CD_BTYPE[4] == 'pitch' && $G['bt']['type'] == 'P')))
                        {
                            if(!empty($G['ch_bt'][$G['bt']['id']])) // 優先度判定
                            {
                                $G['ch_bt_ar'] = explode(",", $G['ch_bt'][$G['bt']['id']]);
                                if($CD_BTYPE[2] < $G['ch_bt_ar'][1]) // 優先度優位
                                {
                                    $G['ch_bt'][$G['bt']['id']] = "{$CD['id']},{$CD_BTYPE[2]},bt";
                                }
                            }
                            else
                            {
                                $G['ch_bt'][$G['bt']['id']] = "{$CD['id']},{$CD_BTYPE[2]},bt"; // 交代対象 => 交代,優先度
                            }
                        }
                        // 代走
                        if($CD_BTYPE[6])
                        {
                            // 1,2,3塁
                            for($i=1; $i<=3; $i++)
                            {
                                if(!empty($G['rn'][$i]) && ($G['rn'][$i]['id'] == $CD_BTYPE[4] || ($CD_BTYPE[4] == 'pitch' && $G['rn'][$i]['type'] == 'P')))
                                {
                                    if(!empty($G['ch_bt'][$G['rn'][$i]['id']])) // 優先度判定
                                    {
                                        $G['ch_bt_ar'] = explode(",", $G['ch_bt'][$G['rn'][$i]['id']]);
                                        if($CD_BTYPE[2] < $G['ch_bt_ar'][1]) // 優先度優位
                                        {
                                            $G['ch_bt'][$G['rn'][$i]['id']] = "{$CD['id']},{$CD_BTYPE[2]},rn,{$i}";
                                        }
                                    }
                                    else
                                    {
                                        $G['ch_bt'][$G['rn'][$i]['id']] = "{$CD['id']},{$CD_BTYPE[2]},rn,{$i}";
                                    }
                                }
                            }
                        }
                    }
                }

                // 代打
                if(count($G['ch_bt']) > 0)
                {
                    foreach($G['ch_bt'] as $ch_id => $str)
                    {
                        $G['ch_bt_ar'] = explode(",", $str);

                        // 交代開始
                        $CD_C = $G['at_ar'][$ch_id]; // 交代
                        $CD_S = $G['at_ar'][$G['ch_bt_ar'][0]]; // 出場
                        $CD_S['g_pos'] = $CD_C['g_pos'];

                        // 条件変更
                        if($G['ch_bt_ar'][2] == 'bt') // 代打
                        {
                            $G['bt'] = $CD_S; // 打者交代
                            $html .= "<strong>ここで代打です。" .$this->_disp_name($CD_C). "に代わり" .$this->_disp_name($CD_S). "。</strong><br>\n";
                            $RS = '打';
                        }
                        elseif($G['ch_bt_ar'][2] == 'rn') // 代走
                        {
                            $G['rn'][$G['ch_bt_ar'][3]] = $CD_S; // 走者交代
                            $html .= "<strong>ここで代走です。{$G['ch_bt_ar'][3]}塁ランナー" .$this->_disp_name($CD_C). "に代わり" .$this->_disp_name($CD_S). "。</strong><br>\n";
                            $RS = '走';
                        }
                        // 交代ログ
                        $this->_game_pl_change($G, $G['at'], $G['at_ar'], $G['at_d'], $G['at_b'], $G['at_bc'], $CD_C, $CD_S, $G['side'], 'at', $RS);
                        break;
                    }
                }

                //------------------------------//
                // 守備固め
                //------------------------------//
                $G['ch_df'] = $G['ch_df_ar'] = [];
                foreach($G['df_ar'] as $id => $CD)
                {
                    if(!$CD['game'] && $CD['g_bench'] && !$CD['g_pos'] && $CD['type'] == 'B')
                    {
                        $CD_BTYPE = explode(",", $CD['bt_type']); // 起用法呼び出し
                        if($G['in'] < $CD_BTYPE[3] || empty($CD_BTYPE[3]) || empty($CD_BTYPE[7]) || empty($CD_BTYPE[4])){ continue; }

                        // 対象者取得
                        for($i=1; $i<=9; $i++)
                        {
                            if($G['df_id'][$i] == $CD_BTYPE[4])
                            {
                                if(!empty($G['ch_df'][$CD_BTYPE[4]])) // 優先度判定
                                {
                                    $G['ch_df_ar'] = explode(",", $G['ch_df'][$CD_BTYPE[4]]);
                                    if($CD_BTYPE[2] < $G['ch_df_ar'][1]) // 優先度優位
                                    {
                                        $G['ch_df'][$CD_BTYPE[4]] = "{$CD['id']},{$CD_BTYPE[2]}";
                                    }
                                }
                                else // そのまま登録
                                {
                                    $G['ch_df'][$CD_BTYPE[4]] = "{$CD['id']},{$CD_BTYPE[2]}"; // 交代対象 => 交代,優先度
                                }
                            }
                        }
                    }
                }

                // 対象サーチ
                if(count($G['ch_df']) > 0)
                {
                    $html .= "<strong>ここで守備を交代するようです。<br>\n";
                    foreach($G['ch_df'] as $ch_id => $str)
                    {
                        $G['ch_df_ar'] = explode(",", $str);

                        // 交代開始
                        $CD_C = $G['df_ar'][$ch_id]; // 交代
                        $CD_S = $G['df_ar'][$G['ch_df_ar'][0]]; // 出場
                        $CD_S['g_pos'] = $CD_C['g_pos'];

                        if($CD_C['type'] == 'P'){ continue; } // 投手は守備固めで交代できない

                        // 交代ログ
                        $this->_game_pl_change($G, $G['df'], $G['df_ar'], $G['df_d'], $G['df_b'], $G['df_bc'], $CD_C, $CD_S, $G['in_op'], 'df', '守');
                        // 表示
                        $PL = explode(",", $cf['pos_list'][$CD_S['g_pos']]);
                        $html .= "{$PL[1]}を" .$this->_disp_name($CD_C). "から" .$this->_disp_name($CD_S). "に交代します。";
                    }
                    $html .= "</strong><br>\n";
                }
                //------------------------------//
                // 走者表示
                //------------------------------//
                $html_run = null;
                for($i=1; $i<=3; $i++)
                {
                    if(!empty($G['base'][$i]))
                    {
                        if($html_run){ $html_run .= "・";}
                        $html_run .= $i;
                    }
                }

                if($html_run)
                {
                    if(!empty($G['base'][1]) && !empty($G['base'][2]) && !empty($G['base'][3]))
                    {
                        $html_run = "満塁";
                    }
                    else
                    {
                        $html_run .= "塁";
                    }
                }
                else
                {
                    $html_run = "なし";
                }

                # アウト
                $html_out = null;
                if($G['c_o'] == 2){ $html_out = "ツー"; }
                elseif($G['c_o'] == 1){ $html_out = "ワン"; }
                else{ $html_out = "ノー"; }

                # 表示
                $html .= "バッター" .$this->_disp_name($G['bt']). "&nbsp;{$html_out}アウトランナー{$html_run}<br>\n";
            }
            //------------------------------------------------------------//
            // PC投球
            //------------------------------------------------------------//
            // HP補正値計算
            if($G['pc_hp_per'] >= 30)
            {
                $G['pc_hp_cor'] = $G['pc_hp_per'] / 700 + 6 / 7;
            }
            else
            {
                $G['pc_hp_cor'] = $G['pc_hp_per'] * 0.03;
            }
            if($G['pc_hp_cor'] < 0){ $G['pc_hp_cor'] = 0; }

            // 補正実行
            $G['pc_hp_ar'] = ['S_p_sp', 'S_p_co', 'S_p_bb1n', 'S_p_bb2n', 'S_p_bb3n', 'p_bb0k', 'p_bb1k', 'p_bb2k', 'p_bb3k'];
            foreach($G['pc_hp_ar'] as $str)
            {
                $G['pc'][$str] = $G['pc'][$str] * $G['pc_hp_cor'];
            }

            # bag
            # $html .= "ピッチャー" .$this->_disp_name($G['pc']). "残りHP:" .floor($G['pc_hp_per']). ", 補正:" . $G['pc_hp_cor'] . "<br>\n";
            //------------------------------//
            // コース選択
            //------------------------------//
            # X
            $G['pc_xH'] = mt_rand(0, 75 * 1000)/10000 + 13.8;
            if(mt_rand(1,2) >= 2){ $G['pc_xH'] = -$G['pc_xH']; }
            # Y
            $G['pc_yH'] = mt_rand(0, 75 * 1000)/10000 + 22.5;
            if(mt_rand(1,2) >= 2){ $G['pc_yH'] = 75 + $G['pc_yH']; }
            else{ $G['pc_yH'] = 75 - $G['pc_yH']; }

            # Z
            $G['pc_zH'] = 43.2;

            //------------------------------//
            // 球種選択
            //------------------------------//
            // 配球比率設定
            if($G['pc']['pc_type']) // 手動
            {
                $G['pc_brA'] = [$G['pc_ptype'][6], $G['pc_ptype'][7], $G['pc_ptype'][8], $G['pc_ptype'][9]];
            }
            else // 自動(ランダム)# 3,1,1,1
            {
                $G['pc_brA'] = [3,1,1,1];
            }

            // 全体
            $G['pc_br_all'] = $G['pc_brA'][0] + $G['pc_brA'][1] + $G['pc_brA'][2] + $G['pc_brA'][3];

            $G['pc_brR'] = mt_rand(0, $G['pc_br_all']);
            for($i=0; $i<count($G['pc_brA']); $i++)
            {
                $G['pc_brR'] -= $G['pc_brA'][$i];
                if($G['pc_brR'] <= 0)
                {
                    $G['pc_br'] = $i;
                    break;
                }
            }

            //------------------------------//
            // 投球座標設定
            //------------------------------//
            $G['pcfm_xy'] = explode(",", $cf['pcfm_xy_list'][$G['pc']['type_p']]);
            # Z
            $G['pc_zS'] = 1844 - 120;
            # X
            if($G['pc']['side_p'] == 'R')
            {
                $G['pc_xS'] = -$G['pcfm_xy'][0];
            }
            else
            {
                $G['pc_xS'] = $G['pcfm_xy'][0];
            }
            # Y
            $G['pc_yS'] = $G['pcfm_xy'][1];

            //------------------------------//
            // 初速設定
            //------------------------------//
            $G['pc_spC'] = [];
            $G['pc_sp'] = $this->_disp_sp($G['pc']['S_p_sp'], $G['pc']['cond']);
            $G['pc_spC'][0] = $this->_disp_sp($G['pc']['S_p_sp'], $G['pc']['cond']); // 1球ごとに少し球威が違うのを再現
            for($i=1; $i<=3; $i++)
            {
                $G['pc_spC'][$i] = $G['pc_spC'][0] + $this->_game_brk($G['pc']["p_bb{$i}k"], $G['pc']["p_bb{$i}"]);
            }
            // 変化球:変化量取得および速度計算
            if($G['pc_br'] == 0)
            {
                $G['pc_bbC'] = $G['pc']["p_sp"];
            }
            else
            {
                $G['pc_bbC'] = $G['pc']["p_bb{$G['pc_br']}n"];
                $G['pc_sp'] += $this->_game_brk($G['pc']["p_bb{$G['pc_br']}k"], $G['pc']["p_bb{$G['pc_br']}"]);
            }
            //------------------------------//
            // キレ設定
            //------------------------------//
            $G['pc_bbkC'] = [];
            for($i=0; $i<=3; $i++)
            {
                $G['pc_bbkC'][$i] = $G['pc']["p_bb{$i}k"];
            }

            //------------------------------//
            // 変化量取得
            //------------------------------//
            $G['pc_bb_x'] = $G['pc_bb_y'] = [];
            # 0 ストレート
            $G['pc_bb_x'][0] = $G['pc_bb_y'][0] = 0;
            # 各々変化方向,量取得
            for($i=1; $i<=3; $i++)
            {
                $g_brk = $G['pc']["p_bb{$i}"]; // 変化方向
                $g_brk_n = $G['pc']["p_bb{$i}n"] * 0.3; // 変化量 * 補正値(0.3)
                switch($g_brk)
                {
                    case 1:
                        $G['pc_bb_x'][$i] = $g_brk_n;
                        $G['pc_bb_y'][$i] = 0;
                    break;
                    case 2:
                        $G['pc_bb_x'][$i] = $g_brk_n * cos(deg2rad(45));
                        $G['pc_bb_y'][$i] = -$g_brk_n * sin(deg2rad(45));
                    break;
                    case 3:
                        $G['pc_bb_x'][$i] = 0;
                        $G['pc_bb_y'][$i] = -$g_brk_n;
                    break;
                    case 4:
                        $G['pc_bb_x'][$i] = -$g_brk_n * cos(deg2rad(45));
                        $G['pc_bb_y'][$i] = -$g_brk_n * sin(deg2rad(45));
                    break;
                    case 5:
                        $G['pc_bb_x'][$i] = -$g_brk_n;
                        $G['pc_bb_y'][$i] = 0;
                    break;
                    default:
                        $G['pc_bb_x'][$i] = 0;
                        $G['pc_bb_y'][$i] = 0;
                    break;
                }
                // 左投げの場合場合反転
                if($G['pc']['side_p'] == 'L')
                {
                    $G['pc_bb_x'][$i] = -$G['pc_bb_x'][$i];
                }
            }
            // km/h→m/sに変更
            $G['pc_sp_ms'] = $G['pc_sp']/3.6;
            # bag
            # $html .= "{$G['pc_br']}を投げます。(x".$G['pc_bb_x'][$G['pc_br']].")(y".$G['pc_bb_y'][$G['pc_br']].")へ球速{$G['pc_sp']}です。<br>\n";

            //------------------------------//
            // 変化球:変化対応
            //------------------------------//
            $G['pc_xE'] = $G['pc_xH'] - $G['pc_bb_x'][$G['pc_br']];
            $G['pc_yE'] = $G['pc_yH'] - $G['pc_bb_y'][$G['pc_br']];
            $G['pc_zE'] = $G['pc_zH'];

            //------------------------------------------------------------//
            // PC vs BT
            //------------------------------------------------------------//
            $G['j_btsw'] = 0; // 振ったかどうか判定
            $G['bt_swsp'] = 0.118 * $G['bt']['S_b_pw'] + 20.25; // スイングスピード計算 # 0.118 * pw + 28.25
            switch($G['bt']['type_b']) // ミートポイント設定
            {
                case 'F': $G['bt_mtp'] = 150; break;
                case 'R': $G['bt_mtp'] = 50; break;
                default: $G['bt_mtp'] = 100; break;
            }

            //------------------------------//
            // 待ち球計算
            //------------------------------//
            // 配球結果呼び出し
            $G['bt_bb'] = $G['pc_bb'];

            // 配球比率設定
            $G['bt_brA'] = $G['bt_bb'];

            // 全体
            $G['bt_br_all'] = $G['bt_brA'][0] + $G['bt_brA'][1] + $G['bt_brA'][2] + $G['bt_brA'][3];

            // 少ない間のみ
            if($G['bt_br_all'] <= 20)
            {
                $G['bt_brA'] = [$G['pc']['S_p_sp'], $G['pc']['S_p_bb1n'], $G['pc']['S_p_bb2n'], $G['pc']['S_p_bb3n']];
                $G['bt_br_all'] = $G['bt_brA'][0] + $G['bt_brA'][1] + $G['bt_brA'][2] + $G['bt_brA'][3];
            }

            $G['bt_brR'] = mt_rand(0, $G['bt_br_all']);
            for($i=0; $i<=5; $i++)
            {
                $G['bt_brR'] -= $G['bt_brA'][$i];
                if($G['bt_brR'] <= 0)
                {
                    $G['bt_br'] = $i;
                    break;
                }
            }
            # bag
            # $html .= "{$G['bt_br']}を打ちます。<br>\n";

            //------------------------------//
            // コントロールミス計算
            //------------------------------//
            if(mt_rand(1, 1000) <= (-0.036 * $G['pc']['S_p_co'] + 4))
            {
                $html .= "ああっと、失投か?";
                $G['pc_br'] = 0;
                $G['bt_br'] = 0;
                $G['pc_sp_ms'] = $G['pc_spC'][0] / 3.6;
                $G['pc_xE'] = 0;
                $G['pc_yE'] = 75;
            }
            else
            {
                $rand_co = mt_rand(1, (100 - $G['pc']['S_p_co']) * 1000) / 5000;
                $rand_co_dg = mt_rand(1, 360);
                $G['pc_xE'] += $rand_co * cos(deg2rad($rand_co_dg));
                $G['pc_yE'] += $rand_co * sin(deg2rad($rand_co_dg));
            }

            //------------------------------//
            // 投球集計
            //------------------------------//
            if($G['side'] == 'o')
            {
                $G['pc_pc']['u'][$G['pc_id']][$G['pc_br']]++;
            }
            else
            {
                $G['pc_pc']['o'][$G['pc_id']][$G['pc_br']]++;
            }
            //------------------------------------------------------------//
            // 打者ストライク/スイング判定
            //------------------------------------------------------------//
            # 初期位置設定
            $G['bt_xS'] = $G['pc_xS']; $G['bt_xD'] = $G['pc_xS'];
            $G['bt_yS'] = $G['pc_yS']; $G['bt_yD'] = $G['pc_yS'];
            $G['bt_zS'] = $G['pc_zS']; $G['bt_zD'] = $G['pc_zS'];

            # スイング位置設定
            $G['bt_xE'] = $G['pc_xE'];
            $G['bt_yE'] = $G['pc_yE'];
            $G['bt_zE'] = $G['pc_zE'];

            # 速度設定
            $G['bt_ps_ms'] = $G['pc_spC'][$G['bt_br']] / 3.6;

            # ベクトル計算
            $G['bt_xV'] = $G['bt_xE'] - $G['bt_xS'];
            $G['bt_yV'] = $G['bt_yE'] - $G['bt_yS'];
            $G['bt_zV'] = $G['bt_zE'] - $G['bt_zS'];

            # 絶対ベクトル
            $G['bt_absV'] = sqrt(pow($G['bt_xV'], 2) + pow($G['bt_yV'], 2) + pow($G['bt_zV'], 2));

            //------------------------------//
            // 移動前計算
            //------------------------------//
            # cm/s
            $G['bt_psp100'] = $G['bt_ps_ms'] * 100;
            # 投球にかかる時間
            $G['bt_tt'] = $G['bt_absV'] / $G['bt_psp100'];

            //------------------------------//
            // 移動計算 投球-変化前間
            //------------------------------//
            # 変化開始秒
            $G['bt_tbb'] = $G['bt_tt'] * (0.007 * $G['pc_bbkC'][$G['bt_br']] + 0.2);

            # 変化開始秒 距離cm
            $G['bt_tbb_cm'] = $G['bt_tbb'] * $G['bt_psp100'];

            # 移動x,y,z
            $G['bt_xD'] += $G['bt_xV'] / $G['bt_absV'] * $G['bt_tbb_cm'];
            $G['bt_yD'] += $G['bt_yV'] / $G['bt_absV'] * $G['bt_tbb_cm'];
            $G['bt_zD'] += $G['bt_zV'] / $G['bt_absV'] * $G['bt_tbb_cm'];

            # ベクトル変化
            $G['bt_xE'] += $G['pc_bb_x'][$G['bt_br']];
            $G['bt_yE'] += $G['pc_bb_y'][$G['bt_br']];

            # ベクトル変化に対応
            $G['bt_xV'] = $G['bt_xE'] - $G['bt_xD'];
            $G['bt_yV'] = $G['bt_yE'] - $G['bt_yD'];
            $G['bt_zV'] = $G['bt_zE'] - $G['bt_zD'];

            # 絶対ベクトル再計算
            $G['bt_absV'] = sqrt(pow($G['bt_xV'], 2) + pow($G['bt_yV'], 2) + pow($G['bt_zV'], 2));

            //------------------------------//
            // 移動計算 変化-ミートポイント間
            //------------------------------//
            # ミートポイントまでの時間比率
            $G['bt_tt_mtp'] = ($G['bt_mtp'] - $G['bt_zD']) / ($G['bt_zE'] - $G['bt_zD']);

            # 変化-ミートまでにかかる時間
            $G['bt_tt'] = $G['bt_tt_mtp'] * ($G['bt_absV'] / $G['bt_psp100']);

            # 移動x,y,z
            $G['bt_xD'] += $G['bt_xV'] * $G['bt_tt_mtp'];
            $G['bt_yD'] += $G['bt_yV'] * $G['bt_tt_mtp'];
            $G['bt_zD'] += $G['bt_zV'] * $G['bt_tt_mtp'];

            # 計算済み秒(投球-変化+変化-ミート)
            $G['bt_tD'] = $G['bt_tbb'] + $G['bt_tt'];

            # スイング判定
            if(abs($G['bt_xD']) <= ($G['bl_r'] / 2 + 21.6) && $G['bt_yD'] >= (45 - $G['bl_r'] / 2) && $G['bt_yD'] < (105 - $G['bl_r'] / 2))
            {
                $G['j_btsw'] = 1;
            }

            # bag
            # $html .= "計算(tbb_cm:". $G['bt_tbb'] ." + bt_tt:". $G['bt_tt'] ."=". $G['bt_tD'] . ")<br>";
            # $html .= '('. $G['bt_xD'] .','. $G['bt_yD'] .','. $G['bt_zD'] .')<br>';

            //------------------------------------------------------------//
            // スイング計算
            //------------------------------------------------------------//
            if($G['j_btsw'])
            {
                //------------------------------//
                // ミートポイント計算
                //------------------------------//
                # ミートポイント
                $G['bt_xMT'] = $G['bt_xD'];
                $G['bt_yMT'] = $G['bt_yD'];
                $G['bt_zMT'] = $G['bt_zD'] - ($G['bl_r'] + $G['bt_r']);

                # ミート時間計算
                $G['bt_tMT'] = $G['bt_tD'];

                # bag
                #$html .= "<br>補正前(". floor($G['bt_xMT']) .",". floor($G['bt_yMT']) .",". floor($G['bt_zMT']) .")<br>";
                #$html .= "ボール(". floor($G['bt_xD']) .",". floor($G['bt_yD']) .",". floor($G['bt_zD']) ."、秒". floor($G['bt_tMT']*100)/100 .")<br>";

                //------------------------------//
                // 内外打ち分け設定 打球多様性
                //------------------------------//
                if($G['bt']['side_b'] == 'R')
                {
                    $G['bt_tMT'] += $G['bt_xMT'] / $G['bt_psp100'];
                }
                else
                {
                    $G['bt_tMT'] -= $G['bt_xMT'] / $G['bt_psp100'];
                }
                //------------------------------//
                // スイング開始、終了計算
                //------------------------------//
                $G['bt_tt_swD45'] = ($G['bt_center'] / 100) / $G['bt_swsp'];
                $G['bt_tt_swS'] = $G['bt_tMT'] - $G['bt_tt_swD45'];
                $G['bt_tt_swE'] = $G['bt_tMT'] + $G['bt_tt_swD45'];

                //------------------------------//
                // 振り遅れ計算
                //------------------------------//
                // 現在なし

                //------------------------------//
                // ミートのずれ
                //------------------------------//
                $rand_str = 100 - $G['bt']['S_b_mt']; if($rand_str < 0){ $rand_str = 0; }
                $rand_mt = mt_rand($rand_str - 10, $rand_str) / 20;
                $rand_mt_dg = mt_rand(1, 360);
                $G['bt_xMT'] += $rand_mt * cos(deg2rad($rand_mt_dg));
                $G['bt_yMT'] += $rand_mt * sin(deg2rad($rand_mt_dg));

                //------------------------------//
                // コース補正
                //------------------------------//
                $rand_str = sqrt(pow($G['bt_xMT'], 2) + pow(($G['bt_yMT'] - 75), 2));
                $rand_mt = mt_rand($rand_str - 10, $rand_str) / 10;
                $rand_mt_dg = mt_rand(1, 360);
                $G['bt_xMT'] += $rand_mt * cos(deg2rad($rand_mt_dg));
                $G['bt_yMT'] += $rand_mt * sin(deg2rad($rand_mt_dg));

                //------------------------------//
                // 変化量 vs ミート 減少補正
                //------------------------------//
                if($G['pc_bbC'] > $G['bt']['S_b_mt'] && $G['pc_br'] != 0)
                {
                    $rand_mt = mt_rand(0, (($G['pc_bbC'] - $G['bt']['S_b_mt']) / 10 + 1) * 1000)/1000; // 変化量 vs ミート
                }
                elseif($G['pc_bbC'] > $G['bt']['S_b_ss'] && $G['pc_br'] == 0)
                {
                    $rand_mt = mt_rand(0, (($G['pc_bbC'] - $G['bt']['S_b_ss']) / 10 + 1) * 1000)/1000; // 速球 vs 反応
                }
                else
                {
                    $rand_mt = 0;
                }
                $rand_mt_dg = mt_rand(1, 360);
                $G['bt_xMT'] += $rand_mt * cos(deg2rad($rand_mt_dg));
                $G['bt_yMT'] += $rand_mt * sin(deg2rad($rand_mt_dg));

                //------------------------------//
                // キレ vs ミート 減少補正
                //------------------------------//
                if($G['pc_bbkC'][$G['pc_br']] > $G['bt']['S_b_mt'])
                {
                    $rand_mt = mt_rand(0, (($G['pc_bbkC'][$G['pc_br']] - $G['bt']['S_b_mt']) / 10 + 1) * 1000)/1000; // 10
                    $rand_mt_dg = mt_rand(1, 360);
                    $G['bt_xMT'] += $rand_mt * cos(deg2rad($rand_mt_dg));
                    $G['bt_yMT'] += $rand_mt * sin(deg2rad($rand_mt_dg));
                }

                //------------------------------//
                // ストレート補正
                //------------------------------//
                if($G['pc_br'] == 0)
                {
                    $rand_mt = mt_rand(0, 1000)/1000; // 10
                    $rand_mt_dg = mt_rand(1, 360);
                    $G['bt_xMT'] += $rand_mt * cos(deg2rad($rand_mt_dg));
                    $G['bt_yMT'] += $rand_mt * sin(deg2rad($rand_mt_dg));
                }

                # bag
                # $html .= "補正後(". floor($G['bt_xMT']) .",". floor($G['bt_yMT']) .",". floor($G['bt_zMT']) .":". floor($G['bt_tMT']*100)/100 .")";
            }

            //------------------------------------------------------------//
            // 盗塁計算
            //------------------------------------------------------------//
            $G['j_sb'] = 0;

            // 企画判定
            if($G['team_sb'] && ((!empty($G['base'][1]) && empty($G['base'][2])) || (!empty($G['base'][2]) && empty($G['base'][3]))))
            {
                // 確率判定
                $mt_rand = mt_rand(0, 1000);
                if(($G['team_sb'] == 3 && $mt_rand < 500) || ($G['team_sb'] == 2 && $mt_rand < 400) || ($G['team_sb'] == 1 && $mt_rand < 300))
                {
                    // 2→3塁
                    if(!empty($G['base'][2]) && empty($G['base'][3]))
                    {
                        $G['sb_rn'] = $G['rn'][2];
                    }
                    else // 1→2塁
                    {
                        $G['sb_rn'] = $G['rn'][1];
                    }
                    $SB_BTYPE = explode(",", $G['sb_rn']['bt_type']);

                    // ランナー設定反映
                    if(($SB_BTYPE[0] && !empty($G['base'][1]) && empty($G['base'][2])) || ($SB_BTYPE[1] && !empty($G['base'][2]) && empty($G['base'][3])))
                    {
                        // 走者データ取得
                        $G['sb_rn_sp'] = $this->_game_bsp($G['sb_rn']['S_b_sp']); // 速度
                        $G['sb_rn_rc'] = $G['sb_rn']['S_b_ss'] / 40 + 1.8; // リード
                        $G['sb_rn_sec'] = ($G['base_l'] - $G['sb_rn_rc']) / $G['sb_rn_sp']; // かかる秒数
                        $G['sb_rn_sec095'] = $G['sb_rn_sec'] / 0.95; // 95%能力時
                        $G['sb_rn_sec100'] = $G['sb_rn_sec'] / 1.00;
                        $G['sb_rn_sec105'] = $G['sb_rn_sec'] / 1.05;

                        // 投手
                        $G['sb_pc_sec'] = (18.44 - 1.20) / ($G['pc_spC'][0] / 3.6);
                        $G['sb_pc_rcs'] = 0.695; // モーション時間

                        // 捕手データ取得
                        $G['sb_df'] = $G['df_ar'][$G['df_d'][2]];
                        $G['sb_df_rcs'] = -0.0025 * $G['sb_df']['S_b_df'] + 0.9;
                        $G['sb_df_sp'] = $this->_disp_sp($G['sb_df']['S_b_sf'], $G['sb_df']['cond']);

                        // 守備計算
                        if(!empty($G['base'][2]) && empty($G['base'][3])) // 2→3塁
                        {
                            $G['sb_df_sec_s'] = ($G['base_l'] + 0.6) / ($G['sb_df_sp'] / 3.6);

                            # タッチ判定
                            $G['sb_df5'] = $G['df_ar'][$G['df_d'][5]];
                            $G['sb_df_sec_t'] = -0.001 * $G['sb_df5']['S_b_df'] + 0.15;
                        }
                        else // 1→2塁
                        {
                            $G['sb_df_sec_s'] = ($G['base_l'] * sqrt(2) + 0.6) / ($G['sb_df_sp'] / 3.6);

                            # タッチ判定
                            $G['sb_df4'] = $G['df_ar'][$G['df_d'][4]];
                            $G['sb_df6'] = $G['df_ar'][$G['df_d'][6]];

                            if($G['sb_df4']['S_b_df'] >= $G['sb_df6']['S_b_df'])
                            {
                                $G['sb_df_sec_t'] = -0.001 * $G['sb_df4']['S_b_df'] + 0.15;
                            }
                            else
                            {
                                $G['sb_df_sec_t'] = -0.001 * $G['sb_df6']['S_b_df'] + 0.15;
                            }
                        }

                        // 秒数取得
                        $G['sb_df_sec'] = $G['sb_pc_sec'] + $G['sb_pc_rcs'] + $G['sb_df_rcs'] + $G['sb_df_sec_t']; // 投手投秒数+モーション+捕手モーション+守備タッチ
                        $G['sb_df_sec095'] = $G['sb_df_sec_s'] / 0.95 + $G['sb_df_sec'];
                        $G['sb_df_sec100'] = $G['sb_df_sec_s'] / 1.00 + $G['sb_df_sec'];
                        $G['sb_df_sec105'] = $G['sb_df_sec_s'] / 1.05 + $G['sb_df_sec'];

                        // 作戦ごとの傾向による設定
                        if($G['team_sb'] == 3 && $G['sb_rn_sec105'] <= $G['sb_df_sec100'])
                        {
                            $G['j_sb'] = 1;
                        }
                        elseif($G['team_sb'] == 2 && $G['sb_rn_sec100'] <= $G['sb_df_sec100'])
                        {
                            $G['j_sb'] = 1;
                        }
                        elseif($G['team_sb'] == 1 && $G['sb_rn_sec095'] <= $G['sb_df_sec105'])
                        {
                            $G['j_sb'] = 1;
                        }

                        // 表示
                        if($G['j_sb'])
                        {
                            $html .= "<strong>ランナースタート!</strong>";
                        }
                    }
                }
            }

            //------------------------------------------------------------//
            // 実投球計算
            //------------------------------------------------------------//
            # 経過時間設定
            $G['bl_t'] = 0;

            # 位置座標 初期設定
            $G['bl_x'] = $G['pc_xS'];
            $G['bl_y'] = $G['pc_yS'];
            $G['bl_z'] = $G['pc_zS'];

            # ベクトル設定
            $G['bv_x'] = $G['pc_xE'] - $G['bl_x'];
            $G['bv_y'] = $G['pc_yE'] - $G['bl_y'];
            $G['bv_z'] = $G['pc_zE'] - $G['bl_z'];

            # 絶対ベクトル
            $G['bv_abs'] = sqrt(pow($G['bv_x'], 2) + pow($G['bv_y'], 2) + pow($G['bv_z'], 2));

            # 各種判定
            # $G['j_btsw'] = 1 or 0; // スイング
            $G['j_st'] = 0; // ストライク
            $G['j_bt'] = 0; // 打撃
            $G['j_db'] = 0; // 死球
            $G['j_ct'] = 0; // カット

            //------------------------------//
            // 初期移動計算
            //------------------------------//
            # 移動速度 cm/s
            $G['bl_sp'] = $G['pc_sp_ms'] * 100; ## なんかおかしくない???

            # 投球にかかる時間
            $G['bl_tt'] = $G['bv_abs'] / $G['bl_sp'];

            # 変化開始秒数
            $G['bl_tbb'] = $G['bl_tt'] * (0.007 * $G['pc_bbkC'][$G['pc_br']] + 0.2);

            //------------------------------//
            // カット
            //------------------------------//
            if($G['pc_br'] != $G['bt_br'] && $G['c_s'] >= 2 && $G['j_btsw'])
            {
                $G['j_ct'] = 1;
            }

            //------------------------------//
            // 投球-MTP
            //------------------------------//
            if($G['j_ct']) // カット
            {
                # 表示
                $html .= $this->_game_bjg($G['bl_x'], $G['bl_y'], $G['bt']['side_b'])."の" . $this->_game_br($G['pc_br'], $G['pc']) . "、".floor($G['pc_sp'])."キロ!";

                // ボール位置
                $G['BL_X'] = 0;
                $G['BL_Y'] = 0.75;
                $G['BL_Z'] = 0.45;

                // 確率計算
                $ct_cor = 1;
                # 変化量
                if($G['pc_bbC'] > $G['bt']['S_b_mt'] && $G['pc_br'] != 0)
                {
                    $ct_cor *= 1 - ($G['pc_bbC'] - $G['bt']['S_b_mt']) / 30;
                }
                elseif($G['pc_bbC'] > $G['bt']['S_b_ss'] && $G['pc_br'] == 0)
                {
                    $ct_cor *= 1 - ($G['pc_bbC'] - $G['bt']['S_b_ss']) / 30;
                }

                # キレ
                if($G['pc_bbkC'][$G['pc_br']] > $G['bt']['S_b_mt'])
                {
                    $ct_cor *= 1 - ($G['pc_bbkC'][$G['pc_br']] - $G['bt']['S_b_mt']) / 30;
                }

                // ランダム
                $mt_rand = mt_rand(1, 100);
                if($mt_rand * $ct_cor >= 70) // カット成功
                {
                    $G['j_bt'] = 1;
                    // ボールベクトル
                    $G['BT_X'] = 0;
                    $G['BT_Y'] = 10;
                    $G['BT_Z'] = -10;
                }
                elseif($mt_rand * $ct_cor >= 15) // カット失敗
                {
                    $G['j_bt'] = 1;
                    // ボールベクトル
                    $G['BT_X'] = mt_rand(-10, 10);
                    $G['BT_Y'] = mt_rand(-10, 10);
                    $G['BT_Z'] = mt_rand(0, 10);
                }
                else // 三振
                {
                    $G['j_st'] = 1;
                }
            }
            elseif($G['j_btsw'] == 1) // 通常スイング
            {
                //------------------------------//
                // スイング開始点までの移動計算
                //------------------------------//
                # 変化開始 <= スイング開始
                if($G['bl_tbb'] <= $G['bt_tt_swS'])
                {
                    # 移動距離計算
                    $G['bl_mv'] = $G['bl_sp'] * $G['bl_tbb'];

                    # 座標移動
                    $G['bl_x'] += $G['bv_x'] / $G['bv_abs'] * $G['bl_mv'];
                    $G['bl_y'] += $G['bv_y'] / $G['bv_abs'] * $G['bl_mv'];
                    $G['bl_z'] += $G['bv_z'] / $G['bv_abs'] * $G['bl_mv'];

                    # 終点変化
                    if(mt_rand(1, 100) >= 80) // 変化量普通
                    {
                        $G['pc_xE'] += $G['pc_bb_x'][$G['pc_br']] * mt_rand(95, 105) / 100;
                        $G['pc_yE'] += $G['pc_bb_y'][$G['pc_br']] * mt_rand(95, 105) / 100;
                    }
                    elseif(mt_rand(1, 100) >= 50) // 変化量多い
                    {
                        $G['pc_xE'] += $G['pc_bb_x'][$G['pc_br']] * mt_rand(110, 120) / 100;
                        $G['pc_yE'] += $G['pc_bb_y'][$G['pc_br']] * mt_rand(110, 120) / 100;
                    }
                    else // 変化量少ない
                    {
                        $G['pc_xE'] += $G['pc_bb_x'][$G['pc_br']] * mt_rand(80, 95) / 100;
                        $G['pc_yE'] += $G['pc_bb_y'][$G['pc_br']] * mt_rand(80, 95) / 100;
                    }

                    # ベクトル変化
                    $G['bv_x'] = $G['pc_xE'] - $G['bl_x'];
                    $G['bv_y'] = $G['pc_yE'] - $G['bl_y'];
                    $G['bv_z'] = $G['pc_zE'] - $G['bl_z'];

                    # 絶対ベクトル再計算
                    $G['bv_abs'] = sqrt(pow($G['bv_x'], 2) + pow($G['bv_y'], 2) + pow($G['bv_z'], 2));

                    # 経過時間設定
                    $G['bl_t'] = $G['bl_tbb'];

                    # bag
                    # $html .= "変化(". floor($G['bl_x']) .",". floor($G['bl_y']) .",". floor($G['bl_z']) .":". floor($G['bl_t']*100)/100 .")";
                }

                # スイング開始点までの移動計算
                $G['bl_mv'] = $G['bl_sp'] * ($G['bt_tt_swS'] - $G['bl_t']);

                # 座標移動
                $G['bl_x'] += $G['bv_x'] / $G['bv_abs'] * $G['bl_mv'];
                $G['bl_y'] += $G['bv_y'] / $G['bv_abs'] * $G['bl_mv'];
                $G['bl_z'] += $G['bv_z'] / $G['bv_abs'] * $G['bl_mv'];

                # 経過時間設定
                $G['bl_t'] = $G['bt_tt_swS'];

                # 表示
                $html .= $this->_game_bjg($G['bl_x'], $G['bl_y'], $G['bt']['side_b'])."の" . $this->_game_br($G['pc_br'], $G['pc']) . "、".floor($G['pc_sp'])."キロ!";

                //------------------------------//
                // 実計算
                //------------------------------//
                # Y
                $dBLy1 = $G['bv_y'] / $G['bv_abs'] * $G['bl_sp'];
                $dBLy0 = $G['bl_y'];
                $dBTy1 = 0;
                $dBTy0 = $G['bt_yMT'];
                #$html .= "Y:BL1:{$dBLy1}, 0:{$dBLy0} BT1:{$dBTy1}, 0:{$dBTy0}<br>";

                # Z
                $dBLz1 = $G['bv_z'] / $G['bv_abs'] * $G['bl_sp'];
                $dBLz0 = $G['bl_z'];
                $dBTz1 = $G['bt_swsp'] * 100;
                $dBTz0 = $G['bt_zMT'] - $G['bt_center'];
                #$html .= "Z:BL1:{$dBLz1}, 0:{$dBLz0} BT1:{$dBTz1}, 0:{$dBTz0}<br>";

                # 係数計算
                $dCA = $dBTy1 - $dBLy1;
                $dCB = $dBTy0 - $dBLy0;
                $dCC = $dBTz1 - $dBLz1;
                $dCD = $dBTz0 - $dBLz0;

                # 解の公式係数 y = at^2 + bt + c
                $dCa = pow($dCA, 2) + pow($dCC, 2);
                $dCb = 2 * ($dCA * $dCB + $dCC * $dCD);
                $dCc = pow($dCB, 2) + pow($dCD, 2) - pow(($G['bl_r'] + $G['bt_r']), 2);

                # 判別式
                $dCd = pow($dCb, 2) - 4 * $dCa * $dCc;

                # 当たり判定
                if($dCd >= 0) // 当たり
                {
                    # t計算式
                    $dCt1 = (-$dCb + sqrt($dCd))/(2 * $dCa);
                    $dCt2 = (-$dCb - sqrt($dCd))/(2 * $dCa);
                    if($dCt1 > $dCt2){ $dCt = $dCt2; }else{ $dCt = $dCt1; }
                    // $dCt = 的中時間

                    // 移動計算
                    # ミートポイント
                    $G['MT_X'] = $G['bt_xMT'];
                    $G['MT_Y'] = $G['bt_yMT'];
                    $G['MT_Z'] = $G['bt_swsp'] * 100 * $dCt + $G['bt_zMT'] - $G['bt_center'];

                    # ボール位置
                    $G['bl_x'] += $G['bv_x'] / $G['bv_abs'] * $G['bl_sp'] * $dCt;
                    $G['bl_y'] += $G['bv_y'] / $G['bv_abs'] * $G['bl_sp'] * $dCt;
                    $G['bl_z'] += $G['bv_z'] / $G['bv_abs'] * $G['bl_sp'] * $dCt;

                    #$html .= "t = {$dCt}<br>";
                    #$html .= "BL座標(". floor($G['bl_x']) .",". floor($G['bl_y']) .",". floor($G['bl_z']) .") → ";
                    #$html .= "BT座標(". floor($G['MT_X']) .",". floor($G['MT_Y']) .",". floor($G['MT_Z']) .")<br>";

                    //当たり判定・角度計算
                    $dANG = 1 / ($G['bt_tt_swD45'] / 45) * $dCt - 45;
                    if(abs($G['MT_X'] - $G['bl_x']) <= $G['bt_meet'] && abs($dANG) <= 90)
                    {
                        # 打撃判定
                        $G['j_bt'] = 1;
                        $G['MT_ANG'] = $dANG;

                        # bag
                        #$html .= "理論値(" .(floor(($G['bt_r'] + $G['bl_r'])*100)/100). ")=計算値(" .(floor(sqrt(pow(($G['MT_Y'] - $G['bl_y']), 2) + pow(($G['MT_Z'] - $G['bl_z']), 2)) * 100)/100). ")<br>";

                        # ボールベクトル解析
                        $G['d_bl_x'] = $G['bv_x'] / $G['bv_abs'] * $G['pc_sp'];
                        $G['d_bl_y'] = $G['bv_y'] / $G['bv_abs'] * $G['pc_sp'];
                        $G['d_bl_z'] = $G['bv_z'] / $G['bv_abs'] * $G['pc_sp'];
                        #$html .= "BL_DIR:(x".floor($G['d_bl_x']).",y".floor($G['d_bl_y']).",z".floor($G['d_bl_z']).")座標(". floor($G['bl_x']) .",". floor($G['bl_y']) .",". floor($G['bl_z']) .")<br>";

                        # バットベクトル解析
                        $G['d_bt_x'] = $G['bt_swsp'] * sin(deg2rad($G['MT_ANG']));
                        $G['d_bt_y'] = 0;
                        $G['d_bt_z'] = $G['bt_swsp'] * cos(deg2rad($G['MT_ANG']));
                        #$html .= "BT_DIR:" . (floor($G['bt_swsp']*100)/100) . "m/s(x".floor($G['d_bt_x']).",z".floor($G['d_bt_z']).")座標(". floor($G['MT_X']) .",". floor($G['MT_Y']) .",". floor($G['MT_Z']) .")<br>";

                        # ベクトル解析
                        $G['d_tl_ang'] = atan2(($G['bl_z'] - $G['MT_Z']), ($G['bl_y'] - $G['MT_Y'])); // ラジアン
                        #$html .= "BL(Y".floor($G['bl_y']).",Z".floor($G['bl_z']).") vs BT(Y".floor($G['MT_Y']).",Z".floor($G['MT_Z']).")=".floor(rad2deg($G['d_tl_ang']))."度<br>";

                        $G['d_bl_ver'] = $G['d_bl_y'] * cos($G['d_tl_ang']) + $G['d_bl_z'] * sin($G['d_tl_ang']); // 衝突方向ベクトル
                        $G['d_bl_par'] = -$G['d_bl_y'] * sin($G['d_tl_ang']) + $G['d_bl_z'] * cos($G['d_tl_ang']); // 平行方向ベクトル

                        $G['d_bt_ver'] = $G['d_bt_y'] * cos($G['d_tl_ang']) + $G['d_bt_z'] * sin($G['d_tl_ang']);
                        $G['d_bt_par'] = -$G['d_bt_y'] * sin($G['d_tl_ang']) + $G['d_bt_z'] * cos($G['d_tl_ang']);

                        #$html .= "BL(Y" .floor($G['d_bl_y']). ",Z" .floor($G['d_bl_z']). ")→(衝" .floor($G['d_bl_ver']). ",平" .floor($G['d_bl_par']). ")<br>";
                        #$html .= "BT(Y" .floor($G['d_bt_y']). ",Z" .floor($G['d_bt_z']). ")→(衝" .floor($G['d_bt_ver']). ",平" .floor($G['d_bt_par']). ")<br>";

                        # 反発係数計算
                        $G['d_cor_x'] = 1 / (abs($G['MT_X'] - $G['bl_x']) + 1);
                        $G['d_cor_y'] = 1 - abs($G['MT_Y'] - $G['bl_y']) * 0.2;
                        $G['d_cor_MT'] = $G['d_cor_x'] * $G['d_cor_y'] * $G['c_cor'];

                        # 正面衝突計算 YZ
                        $m1 = $G['bl_wg'];
                        $m2 = $G['bt_wg'];
                        $s1 = $G['d_bl_ver'];
                        $s2 = $G['d_bt_ver'];

                        $ds_bl = ($m1*$s1 + $m2*$s2 - $m2*$G['d_cor_MT']*($s1-$s2))/($m1+$m2);
                        $ds_bt = ($m1*$s1 + $m2*$s2 + $m1*$G['d_cor_MT']*($s1-$s2))/($m1+$m2);

                        #$html .= "1:{$m1}g × {$s1}m/s vs 2:{$m2}g × {$s2}m/s<br>";
                        #$html .= "1:{$ds_bl}m/s × 2:{$ds_bt}m/s<br>";
                        #$html .= "後(" . floor($ds_bl) . "," . floor($G['d_bl_par']) . ")<br>";

                        # 計算完了
                        $G['BT_Y'] = $ds_bl * cos(-$G['d_tl_ang']) + $G['d_bl_par'] * sin(-$G['d_tl_ang']);
                        $G['BT_Z'] = -$ds_bl * sin(-$G['d_tl_ang']) + $G['d_bl_par'] * cos(-$G['d_tl_ang']);

                        // 左右打ち分け計算
                        # ベクトル解析
                        $G['dX_tl_ang'] = atan2(($G['MT_X'] - $G['bl_x']), ($G['MT_Z'] - $G['bl_z'])); // ラジアン

                        $G['dX_bl_ver'] = $G['d_bl_x'] * cos($G['dX_tl_ang']) + $G['d_bl_z'] * sin($G['dX_tl_ang']); // 衝突方向ベクトル
                        $G['dX_bl_par'] = -$G['d_bl_x'] * sin($G['dX_tl_ang']) + $G['d_bl_z'] * cos($G['dX_tl_ang']); // 平行方向ベクトル

                        $G['dX_bt_ver'] = $G['d_bt_x'] * cos($G['dX_tl_ang']) + $G['d_bt_z'] * sin($G['dX_tl_ang']);
                        $G['dX_bt_par'] = -$G['d_bt_x'] * sin($G['dX_tl_ang']) + $G['d_bt_z'] * cos($G['dX_tl_ang']);

                        # 正面衝突計算 XZ
                        $m1 = $G['bl_wg'];
                        $m2 = $G['bt_wg'];
                        $s1 = $G['dX_bl_ver'];
                        $s2 = $G['dX_bt_ver'];

                        $dsX_bl = ($m1*$s1 + $m2*$s2 - $m2*$G['d_cor_MT']*($s1-$s2))/($m1+$m2);
                        $dsX_bt = ($m1*$s1 + $m2*$s2 + $m1*$G['d_cor_MT']*($s1-$s2))/($m1+$m2);

                        # 計算完了
                        $G['BT_X'] = $dsX_bl * cos(-$G['dX_tl_ang']) + $G['dX_bl_par'] * sin(-$G['dX_tl_ang']);
                        #$html .= "打(X" . floor($G['BT_X']) . ",Y" . floor($G['BT_Y']) . ",Z" . floor($G['BT_Z']) . ")係数:". (floor($G['d_cor_MT']*100)/100) ."<br>";

                        # 初期位置計算(m換算)
                        $G['BL_X'] = $G['bl_x'] / 100;
                        $G['BL_Y'] = $G['bl_y'] / 100;
                        $G['BL_Z'] = $G['bl_z'] / 100;
                    }
                }

                # 簡易ストライク判定
                $G['j_st_zv'] = -$G['bv_z'] / $G['bv_abs'] * $G['bl_sp'];
                $G['j_st_t1'] = ($G['bl_z'] - 43.2) / $G['j_st_zv'];
                $G['j_st_t2'] = ($G['bl_z'] - 21.6) / $G['j_st_zv'];

                # 当たり判定 - 前
                $G['j_st_x1'] = $G['bl_x'] + $G['bv_x'] / $G['bv_abs'] * $G['bl_sp'] * $G['j_st_t1'];
                $G['j_st_y1'] = $G['bl_y'] + $G['bv_y'] / $G['bv_abs'] * $G['bl_sp'] * $G['j_st_t1'];
                $G['j_st_z1'] = $G['bl_z'] + $G['bv_z'] / $G['bv_abs'] * $G['bl_sp'] * $G['j_st_t1'];

                # 当たり判定 - 後
                $G['j_st_x2'] = $G['bl_x'] + $G['bv_x'] / $G['bv_abs'] * $G['bl_sp'] * $G['j_st_t2'];
                $G['j_st_y2'] = $G['bl_y'] + $G['bv_y'] / $G['bv_abs'] * $G['bl_sp'] * $G['j_st_t2'];
                $G['j_st_z2'] = $G['bl_z'] + $G['bv_z'] / $G['bv_abs'] * $G['bl_sp'] * $G['j_st_t2'];

                if((abs($G['j_st_x1']) <= (21.6 + $G['bl_r'] / 2) && $G['j_st_y1'] < (105 - $G['bl_r'] / 2) && $G['j_st_y1'] >= (45 - $G['bl_r'] / 2)) || (abs($G['j_st_x2']) <= (21.6 + $G['bl_r'] / 2) && $G['j_st_y2'] < (105 - $G['bl_r'] / 2) && $G['j_st_y2'] >= (45 - $G['bl_r'] / 2)))
                {
                    $G['j_st'] = 1;
                }
            }
            else // 見た場合
            {
                # 移動距離計算
                $G['bl_mv'] = $G['bl_sp'] * $G['bl_tbb'];

                # 座標移動
                $G['bl_x'] += $G['bv_x'] / $G['bv_abs'] * $G['bl_mv'];
                $G['bl_y'] += $G['bv_y'] / $G['bv_abs'] * $G['bl_mv'];
                $G['bl_z'] += $G['bv_z'] / $G['bv_abs'] * $G['bl_mv'];

                # 終点変化
                $G['pc_xE'] += $G['pc_bb_x'][$G['pc_br']];
                $G['pc_yE'] += $G['pc_bb_y'][$G['pc_br']];

                # ベクトル変化
                $G['bv_x'] = $G['pc_xE'] - $G['bl_x'];
                $G['bv_y'] = $G['pc_yE'] - $G['bl_y'];
                $G['bv_z'] = $G['pc_zE'] - $G['bl_z'];

                # 絶対ベクトル再計算
                $G['bv_abs'] = sqrt(pow($G['bv_x'], 2) + pow($G['bv_y'], 2) + pow($G['bv_z'], 2));

                # 経過時間設定
                $G['bl_t'] = $G['bl_tbb'];

                # 表示
                $html .= $this->_game_bjg($G['bl_x'], $G['bl_y'], $G['bt']['side_b'])."の" . $this->_game_br($G['pc_br'], $G['pc']) . "、".floor($G['pc_sp'])."キロ!見ました";

                # 簡易ストライク判定
                $G['j_st_zv'] = -$G['bv_z'] / $G['bv_abs'] * $G['bl_sp'];
                $G['j_st_t1'] = ($G['bl_z'] - 43.2) / $G['j_st_zv'];
                $G['j_st_t2'] = ($G['bl_z'] - 21.6) / $G['j_st_zv'];

                # 前側判定(1)
                $G['j_st_x1'] = $G['bl_x'] + $G['bv_x'] / $G['bv_abs'] * $G['bl_sp'] * $G['j_st_t1'];
                $G['j_st_y1'] = $G['bl_y'] + $G['bv_y'] / $G['bv_abs'] * $G['bl_sp'] * $G['j_st_t1'];
                $G['j_st_z1'] = $G['bl_z'] + $G['bv_z'] / $G['bv_abs'] * $G['bl_sp'] * $G['j_st_t1'];

                # 後ろ判定(2)
                $G['j_st_x2'] = $G['bl_x'] + $G['bv_x'] / $G['bv_abs'] * $G['bl_sp'] * $G['j_st_t2'];
                $G['j_st_y2'] = $G['bl_y'] + $G['bv_y'] / $G['bv_abs'] * $G['bl_sp'] * $G['j_st_t2'];
                $G['j_st_z2'] = $G['bl_z'] + $G['bv_z'] / $G['bv_abs'] * $G['bl_sp'] * $G['j_st_t2'];

                if((abs($G['j_st_x1']) <= (21.6 + $G['bl_r'] / 2) && $G['j_st_y1'] < (105 - $G['bl_r'] / 2) && $G['j_st_y1'] >= (45 - $G['bl_r'] / 2)) || (abs($G['j_st_x2']) <= (21.6 + $G['bl_r'] / 2) && $G['j_st_y2'] < (105 - $G['bl_r'] / 2) && $G['j_st_y2'] >= (45 - $G['bl_r'] / 2)))
                {
                    $G['j_st'] = 1;
                }
            }

            //------------------------------------------------------------//
            // 判定
            //------------------------------------------------------------//
            $G['get_pt'] = 0;

            if($G['j_btsw'] && !$G['j_bt'])
            {
                $html .= "空振り!";
                $G['c_s']++;
            }
            elseif(!$G['j_btsw'] && $G['j_st'])
            {
                $html .= "ストライク";
                $G['c_s']++;
            }
            elseif(!$G['j_btsw'] && !$G['j_st'])
            {
                $html .= "ボール";
                $G['c_b']++;
            }
            elseif($G['j_btsw'] && $G['j_bt'])
            {
                $html .= "打った!";

                # 初期位置等設定
                # $G['BL_X'], $G['BL_Y'], $G['BL_Z'] // 位置(m)
                # $G['BT_X'], $G['BT_Y'], $G['BT_Z'] // ベクトル(m/s)
                #$html .= "(BL:".(floor($G['BL_X'] * 100)/100).",".(floor($G['BL_Y'] * 100)/100).",".(floor($G['BL_Z'] * 100)/100).")<br>";
                #$html .= "(BT:".(floor($G['BT_X'] * 100)/100).",".(floor($G['BT_Y'] * 100)/100).",".(floor($G['BT_Z'] * 100)/100).")<br>";

                # 変数設定
                $G['RS_bt'] = $G['RS_df_pos'] = null; // 結果
                $G['RS_sec'] = $G['RS_df_sec'] = $G['RS_er_sec'] = $G['RS_fe'] = $G['RS_bb'] = $G['RS_stop'] = $G['RS_hr'] = $G['RS_f'] = 0;
                // 経過時間, エラーwt時間, フェンス当たり判定, バウンド回数, ボール停止, ホームラン飛距離, フェア判定

                # フェンス距離設定
                $G['RS_fe_l'] = $G['bp_fe_c'] - ($G['bp_fe_c'] - $G['bp_fe_w']) / 45 * abs(rad2deg(atan2($G['BT_Z'], $G['BT_X'])) - 90);

                # 計算開始
                $G['bb_stop'] = 10;
                while($G['RS_bb'] <= $G['bb_stop'])
                {
                    // ベクトル解析
                    # X
                    $G['d_Xa'] = $this->_game_air_res($G['BT_X']);
                    $G['d_Xb'] = $G['BT_X'];
                    $G['d_Xc'] = $G['BL_X'];

                    # Y
                    $G['d_Ya'] = -1/2 * 9.81 + $this->_game_air_res($G['BT_Y']);
                    $G['d_Yb'] = $G['BT_Y'];
                    $G['d_Yc'] = $G['BL_Y'];

                    # Z
                    $G['d_Za'] = $this->_game_air_res($G['BT_Z']);
                    $G['d_Zb'] = $G['BT_Z'];
                    $G['d_Zc'] = $G['BL_Z'];

                    # 落球位置(y = 0m)計算
                    $G['d_drop_d'] = pow($G['d_Yb'], 2) - 4 * $G['d_Ya'] * ($G['d_Yc'] - $G['bl_r'] / 100); // 解の公式
                    $G['d_drop_t'] = (-$G['d_Yb'] - sqrt($G['d_drop_d'])) / (2 * $G['d_Ya']);

                    # 捕球可能位置(y = 2.0m)計算
                    $G['d_ct_d'] = pow($G['d_Yb'], 2) - 4 * $G['d_Ya'] * ($G['d_Yc'] - 2.0); // 解の公式
                    if($G['d_ct_d'] >= 0)
                    {
                        $G['d_ct_t0'] = (-$G['d_Yb'] + sqrt($G['d_ct_d'])) / (2 * $G['d_Ya']);
                        $G['d_ct_t1'] = (-$G['d_Yb'] - sqrt($G['d_ct_d'])) / (2 * $G['d_Ya']);
                        #$html .= "(ct0:" . (floor($G['d_ct_t0'] * 100)/100) . "s)";
                        #$html .= "(ct1:" . (floor($G['d_ct_t1'] * 100)/100) . "s)";
                    }
                    #$html .= "(d:" . (floor($G['d_drop_t'] * 10)/10) . "s)";

                    # ストップ
                    if($G['d_drop_t'] <= 0.001)
                    {
                        $G['RS_stop'] = 1;
                    }

                    # 捕球計算(距離)
                    #$html .= "bb:{$G['RS_bb']}=NEED" . (floor($G['d_drop_t']*100)/100) . "s";
                    $G['d_ct'] = [];
                    for($i = 1; $i <= 9; $i++)
                    {
                        # 守備者/守備位置読み込み
                        $G['df_man'] = $G['df_ar'][$G['df_d'][$i]];
                        $G['df_pos'] = explode(",", $G['bp_dpos'][$i]);

                        # 距離計算
                        if($G['RS_stop'] || $G['RS_bb'] == $G['bb_stop']) // 静止
                        {
                            # 距離計算 t = 0
                            $G['df_abs'] = sqrt(pow(($G['BL_X'] - $G['df_pos'][0]), 2) + pow(($G['BL_Z'] - $G['df_pos'][1]), 2));
                        }
                        else // その他
                        {
                            # t = 0~$G['d_drop_t']
                            $G['d_BL_T'] = $G['d_drop_t'];
                            $G['d_BL_X'] = $G['d_Xa'] * pow($G['d_BL_T'], 2) + $G['d_Xb'] * $G['d_BL_T'] + $G['d_Xc'];
                            $G['d_BL_Z'] = $G['d_Za'] * pow($G['d_BL_T'], 2) + $G['d_Zb'] * $G['d_BL_T'] + $G['d_Zc'];
                            $G['df_abs'] = sqrt(pow(($G['d_BL_X'] - $G['df_pos'][0]), 2) + pow(($G['d_BL_Z'] - $G['df_pos'][1]), 2));
                        }

                        // 空中守備
                        # 守備
                        $G['df_sp'] = 0.12 * ($G['df_man']['S_b_sp'] + $G['df_man']['S_b_df'] * 3) / 4 + 7;
                        $G['df_ws'] = 0.2 - 0.002 * $G['df_man']['S_b_ss'];

                        # 補正
                        if($i == 1){ $G['df_ws'] += 1; }
                        if($i == 2){ $G['df_ws'] += 2; }

                        $dA = pow($G['d_Xb'], 2) + pow($G['d_Zb'], 2) - pow($G['df_sp'], 2);
                        $dB = 2 * ($G['d_Xb'] * $G['d_Xc'] - $G['d_Xb'] * $G['df_pos'][0] + $G['d_Zb'] * $G['d_Zc'] - $G['d_Zb'] * $G['df_pos'][1]);
                        $dC = pow(($G['d_Xc'] - $G['df_pos'][0]), 2) + pow(($G['d_Zc'] - $G['df_pos'][1]), 2) + $G['df_sp'] * $G['df_ws'];

                        $dD = pow($dB, 2) - 4 * $dA * $dC;

                        # D >= 0
                        $df_flag = 0;
                        if($dD >= 0)
                        {
                            $dT1 = (-$dB - sqrt($dD)) / (2 * $dA);
                            $dT2 = (-$dB + sqrt($dD)) / (2 * $dA);

                            if($G['d_ct_d'] >= 0 && ($G['d_ct_t0'] > 0 || $G['d_ct_t1'] > 0))
                            {
                                if($this->_game_range($dT1, 0, $G['d_ct_t0']) || $this->_game_range($dT1, $G['d_ct_t1'], $G['d_drop_t']))
                                {
                                    $G['d_BL_T'] = $dT1;
                                    $df_flag = 1;
                                }
                                elseif($this->_game_range($dT2, 0, $G['d_ct_t0']) && $dT1 < 0)
                                {
                                    $G['d_BL_T'] = 0;
                                    $df_flag = 1;
                                }
                                elseif($this->_game_range($dT2, $G['d_ct_t1'], $G['d_drop_t']) && $dT1 < $G['d_ct_t1'])
                                {
                                    $G['d_BL_T'] = $G['d_ct_t1'];
                                    $df_flag = 1;
                                }
                            }
                            else
                            {
                                if($this->_game_range($dT1, 0, $G['d_drop_t']))
                                {
                                    $G['d_BL_T'] = $dT1;
                                    $df_flag = 1;
                                }
                                elseif($this->_game_range($dT2, 0, $G['d_drop_t']) && $dT1 < 0)
                                {
                                    $G['d_BL_T'] = 0;
                                    $df_flag = 1;
                                }
                            }
                        }

                        // 捕球可能
                        if($df_flag && !($i == 2 && $G['RS_bb'] == 0))
                        {
                            $G['d_BL_X'] = $G['d_Xa'] * pow($G['d_BL_T'], 2) + $G['d_Xb'] * $G['d_BL_T'] + $G['d_Xc'];
                            $G['d_BL_Y'] = $G['d_Ya'] * pow($G['d_BL_T'], 2) + $G['d_Yb'] * $G['d_BL_T'] + $G['d_Yc'];
                            if($G['d_BL_Y'] < 0 || $G['d_BL_Y'] > 2.0 ){ continue; }
                            # バウンド判定
                            if($G['RS_bb'])
                            {
                                $G['RS_bt'] = 'G';
                            }
                            else
                            {
                                $G['RS_bt'] = 'F';
                            }
                            # 位置座標特定
                            $G['RS_df_pos'] = $i;
                            $G['BL_X'] = $G['d_Xa'] * pow($G['d_BL_T'], 2) + $G['d_Xb'] * $G['d_BL_T'] + $G['d_Xc'];
                            $G['BL_Y'] = $G['d_Ya'] * pow($G['d_BL_T'], 2) + $G['d_Yb'] * $G['d_BL_T'] + $G['d_Yc'];
                            $G['BL_Z'] = $G['d_Za'] * pow($G['d_BL_T'], 2) + $G['d_Zb'] * $G['d_BL_T'] + $G['d_Zc'];
                            $G['RS_df_sec'] = $G['RS_sec'] + $G['d_BL_T'];

                            break 2;
                        }
                        // 空中守備ここまで

                        # 内外野判定
                        if(sqrt(pow($G['d_BL_X'], 2) + pow($G['d_BL_Z'], 2)) > 42 && $G['d_BL_Z'] > 0) // 外野
                        {
                            if($i >= 1 && $i <= 6){ continue; }
                        }
                        else // 内野
                        {
                            if($i >= 7 && $i <= 9){ continue; }
                        }

                        # 設定
                        $G['d_ct'][$i] = $G['df_abs'];

                        #$html .= "<br>$i:(x".floor($G['d_BL_X']).",z".floor($G['d_BL_Z']).")DR".(floor($G['d_BL_T']*100)/100)."s,NE".(floor($G['df_abs']/$G['df_sp']*100)/100)."s,";

                    }

                    # フェンス接触計算
                    if(!$G['RS_fe'])
                    {
                        $G['d_fe_a'] = pow($G['d_Xb'], 2) + pow($G['d_Zb'], 2);
                        $G['d_fe_b'] = 2 * ($G['d_Xb'] * $G['d_Xc'] + $G['d_Zb'] * $G['d_Zc']);
                        $G['d_fe_c'] = pow($G['d_Xc'], 2) + pow($G['d_Zc'], 2) - pow($G['RS_fe_l'], 2);
                        $G['d_fe_d'] = pow($G['d_fe_b'], 2) - 4 * $G['d_fe_a'] * $G['d_fe_c'];

                        # 判別式
                        if($G['d_fe_d'] >= 0)
                        {
                            # 接触秒数
                            $G['d_fe_t'] = (-$G['d_fe_b'] + sqrt($G['d_fe_d'])) / (2 * $G['d_fe_a']);
                            #$html .= "(fe:" . (floor($G['d_fe_t'] * 100)/100) . "s)";

                            # HR判定等
                            if($G['d_fe_t'] > 0 && $G['d_fe_t'] < $G['d_drop_t'])
                            {
                                # 衝突探偵
                                $G['RS_fe'] = 1;

                                # 位置計算
                                $G['RS_sec'] += $G['d_fe_t'];
                                $G['BL_X'] = $G['d_Xa'] * pow($G['d_fe_t'], 2) + $G['d_Xb'] * $G['d_fe_t'] + $G['d_Xc'];
                                $G['BL_Y'] = $G['d_Ya'] * pow($G['d_fe_t'], 2) + $G['d_Yb'] * $G['d_fe_t'] + $G['d_Yc'];
                                $G['BL_Z'] = $G['d_Za'] * pow($G['d_fe_t'], 2) + $G['d_Zb'] * $G['d_fe_t'] + $G['d_Zc'];
                                #$html .= "(".(floor($G['BL_X'] * 100)/100).",".(floor($G['BL_Z'] * 100)/100).",".(floor($G['BL_Z'] * 100)/100).")";

                                # ベクトル経時変化計算 d = a * 2t + b
                                $G['BT_X'] = $G['d_Xa'] * $G['d_fe_t'] * 2 + $G['d_Xb'];
                                $G['BT_Y'] = $G['d_Ya'] * $G['d_fe_t'] * 2 + $G['d_Yb'];
                                $G['BT_Z'] = $G['d_Za'] * $G['d_fe_t'] * 2 + $G['d_Zb'];

                                # 判定
                                if(!$G['RS_f'] && abs(rad2deg(atan2($G['BL_Z'], $G['BL_X'])) - 90) > 45)
                                {
                                    $G['RS_bt'] = 'FB'; // ファール
                                    break;
                                }
                                elseif($G['BL_Y'] > $G['bp_fe_h'])
                                {
                                    if($G['RS_bb'])
                                    {
                                        $G['RS_bt'] = 'EN2'; // エンタイトル2ベース
                                    }
                                    else
                                    {
                                        $G['RS_bt'] = 'HR'; // ホームラン
                                        $G['RS_f'] = 1;
                                        $G['BL_X'] = $G['d_Xa'] * pow($G['d_drop_t'], 2) + $G['d_Xb'] * $G['d_drop_t'] + $G['d_Xc'];
                                        $G['BL_Y'] = $G['d_Ya'] * pow($G['d_drop_t'], 2) + $G['d_Yb'] * $G['d_drop_t'] + $G['d_Yc'];
                                        $G['BL_Z'] = $G['d_Za'] * pow($G['d_drop_t'], 2) + $G['d_Zb'] * $G['d_drop_t'] + $G['d_Zc'];
                                        $G['RS_hr'] = floor(sqrt(pow($G['BL_X'], 2) + pow($G['BL_Z'], 2)) + 5);
                                    }
                                    break;
                                }
                                else
                                {
                                    $html .= "<b>フェンスに当たった!</b>";
                                    $G['RS_f'] = 1;
                                    $G['RS_fe'] = 1;
                                    $G['RS_bb']++;
                                    #$html .= "(BT:".(floor($G['BT_X'] * 100)/100).",".(floor($G['BT_Y'] * 100)/100).",".(floor($G['BT_Z'] * 100)/100).")";

                                    # クッション判定
                                    $G['BT_X'] = $G['BT_X'] * $G['bp_corz'];
                                    $G['BT_Y'] = $G['BT_Y'] * $G['bp_corz'];
                                    $G['BT_Z'] = -$G['BT_Z'] * $G['bp_corf'];
                                    #$html .= "(WBT:".(floor($G['BT_X'] * 100)/100).",".(floor($G['BT_Y'] * 100)/100).",".(floor($G['BT_Z'] * 100)/100).")";
                                    #$html .= "(WBL:".(floor($G['BL_X'] * 100)/100).",".(floor($G['BL_Y'] * 100)/100).",".(floor($G['BL_Z'] * 100)/100).")";

                                    # 継続
                                    continue;
                                }
                            }

                        }
                    }

                    // 捕球計算
                    if(count($G['d_ct']) > 0)
                    {
                        # ソート
                        asort($G['d_ct']);

                        foreach($G['d_ct'] as $i => $abs)
                        {
                            # バウンド判定
                            if($G['RS_bb'])
                            {
                                $G['RS_bt'] = 'G';
                            }
                            else
                            {
                                $G['RS_bt'] = 'F';
                            }

                            # 守備者/守備位置読み込み
                            $G['RS_df_pos'] = $i;
                            $G['df_man'] = $G['df_ar'][$G['df_d'][$i]];
                            $G['df_pos'] = explode(",", $G['bp_dpos'][$i]);

                            # 移動速度計算
                            $G['df_sp'] = 0.12 * ($G['df_man']['S_b_sp'] + $G['df_man']['S_b_df'] * 3) / 4 + 7;
                            $G['df_ws'] = 0.2 - 0.002 * $G['df_man']['S_b_ss'];

                            # 補正
                            if($i == 1){ $G['df_ws'] += 1; }
                            if($i == 2){ $G['df_ws'] += 2; }

                            # 守備秒計算
                            $G['df_sec'] = $abs / $G['df_sp'] + $G['df_ws'];

                            # 秒数計算
                            if($G['RS_stop'] || $G['RS_bb'] == $G['bb_stop']) // 静止
                            {
                                $G['RS_df_sec'] = $G['df_sec'];

                                // ファウル
                                if(!$G['RS_f'] && abs(rad2deg(atan2($G['BL_Z'], $G['BL_X'])) - 90) > 45 || ($G['BL_Z'] < -10 && sqrt(pow($G['BL_X'], 2) + pow($G['BL_Z'], 2)) > 20))
                                {
                                    $G['RS_bt'] = 'FB';
                                    break 2;
                                }
                            }
                            elseif($G['df_sec'] < ($G['RS_sec'] + $G['d_drop_t'])) // 捕球可能
                            {
                                $G['BL_X'] = $G['d_Xa'] * pow($G['d_drop_t'], 2) + $G['d_Xb'] * $G['d_drop_t'] + $G['d_Xc'];
                                $G['BL_Y'] = $G['d_Ya'] * pow($G['d_drop_t'], 2) + $G['d_Yb'] * $G['d_drop_t'] + $G['d_Yc'];
                                $G['BL_Z'] = $G['d_Za'] * pow($G['d_drop_t'], 2) + $G['d_Zb'] * $G['d_drop_t'] + $G['d_Zc'];
                                if($G['BL_Y'] < 0){ continue; }
                                $G['RS_df_sec'] = $G['RS_sec'] + $G['d_drop_t'];
                            }
                            else // 捕球不可
                            {
                                continue;
                            }
                            # 終了
                            break 2;
                        }
                    }

                    // バウンド計算
                    # 位置計算
                    $G['RS_sec'] += $G['d_drop_t'];
                    $G['BL_X'] = $G['d_Xa'] * pow($G['d_drop_t'], 2) + $G['d_Xb'] * $G['d_drop_t'] + $G['d_Xc'];
                    $G['BL_Y'] = $G['d_Ya'] * pow($G['d_drop_t'], 2) + $G['d_Yb'] * $G['d_drop_t'] + $G['d_Yc'];
                    $G['BL_Z'] = $G['d_Za'] * pow($G['d_drop_t'], 2) + $G['d_Zb'] * $G['d_drop_t'] + $G['d_Zc'];
                    #$html .= "B{$G['RS_bb']}:" . (floor($G['RS_sec']*100)/100) . "s(".(floor($G['BL_X'] * 100)/100).",".(floor($G['BL_Y'] * 100)/100).",".(floor($G['BL_Z'] * 100)/100).")<br>";

                    #  ベクトル経時変化計算 d = a * 2t + b
                    $G['BT_X'] = $G['d_Xa'] * $G['d_fe_t'] * 2 + $G['d_Xb'];
                    $G['BT_Y'] = $G['d_Ya'] * $G['d_fe_t'] * 2 + $G['d_Yb'];
                    $G['BT_Z'] = $G['d_Za'] * $G['d_fe_t'] * 2 + $G['d_Zb'];

                    # バウンド計算
                    $G['BT_X'] = $G['BT_X'] * $G['bp_corz'];
                    $G['BT_Y'] = abs($G['BT_Y'] * $G['bp_cor']);
                    $G['BT_Z'] = $G['BT_Z'] * $G['bp_corz'];

                    // 判定
                    if(!$G['RS_f'] && abs(rad2deg(atan2($G['BL_Z'], $G['BL_X'])) - 90) > 45)
                    {
                        $G['RS_bt'] = 'FB'; // ファール
                        break;
                    }
                    elseif(abs(rad2deg(atan2($G['BL_Z'], $G['BL_X'])) - 90) <= 45 && sqrt(pow($G['BL_X'], 2) + pow($G['BL_Z'], 2)) >= $G['base_l'])
                    {
                        $G['RS_f'] = 1;
                    }
                    $G['RS_bb']++;

                }
                #$html .= "{$G['RS_bb']}回{$G['RS_bt']}(" . (floor($G['RS_sec']*10)/10) . "s)?{$G['RS_df_pos']}(". (floor($G['RS_df_sec']*10)/10)."s)";
                #$html .= "(BL:".(floor($G['BL_X'] * 100)/100).",".(floor($G['BL_Y'] * 100)/100).",".(floor($G['BL_Z'] * 100)/100).")";

                // 守備計算
                if($G['RS_bt'] == 'G' || $G['RS_bt'] == 'F')
                {
                    $G['df_man'] = $G['df_ar'][$G['df_d'][$G['RS_df_pos']]];
                    $G['df_pos'] = explode(",", $G['bp_dpos'][$G['RS_df_pos']]);
                    $G['df_sp'] = $this->_disp_sp($G['df_man']['S_b_sf'], $G['df_man']['cond']) / 3.6; // m/s
                    $G['RS_sec'] += 2 - $G['df_man']['S_b_df'] / 200; // 捕球から投げるまでの速度追加
                    if($G['RS_df_pos'] >= 7){ $G['RS_sec'] += 3.5; } // 外野補正
                    if($G['RS_fe']){ $G['RS_sec'] += 2; } // フェンス当たり補正

                    // ベース位置取得
                    $G['bp_base_l'] = [];
                    $G['bp_base_ds'] = [];
                    for($i=0; $i<=3; $i++)
                    {
                        $G['bp_base_lxz'] = explode(",", $G['bp_base'][$i]);
                        $G['bp_base_l'][$i] = sqrt(pow(($G['bp_base_lxz'][0] - $G['BL_X']), 2) + pow(($G['bp_base_lxz'][1] - $G['BL_Z']), 2));
                        $G['bp_base_ds'][$i] = $G['RS_sec'] + $G['bp_base_l'][$i] / $G['df_sp'];
                        $G['bp_base_fs'][$i] = $G['bp_base_l'][$i] / $G['df_sp'] + (3 - $G['df_man']['S_b_df'] / 50);
                    }
                }

                // 守備判定
                if($G['RS_bt'] == 'G')
                {
                    // 表示
                    $PL = explode(",", $cf['pos_list'][$G['RS_df_pos']]);
                    $html .= "<span style='background-color: {$PL[3]}; color: {$PL[2]};'>{$PL[1]}</span>への当たり!";

                    // チェック設定
                    $G['df_out'] = 0;

                    // 打者走力計算
                    $G['bt_sp'] = $this->_game_bsp($G['bt']['S_b_sp']);
                    $G['bt_rc'] = 0; // 打撃時位置
                    if($G['bt']['side_b'] == 'L'){ $G['bt_c'] = 1; }else{ $G['bt_c'] = -1; }
                    $G['bt_nb1'] = $G['bp_base_ds'][1] * $G['bt_sp'] + $G['bt_rc']; // 移動距離
                    $G['bt_nb2'] = $G['bp_base_ds'][2] * ($G['bt_sp'] + 1) + $G['bt_rc'];
                    $G['bt_nb3'] = $G['bp_base_ds'][3] * ($G['bt_sp'] + 1) + $G['bt_rc'];
                    $G['bt_nb4'] = $G['bp_base_ds'][0] * $G['bt_sp'] + $G['bt_rc'];
                    #$html .= "(X:{$G['BL_X']},Z:{$G['BL_Z']})1:{$G['bt_nb1']},2:{$G['bt_nb2']},3:{$G['bt_nb3']},4:{$G['bt_nb4']}";

                    // アウト判定
                    if($G['bt_nb1'] / $G['base_l'] < 1){ $G['df_out'] = 1; }

                    // 1塁走力計算
                    if(!empty($G['base'][1]))
                    {
                        $G['rn1_sp'] = $this->_game_bsp($G['rn'][1]['S_b_sp']);
                        $G['rn1_rc'] = $G['base_l'] * 1 + $G['rn'][1]['S_b_ss'] / 20 + $G['rn_c'];
                        if($G['j_sb']){ $G['rn1_rc'] += $G['rn1_sp']; }
                        $G['rn1_nb2'] = $G['bp_base_ds'][2] * $G['rn1_sp'] + $G['rn1_rc'];
                        $G['rn1_nb3'] = $G['bp_base_ds'][3] * $G['rn1_sp'] + $G['rn1_rc'];
                        $G['rn1_nb4'] = $G['bp_base_ds'][0] * $G['rn1_sp'] + $G['rn1_rc'];
                        // アウト判定
                        if($G['rn1_nb2'] / $G['base_l'] < 2){ $G['df_out'] = 2; }
                        #$html .= "rn1:" . (floor($G['rn1_nb2'] / $G['base_l']*100)/100) . ", ";
                    }

                    // 2塁走力計算
                    if(!empty($G['base'][2]))
                    {
                        $G['rn2_sp'] = $this->_game_bsp($G['rn'][2]['S_b_sp']);
                        $G['rn2_rc'] = $G['base_l'] * 2 + $G['rn'][2]['S_b_ss'] / 20 + $G['rn_c'];
                        if($G['j_sb']){ $G['rn2_rc'] += $G['rn2_sp']; }
                        $G['rn2_nb3'] = $G['bp_base_ds'][3] * $G['rn2_sp'] + $G['rn2_rc'];
                        $G['rn2_nb4'] = $G['bp_base_ds'][0] * $G['rn2_sp'] + $G['rn2_rc'];
                        // アウト判定
                        if($G['rn2_nb3'] / $G['base_l'] < 3){ $G['df_out'] = 3; }
                        #$html .= "rn2:" . (floor($G['rn2_nb3'] / $G['base_l']*100)/100) . ", ";
                    }

                    // 3塁走力計算
                    if(!empty($G['base'][3]))
                    {
                        $G['rn3_sp'] = $this->_game_bsp($G['rn'][3]['S_b_sp']);
                        $G['rn3_rc'] = $G['base_l'] * 3 + $G['rn'][3]['S_b_ss'] / 20 + $G['rn_c'];
                        if($G['j_sb']){ $G['rn3_rc'] += $G['rn3_sp']; }
                        $G['rn3_nb4'] = $G['bp_base_ds'][0] * $G['rn3_sp'] + $G['rn3_rc'];
                        // アウト判定
                        if($G['rn3_nb4'] / $G['base_l'] < 4){ $G['df_out'] = 4; }
                        #$html .= "rn3:" . (floor($G['rn3_nb4'] / $G['base_l']*100)/100) . "";
                    }

                    # bag
                    #$html .= "<br>肩力:" . floor($G['df_sp']) ."m/s, 走力:" . floor($G['bt_sp']) . "m/s, ";
                    #$html .= "距離:" . floor($G['bp_base_l'][1]) . "m, 経過時間:" . (floor($G['RS_sec']*100)/100) . "s, 必要時間:" . (floor($G['bp_base_ds'][0]*100)/100) . "<br>";

                    if($G['df_out'])
                    {
                        //
                        $html_dp = null;
                        if($G['df_out'] == 4)
                        {
                            $html .= "本塁へ!";

                            // アウト
                            $G['base'][3] = null;
                            $G['c_o']++;
                            $html .= "<b style='color:red;'>{$G['c_o']}アウト!</b>";

                            // ランナー設定
                            $G['base'][3] = $G['base'][2];
                            $G['base'][2] = $G['base'][1];
                            $G['base'][1] = $G['bt']['id'] . ',' . $G['pc_id'];

                            // 守備設定(捕手)
                            if($G['RS_df_pos'] == 2)
                            {
                                $G['df_man'] = $G['df_ar'][$G['df_d'][1]];
                            }
                            else
                            {
                                $G['df_man'] = $G['df_ar'][$G['df_d'][2]];
                            }
                            $G['df_sp'] = $this->_disp_sp($G['df_man']['S_b_sf'], $G['df_man']['cond']) / 3.6; // m/s

                            $G['bp_base_lxz0'] = explode(",", $G['bp_base'][0]);
                            for($i=1; $i<=3; $i++)
                            {
                                $G['bp_base_lxz'] = explode(",", $G['bp_base'][$i]);
                                $G['bp_base_l'][$i] = sqrt(pow(($G['bp_base_lxz'][0] - $G['bp_base_lxz0'][0]), 2) + pow(($G['bp_base_lxz'][1] - $G['bp_base_lxz0'][1]), 2));
                                $G['bp_base_ds'][$i] = $G['bp_base_l'][$i] / $G['df_sp'] + (1 - $G['df_man']['S_b_df'] / 200);
                            }

                            // 併殺計算
                            if($G['c_o'] <= 2)
                            {
                                # 秒計算
                                $G['df_sec'] = $G['bp_base_ds'][0];
                                $G['bt_nb1'] = ($G['bp_base_ds'][1] + $G['df_sec']) * $G['bt_sp'] + $G['bt_rc'];
                                if(!empty($G['baseH'][1])){ $G['rn1_nb2'] = ($G['bp_base_ds'][2] + $G['df_sec']) * $G['rn1_sp'] + $G['rn1_rc']; }
                                if(!empty($G['baseH'][2])){ $G['rn2_nb3'] = ($G['bp_base_ds'][3] + $G['df_sec']) * $G['rn2_sp'] + $G['rn2_rc']; }

                                # 判定
                                if($G['rn2_nb3'] / $G['base_l'] < 3 && !empty($G['baseH'][2]))
                                {
                                    $html .= "さらに3塁へ!";

                                    // アウト
                                    $G['base'][3] = null;
                                    $G['c_o']++;
                                    $html .= "<b style='color:red;'>{$G['c_o']}アウト!ダブルプレー!</b>";
                                    $html_dp = 1;
                                }
                                elseif($G['rn1_nb2'] / $G['base_l'] < 2 && !empty($G['baseH'][1]))
                                {
                                    $html .= "さらに2塁へ!";

                                    // アウト
                                    $G['base'][2] = null;
                                    $G['c_o']++;
                                    $html .= "<b style='color:red;'>{$G['c_o']}アウト!ダブルプレー!</b>";
                                    $html_dp = 1;
                                }
                                elseif($G['bt_nb1'] / $G['base_l'] < 1)
                                {
                                    $html .= "さらに1塁へ!";

                                    // アウト
                                    $G['base'][1] = null;
                                    $G['c_o']++;
                                    $html .= "<b style='color:red;'>{$G['c_o']}アウト!ダブルプレー!</b>";
                                    $html_dp = 1;
                                }
                            }

                            // 併殺
                            if($html_dp)
                            {
                                $this->_game_reslut($G, $G['bt']['id'], 'DP', $G['pc_id']);
                            }
                            else
                            {
                                $this->_game_reslut($G, $G['bt']['id'], 'MH', $G['pc_id']);
                            }
                        }
                        elseif($G['df_out'] == 3)
                        {
                            $html .= "3塁へ!";

                            // アウト
                            $G['base'][2] = null;
                            $G['c_o']++;
                            $html .= "<b style='color:red;'>{$G['c_o']}アウト!</b>";

                            // ランナー設定
                            $G['base'][3] = $G['base'][2];
                            $G['base'][2] = $G['base'][1];
                            $G['base'][1] = $G['bt']['id'] . ',' . $G['pc_id'];

                            // 守備設定(サード)
                            if($G['RS_df_pos'] == 5)
                            {
                                $G['df_man'] = $G['df_ar'][$G['df_d'][6]];
                            }
                            else
                            {
                                $G['df_man'] = $G['df_ar'][$G['df_d'][5]];
                            }
                            $G['df_sp'] = $this->_disp_sp($G['df_man']['S_b_sf'], $G['df_man']['cond']) / 3.6; // m/s

                            $G['bp_base_lxz3'] = explode(",", $G['bp_base'][3]);
                            for($i=1; $i<=2; $i++)
                            {
                                $G['bp_base_lxz'] = explode(",", $G['bp_base'][$i]);
                                $G['bp_base_l'][$i] = sqrt(pow(($G['bp_base_lxz'][0] - $G['bp_base_lxz3'][0]), 2) + pow(($G['bp_base_lxz'][1] - $G['bp_base_lxz3'][1]), 2));
                                $G['bp_base_ds'][$i] = $G['bp_base_l'][$i] / $G['df_sp'] + (1 - $G['df_man']['S_b_df'] / 200);
                            }

                            // 併殺計算
                            if($G['c_o'] <= 2)
                            {
                                # 秒計算
                                $G['df_sec'] = $G['bp_base_ds'][3];
                                $G['bt_nb1'] = ($G['bp_base_ds'][1] + $G['df_sec']) * $G['bt_sp'] + $G['bt_rc'];
                                if(!empty($G['baseH'][1])){ $G['rn1_nb2'] = ($G['bp_base_ds'][2] + $G['df_sec']) * $G['rn1_sp'] + $G['rn1_rc']; }

                                # 判定
                                if($G['rn1_nb2'] / $G['base_l'] < 2 && !empty($G['baseH'][1]))
                                {
                                    $html .= "さらに2塁へ!";

                                    // アウト
                                    $G['base'][2] = null;
                                    $G['c_o']++;
                                    $html .= "<b style='color:red;'>{$G['c_o']}アウト!ダブルプレー!</b>";
                                    $html_dp = 1;
                                }
                                elseif($G['bt_nb1'] / $G['base_l'] < 1)
                                {
                                    $html .= "さらに1塁へ!";

                                    // アウト
                                    $G['base'][1] = null;
                                    $G['c_o']++;
                                    $html .= "<b style='color:red;'>{$G['c_o']}アウト!ダブルプレー!</b>";
                                    $html_dp = 1;
                                }
                            }

                            // 得点
                            if($G['c_o'] <= 2 && !empty($G['baseH'][3]))
                            {
                                $html .= "その間にランナーがホームに帰る!";
                                $G['get_pt']++;
                                $this->_game_reslut($G, $G['rn'][3]['id'], 'POINT', $G['base_cid'][3]);
                            }

                            // 併殺
                            if($html_dp)
                            {
                                $this->_game_reslut($G, $G['bt']['id'], 'DP', $G['pc_id']);
                            }
                            else
                            {
                                $this->_game_reslut($G, $G['bt']['id'], 'MH', $G['pc_id']);
                            }
                        }
                        elseif($G['df_out'] == 2)
                        {
                            $html .= "2塁へ!";

                            // アウト
                            $G['base'][1] = null;
                            $G['c_o']++;
                            $html .= "<b style='color:red;'>{$G['c_o']}アウト!</b>";

                            // ランナー設定
                            $G['base'][3] = $G['base'][2];
                            $G['base'][2] = $G['base'][1];
                            $G['base'][1] = $G['bt']['id'] . ',' . $G['pc_id'];

                            // 守備設定(ショート or セカンド)
                            if($G['RS_df_pos'] == 6)
                            {
                                $G['df_man'] = $G['df_ar'][$G['df_d'][4]];
                            }
                            else
                            {
                                $G['df_man'] = $G['df_ar'][$G['df_d'][6]];
                            }
                            $G['df_sp'] = $this->_disp_sp($G['df_man']['S_b_sf'], $G['df_man']['cond']) / 3.6; // m/s

                            $G['bp_base_lxz2'] = explode(",", $G['bp_base'][2]);
                            for($i=1; $i<=1; $i++)
                            {
                                $G['bp_base_lxz'] = explode(",", $G['bp_base'][$i]);
                                $G['bp_base_l'][$i] = sqrt(pow(($G['bp_base_lxz'][0] - $G['bp_base_lxz2'][0]), 2) + pow(($G['bp_base_lxz'][1] - $G['bp_base_lxz2'][1]), 2));
                                $G['bp_base_ds'][$i] = $G['bp_base_l'][$i] / $G['df_sp'] + (1 - $G['df_man']['S_b_df'] / 200);
                            }

                            // 併殺計算
                            if($G['c_o'] <= 2)
                            {
                                # 秒計算
                                $G['df_sec'] = $G['bp_base_ds'][3];
                                $G['bt_nb1'] = ($G['bp_base_ds'][1] + $G['df_sec']) * $G['bt_sp'] + $G['bt_rc'];

                                # 判定
                                if($G['bt_nb1'] / $G['base_l'] < 1)
                                {
                                    $html .= "さらに1塁へ!";

                                    // アウト
                                    $G['base'][1] = null;
                                    $G['c_o']++;
                                    $html .= "<b style='color:red;'>{$G['c_o']}アウト!ダブルプレー!</b>";
                                    $html_dp = 1;
                                }
                            }

                            // 得点
                            if($G['c_o'] <= 2 && !empty($G['baseH'][3]))
                            {
                                $html .= "その間にランナーがホームに帰る!";
                                $G['get_pt']++;
                                $this->_game_reslut($G, $G['rn'][3]['id'], 'POINT', $G['base_cid'][3]);
                            }

                            // 併殺
                            if($html_dp)
                            {
                                $this->_game_reslut($G, $G['bt']['id'], 'DP', $G['pc_id']);
                            }
                            else
                            {
                                $this->_game_reslut($G, $G['bt']['id'], 'MH', $G['pc_id']);
                            }
                        }
                        else
                        {
                            $html .= "1塁へ!";

                            // アウト
                            $G['c_o']++;
                            $html .= "<b style='color:red;'>{$G['c_o']}アウト!</b>";

                            // ランナー設定
                            $G['base'][3] = $G['base'][2];
                            $G['base'][2] = $G['base'][1];
                            $G['base'][1] = null;

                            // 得点
                            if($G['c_o'] <= 2 && !empty($G['baseH'][3]))
                            {
                                $html .= "その間にランナーがホームに帰る!";
                                $G['get_pt']++;
                                $this->_game_reslut($G, $G['rn'][3]['id'], 'POINT', $G['base_cid'][3]);
                            }
                            $this->_game_reslut($G, $G['bt']['id'], 'MH', $G['pc_id']);
                        }
                    }
                    else // ヒット以上
                    {
                        // 3塁ランナー
                        if(!empty($G['baseH'][3]))
                        {
                            $G['base'][3] = null;
                            $G['get_pt']++;
                            $this->_game_reslut($G, $G['rn'][3]['id'], 'POINT', $G['base_cid'][3]);
                        }

                        // 2塁ランナー
                        if(!empty($G['baseH'][2]))
                        {
                            if($G['rn2_nb4'] / $G['base_l'] >= 4)
                            {
                                $G['base'][2] = null;
                                $G['get_pt']++;
                                $this->_game_reslut($G, $G['rn'][2]['id'], 'POINT', $G['base_cid'][2]);
                            }
                            else
                            {
                                $G['base'][3] = $G['base'][2];
                                $G['base'][2] = null;
                            }
                        }

                        // 1塁ランナー
                        if(!empty($G['baseH'][1]))
                        {
                            if(empty($G['base'][3]) && $G['rn1_nb4'] / $G['base_l'] >= 4)
                            {
                                $G['base'][1] = null;
                                $G['get_pt']++;
                                $this->_game_reslut($G, $G['rn'][1]['id'], 'POINT', $G['base_cid'][1]);
                            }
                            elseif(empty($G['base'][3]) && $G['rn1_nb3'] / $G['base_l'] >= 3)
                            {
                                $G['base'][3] = $G['base'][1];
                                $G['base'][1] = null;
                            }
                            else
                            {
                                $G['base'][2] = $G['base'][1];
                                $G['base'][1] = null;
                            }
                        }

                        // 打者
                        if(empty($G['base'][3]) && empty($G['base'][2]) && $G['bt_nb4'] /  $G['base_l'] >= 4)
                        {
                            $html .= "<b style='color:pink;'>ランニングホームラン!</b>";
                            $G['get_pt']++;
                            $this->_game_reslut($G, $G['bt']['id'], 'HR', $G['pc_id']);
                        }
                        elseif(empty($G['base'][3]) && empty($G['base'][2]) && $G['bt_nb3'] /  $G['base_l'] >= 3)
                        {
                            $html .= "<b style='color:pink;'>スリーベース!</b>";
                            $G['base'][3] = $G['bt']['id'] . ',' . $G['pc_id'];
                            $this->_game_reslut($G, $G['bt']['id'], '3B', $G['pc_id']);
                        }
                        elseif(empty($G['base'][2]) && $G['bt_nb2'] /  $G['base_l'] >= 2)
                        {
                            $html .= "<b style='color:pink;'>ツーベース!</b>";
                            $G['base'][2] = $G['bt']['id'] . ',' . $G['pc_id'];
                            $this->_game_reslut($G, $G['bt']['id'], '2B', $G['pc_id']);
                        }
                        else
                        {
                            $html .= "<b style='color:pink;'>ヒット!</b>";
                            $G['base'][1] = $G['bt']['id'] . ',' . $G['pc_id'];
                            $this->_game_reslut($G, $G['bt']['id'], '1B', $G['pc_id']);
                        }

                    }

                    // 計算
                    $G['j_bc'] = 1;
                }
                elseif($G['RS_bt'] == 'F')
                {
                    // 表示
                    $PL = explode(",", $cf['pos_list'][$G['RS_df_pos']]);
                    $html .= "<span style='background-color: {$PL[3]}; color: {$PL[2]};'>{$PL[1]}</span>";

                    // フライorライナー
                    $bt_xz = sqrt(pow($G['BT_X'], 2) + pow($G['BT_Z'], 2));
                    $bt_rad = rad2deg(atan2($G['BT_Y'], $bt_xz));
                    if($bt_rad <= 15)
                    {
                        $html .= "ライナー!";
                    }
                    else
                    {
                        $html .= "へのフライ!";
                    }

                    // 計算
                    $G['c_o']++;
                    $html .= "<b style='color:red;'>{$G['c_o']}アウト!</b>";

                    // ランナー進塁
                    $html_sf = null;
                    if($G['c_o'] <= 2)
                    {
                        // 3塁
                        if(!empty($G['base'][3]))
                        {
                            $G['rn3_sp'] = $this->_game_bsp($G['rn'][3]['S_b_sp']);
                            $G['rn3_rc'] = $G['base_l'] * 3 + $G['rn'][3]['S_b_ss'] / 40;
                            $G['rn3_nb4'] = $G['bp_base_ds'][0] * $G['rn3_sp'] + $G['rn3_rc'];

                            // 犠牲フライ
                            if($G['rn3_nb4'] / $G['base_l'] >= 4)
                            {
                                $G['base'][3] = null;
                                $G['get_pt']++;
                                $this->_game_reslut($G, $G['rn'][3]['id'], 'POINT', $G['base_cid'][3]);

                                $html_sf = 2;
                            }
                        }

                        // 2塁
                        if(!empty($G['base'][2]))
                        {
                            $G['rn2_sp'] = $this->_game_bsp($G['rn'][2]['S_b_sp']);
                            $G['rn2_rc'] = $G['base_l'] * 2 + $G['rn'][2]['S_b_ss'] / 40;
                            $G['rn2_nb3'] = $G['bp_base_ds'][3] * $G['rn2_sp'] + $G['rn2_rc'];

                            // 犠牲フライ
                            if(empty($G['base'][3]) && $G['rn2_nb3'] / $G['base_l'] >= 3)
                            {
                                $G['base'][3] = $G['base'][2];
                                $G['base'][2] = null;
                                if(!$html_sf){ $html_sf = 1; }
                            }
                        }

                        // 1塁
                        if(!empty($G['base'][1]))
                        {
                            $G['rn1_sp'] = $this->_game_bsp($G['rn'][1]['S_b_sp']);
                            $G['rn1_rc'] = $G['base_l'] * 1 + $G['rn'][1]['S_b_ss'] / 40;
                            $G['rn1_nb2'] = $G['bp_base_ds'][2] * $G['rn1_sp'] + $G['rn1_rc'];

                            // 犠牲フライ
                            if(empty($G['base'][2]) && $G['rn1_nb2'] / $G['base_l'] >= 2)
                            {
                                $G['base'][2] = $G['base'][1];
                                $G['base'][1] = null;
                                if(!$html_sf){ $html_sf = 1; }
                            }
                        }

                        // 表示
                        if($html_sf)
                        {
                            $html .= "その間にランナーが進む!";
                        }
                    }

                    // 計算
                    $G['j_bc'] = 1;

                    // 犠飛
                    if($html_sf == 2)
                    {
                        $this->_game_reslut($G, $G['bt']['id'], 'BF', $G['pc_id']);
                    }
                    else
                    {
                        $this->_game_reslut($G, $G['bt']['id'], 'MH', $G['pc_id']);
                    }
                }
                elseif($G['RS_bt'] == 'FB')
                {
                    $html .= "ファールボール!";
                    if($G['c_s'] <= 1)
                    {
                        $G['c_s']++;
                    }
                }
                elseif($G['RS_bt'] == 'HR')
                {
                    $html .= "大きい!いったか!";
                    if(abs(rad2deg(atan2($G['BL_Z'], $G['BL_X'])) - 90) > 22.5)
                    {
                        $html .= "ライト";
                        $G['RS_df_pos'] = 9;
                    }
                    elseif(abs(rad2deg(atan2($G['BL_Z'], $G['BL_X'])) - 90) < -22.5)
                    {
                        $html .= "レフト";
                        $G['RS_df_pos'] = 7;
                    }
                    else
                    {
                        $html .= "センター";
                        $G['RS_df_pos'] = 8;
                    }
                    $html .= "への<b style='color:pink;'>ホームラン!({$G['RS_hr']}m)</b>";

                    // 塁
                    if(!empty($G['baseH'][3]))
                    {
                        $G['base'][3] = null;
                        $G['get_pt']++;
                        $this->_game_reslut($G, $G['rn'][3]['id'], 'POINT', $G['base_cid'][3]);
                    }
                    if(!empty($G['baseH'][2]))
                    {
                        $G['base'][2] = null;
                        $G['get_pt']++;
                        $this->_game_reslut($G, $G['rn'][2]['id'], 'POINT', $G['base_cid'][2]);
                    }
                    if(!empty($G['baseH'][1]))
                    {
                        $G['base'][1] = null;
                        $G['get_pt']++;
                        $this->_game_reslut($G, $G['rn'][1]['id'], 'POINT', $G['base_cid'][1]);
                    }

                    // 計算
                    $G['get_pt']++;
                    $G['j_bc'] = 1;
                    $this->_game_reslut($G, $G['bt']['id'], 'HR', $G['pc_id']);
                }
                elseif($G['RS_bt'] == 'EN2')
                {
                    $html .= "いい当たりだー!あっとバウンドしてそのままフェンスを超えた!<b style='color:green;'>エンタイトルツーベース!</b>";

                    // 結果
                    if(abs(rad2deg(atan2($G['BL_Z'], $G['BL_X'])) - 90) > 22.5)
                    {
                        $G['RS_df_pos'] = 9;
                    }
                    elseif(abs(rad2deg(atan2($G['BL_Z'], $G['BL_X'])) - 90) < -22.5)
                    {
                        $G['RS_df_pos'] = 7;
                    }
                    else
                    {
                        $G['RS_df_pos'] = 8;
                    }

                    // 塁
                    if(!empty($G['baseH'][3]))
                    {
                        $G['base'][3] = null;
                        $G['get_pt']++;
                        $this->_game_reslut($G, $G['rn'][3]['id'], 'POINT', $G['base_cid'][3]);
                    }
                    if(!empty($G['baseH'][2]))
                    {
                        $G['base'][2] = null;
                        $G['get_pt']++;
                        $this->_game_reslut($G, $G['rn'][2]['id'], 'POINT', $G['base_cid'][2]);
                    }
                    if(!empty($G['baseH'][1]))
                    {
                        $G['base'][3] = $G['base'][1];
                        $G['base'][1] = null;
                    }
                    $G['base'][2] = $G['bt']['id'] . ',' . $G['pc_id'];

                    // 計算
                    $G['j_bc'] = 1;
                    $this->_game_reslut($G, $G['bt']['id'], '2B', $G['pc_id']);
                }
                else
                {
                    $html .= "打撃コードエラー";
                }
            }
            else // エラー
            {
                $html .= "error";
            }

            //------------------------------------------------------------//
            // 変動
            //------------------------------------------------------------//
            # 三振
            if($G['c_s'] >= 3)
            {
                $G['c_o']++;
                $html .= "<b style='color:green;'>三振!</b><b style='color:red;'>{$G['c_o']}アウト!</b>";
                $G['j_bc'] = 1;
                $this->_game_reslut($G, $G['bt']['id'], 'SO', $G['pc_id']);
            }
            #四球
            if($G['c_b'] >= 4)
            {
                $html .= "<b style='color:blue;'>フォアボール!</b>";
                $this->_game_bb($G, $html);
                $G['j_bc'] = 1;
                $this->_game_reslut($G, $G['bt']['id'], 'BB', $G['pc_id']);
            }

            //------------------------------------------------------------//
            // 盗塁結果
            //------------------------------------------------------------//
            if($G['j_sb'] && !$G['j_bt'] && $G['c_o'] <= 2 && $G['c_b'] <= 3 && ((!empty($G['base'][1]) && empty($G['base'][2])) || (!empty($G['base'][2]) && empty($G['base'][3]))))
            {
                // 結果
                # 走者
                $G['sb_rn_r'] = (mt_rand(0, 1000) / 100 + 95) / 100;
                $G['sb_rn_f'] = $G['sb_rn_sec'] / $G['sb_rn_r'];

                # 守備
                $G['sb_df_r'] = (mt_rand(0, 1000) / 100 + 95) / 100;
                $G['sb_df_f'] = $G['sb_df_sec_s'] / $G['sb_df_r'] + $G['sb_df_sec'];
                if($G['j_btsw']){ $G['sb_df_f'] += 0.1; } // スイングで増加
                if(!$G['j_st']){ $G['sb_df_f'] -= 0.1; } // ボールで減少

                # 走塁判定
                if($G['sb_rn_f'] <= $G['sb_df_f']) // セーフ
                {
                    if((!empty($G['base'][1]) && empty($G['base'][2])))
                    {
                        $html .= "2塁<strong style='color: blue;'>セーフ!</strong>";
                        $G['base'][2] = $G['base'][1];
                        $G['base'][1] = null;
                        $this->_game_reslut($G, $G['rn'][1]['id'], 'SB', $G['pc_id']);
                    }
                    elseif((!empty($G['base'][2]) && empty($G['base'][3])))
                    {
                        $html .= "3塁<strong style='color: blue;'>セーフ!</strong>";
                        $G['base'][3] = $G['base'][2];
                        $G['base'][2] = null;
                        $this->_game_reslut($G, $G['rn'][2]['id'], 'SB', $G['pc_id']);
                        // 便乗
                        if(!empty($G['base'][1]))
                        {
                            $html .= "2塁<strong style='color: blue;'>セーフ!</strong>";
                            $G['base'][2] = $G['base'][1];
                            $G['base'][1] = null;
                            $this->_game_reslut($G, $G['rn'][1]['id'], 'SB', $G['pc_id']);
                        }
                    }
                }
                else // アウト
                {
                    if((!empty($G['base'][1]) && empty($G['base'][2])))
                    {
                        $html .= "2塁<strong style='color: red;'>アウト!</strong>";
                        $G['c_o']++;
                        $G['base'][1] = null;
                        $this->_game_reslut($G, $G['rn'][1]['id'], 'SBO', $G['pc_id']);
                    }
                    elseif((!empty($G['base'][2]) && empty($G['base'][3])))
                    {
                        $html .= "3塁<strong style='color: red;'>アウト!</strong>";
                        $G['c_o']++;
                        $G['base'][2] = null;
                        $this->_game_reslut($G, $G['rn'][2]['id'], 'SBO', $G['pc_id']);
                        // 便乗
                        if(!empty($G['base'][1]))
                        {
                            $html .= "2塁は<strong style='color: blue;'>セーフ!</strong>";
                            $G['base'][2] = $G['base'][1];
                            $G['base'][1] = null;
                        }
                    }
                }

                // 表示
                $html_run = null;
                for($i=1; $i<=3; $i++)
                {
                    if(!empty($G['base'][$i]))
                    {
                        if($html_run){ $html_run .= "・";}
                        $html_run .= $i;
                    }
                }

                if($html_run)
                {
                    if(!empty($G['base'][1]) && !empty($G['base'][2]) && !empty($G['base'][3]))
                    {
                        $html_run = "満塁";
                    }
                    else
                    {
                        $html_run .= "塁";
                    }
                }
                else
                {
                    $html_run = "なし";
                }

                $html .= "<br>\nランナー<strong>{$html_run}</strong>となりました!";
            }

            //------------------------------------------------------------//
            // 得点表示
            //------------------------------------------------------------//
            if($G['get_pt'] > 0 && $G['c_o'] <= 2)
            {
                # 計算
                if($G['side'] == 'o')
                {
                    $G['pt_o'] += $G['get_pt'];
                    $G['pt_o_in'][$G['in']] += $G['get_pt'];
                }
                else
                {
                    $G['pt_u'] += $G['get_pt'];
                    $G['pt_u_in'][$G['in']] += $G['get_pt'];
                }

                # 勝ち側計算
                if($G['pt_o'] > $G['pt_u'])
                {
                    $G['win_side2'] = 'o';
                }
                elseif($G['pt_o'] < $G['pt_u'])
                {
                    $G['win_side2'] = 'u';
                }
                else
                {
                    $G['win_side2'] = null;
                }

                # 勝ち投手計算
                if($G['win_side'] != $G['win_side2'])
                {
                    $G['win_side'] = $G['win_side2'];
                    if($G['pt_o'] > $G['pt_u'])
                    {
                        if($G['in'] >= 6)
                        {
                            $G['win_id'] = $OD_DF[1];
                        }
                        $G['lose_id'] = $UD_DF[1];
                    }
                    elseif($G['pt_o'] < $G['pt_u'])
                    {
                        if($G['in'] >= 6)
                        {
                            $G['win_id'] = $UD_DF[1];
                        }
                        $G['lose_id'] = $OD_DF[1];
                    }
                    else
                    {
                        $G['win_id'] = null;
                        $G['lose_id'] = null;
                    }
                }

                # 表示
                $html .= "<br>\n<b style='color:red;'>{$G['get_pt']}点追加!";
                if(($G['pt_oH'] > $G['pt_uH'] && $G['pt_o'] < $G['pt_u']) || ($G['pt_oH'] < $G['pt_uH'] && $G['pt_o'] > $G['pt_u']))
                {
                    $html .= "逆転!";
                    $G['pt_oH'] = $G['pt_o'];$G['pt_uH'] = $G['pt_u'];
                }
                elseif($G['pt_oH'] != $G['pt_uH'] && $G['pt_o'] == $G['pt_u'])
                {
                    $html .= "同点!";
                }
                elseif($G['pt_oH'] == 0 && $G['pt_uH'] == 0 && $G['pt_o'] != $G['pt_u'])
                {
                    $html .= "先制点!";
                    $G['pt_oH'] = $G['pt_o'];$G['pt_uH'] = $G['pt_u'];
                }
                elseif($G['pt_oH'] != 0 && $G['pt_uH'] != 0 && $G['pt_oH'] == $G['pt_uH'] && $G['pt_o'] != $G['pt_u'])
                {
                    $html .= "均衡が破れました!";
                    $G['pt_oH'] = $G['pt_o'];$G['pt_uH'] = $G['pt_u'];
                }
                $html .= "({$G['pt_o']}-{$G['pt_u']})</b>";
            }

            //------------------------------------------------------------//
            // 打者交代
            //------------------------------------------------------------//
            if($G['j_bc'])
            {
                $G['c_s'] = $G['c_b'] = 0;
                $html .= "<br>\n";
                $G['bt_n']++;
                if($G['bt_n'] >= 9)
                {
                    $G['bt_n'] = 0;
                }

                // 打者再読み込み
                $G['bt'] = $G['at_ar'][$G['at_b'][$G['bt_n']]];
                $G['j_bc'] = 0;
            }

            $html .= "<br>\n";

            //------------------------------------------------------------//
            // 勝ち投手計算
            //------------------------------------------------------------//
            if($G['in'] == 5 && $G['side'] == 'u' && $G['c_o'] >= 3)
            {
                if($G['pt_o'] > $G['pt_u'])
                {
                    $G['win_side'] = 'o';
                    $G['win_id'] = $OD_D[1];
                    $G['lose_id'] = $UD_D[1];
                }
                elseif($G['pt_o'] < $G['pt_u'])
                {
                    $G['win_side'] = 'u';
                    $G['win_id'] = $UD_D[1];
                    $G['lose_id'] = $OD_D[1];
                }
                else
                {
                    $G['win_side'] = null;
                }
            }

            //------------------------------------------------------------//
            // チェンジ
            //------------------------------------------------------------//
            if($G['c_o'] >= 3)
            {
                $G['c_s'] = $G['c_b'] = $G['c_o'] = 0;
                $G['in_c'] = 0;
                $G['base'] = [];

                $html .= "</div>"; //色表示用

                # 保存
                if($G['side'] == 'o')
                {
                    # 守備=>U
                    $UD = $G['df'];
                    $UCs = $G['df_ar'];
                    $UD_B = $G['df_b']; $UD_BC = $G['df_bc'];
                    $UD_D = $G['df_d'];
                    # 攻撃=>O
                    $OD = $G['at'];
                    $OCs = $G['at_ar'];
                    $OD_B = $G['at_b']; $OD_BC = $G['at_bc'];
                    $OD_D = $G['at_d'];
                }
                else
                {
                    # 守備=>O
                    $OD = $G['df'];
                    $OCs = $G['df_ar'];
                    $OD_B = $G['df_b']; $OD_BC = $G['df_bc'];
                    $OD_D = $G['df_d'];
                    # 攻撃=>U
                    $UD = $G['at'];
                    $UCs = $G['at_ar'];
                    $UD_B = $G['at_b']; $UD_BC = $G['at_bc'];
                    $UD_D = $G['at_d'];
                }

                // 回変更
                if($G['side'] == 'o')
                {
                    $G['bt_o'] = $G['bt_n'];
                    if($G['in'] >= 9 && $G['pt_o'] < $G['pt_u'])
                    {
                        $html .= "<div class=desc>";
                        $html .= "<table class='score_board' width=100% style='border:none;'>\n";
                        $html .= "<tr>";
                        $html .= "<td rowspan=2><img src='" . $this->_disp_flag($OD['team_flag']) . "' style='height:100px; width:100px; vertical-align:middle;'>&nbsp;<img src='" . $this->_disp_icon($OD['mn_img']) . "' style='height:30px; width:30px; vertical-align:middle;'></td>";
                        $html .= "<td colspan=3><font style='font-size:40px;'>{$G['pt_o']}&nbsp;-&nbsp;{$G['pt_u']}</font></td>";
                        $html .= "<td rowspan=2><img src='" . $this->_disp_icon($UD['mn_img']) . "' style='height:30px; width:30px; vertical-align:middle;'>&nbsp;<img src='" . $this->_disp_flag($UD['team_flag']) . "' style='height:100px; width:100px; vertical-align:middle;'></td></tr>";
                        $html .= "<tr><td width=100>&nbsp;</td><td width=150>ゲームセット!</td><td width=100>&nbsp;</td></tr>";
                        $html .= "</table></div>\n";
                        break;
                    }
                    $G['side'] = 'u';
                    $G['bt_n'] = $G['bt_u'];
                    # 表示
                    $html .= "<div class=desc name=\"{$G['in']}u\">";
                    if($G['in'] >= 10)
                    {
                        $html .= "<b style='color:red;'>延長</b>";
                    }

                    $html .= "<table class='score_board' width=100% style='border:none;'>\n";
                    $html .= "<tr>";
                    $html .= "<td rowspan=2><img src='" . $this->_disp_flag($OD['team_flag']) . "' style='height:100px; width:100px; vertical-align:middle;'>&nbsp;<img src='" . $this->_disp_icon($OD['mn_img']) . "' style='height:30px; width:30px; vertical-align:middle;'></td>";
                    $html .= "<td colspan=3><font style='font-size:40px;'>{$G['pt_o']}&nbsp;-&nbsp;{$G['pt_u']}</font></td>";
                    $html .= "<td rowspan=2><img src='" . $this->_disp_icon($UD['mn_img']) . "' style='height:30px; width:30px; vertical-align:middle;'>&nbsp;<img src='" . $this->_disp_flag($UD['team_flag']) . "' style='height:100px; width:100px; vertical-align:middle;'></td></tr>";
                    $html .= "<tr><td width=100>&nbsp;</td><td width=150>{$G['in']}回ウラ</td><td width=100>&gt;&gt;</td></tr>";
                    $html .= "</table></div>\n";
                }
                elseif($G['side'] == 'u')
                {
                    $G['bt_u'] = $G['bt_n'];
                    if(($G['in'] >= 9 && $G['pt_o'] > $G['pt_u']) || ($G['in'] >= 15 && $game_type == 'pract'))
                    {
                        if((!$G['win_side'] || !$G['win_id']) && $G['pt_o'] > $G['pt_u'])
                        {
                            $G['win_side'] = 'o';
                            $G['win_id'] = $OD_D[1];
                            $G['lose_id'] = $UD_D[1];
                        }
                        $html .= "<div class=desc>";
                        $html .= "<table class='score_board' width=100% style='border:none;'>\n";
                        $html .= "<tr>";
                        $html .= "<td rowspan=2><img src='" . $this->_disp_flag($OD['team_flag']) . "' style='height:100px; width:100px; vertical-align:middle;'>&nbsp;<img src='" . $this->_disp_icon($OD['mn_img']) . "' style='height:30px; width:30px; vertical-align:middle;'></td>";
                        $html .= "<td colspan=3><font style='font-size:40px;'>{$G['pt_o']}&nbsp;-&nbsp;{$G['pt_u']}</font></td>";
                        $html .= "<td rowspan=2><img src='" . $this->_disp_icon($UD['mn_img']) . "' style='height:30px; width:30px; vertical-align:middle;'>&nbsp;<img src='" . $this->_disp_flag($UD['team_flag']) . "' style='height:100px; width:100px; vertical-align:middle;'></td></tr>";
                        $html .= "<tr><td width=100>&nbsp;</td><td width=150>ゲームセット!</td><td width=100>&nbsp;</td></tr>";
                        $html .= "</table></div>\n";
                        break;
                    }
                    $G['in']++;
                    $G['side'] = 'o';
                    $G['bt_n'] = $G['bt_o'];
                    # 表示
                    $html .= "<div class=desc name=\"{$G['in']}o\">";
                    if($G['in'] >= 10)
                    {
                        $html .= "<b style='color:red;'>延長</b>";
                    }
                    $html .= "<table class='score_board' width=100% style='border:none;'>\n";
                    $html .= "<tr>";
                    $html .= "<td rowspan=2><img src='" . $this->_disp_flag($OD['team_flag']) . "' style='height:100px; width:100px; vertical-align:middle;'>&nbsp;<img src='" . $this->_disp_icon($OD['mn_img']) . "' style='height:30px; width:30px; vertical-align:middle;'></td>";
                    $html .= "<td colspan=3><font style='font-size:40px;'>{$G['pt_o']}&nbsp;-&nbsp;{$G['pt_u']}</font></td>";
                    $html .= "<td rowspan=2><img src='" . $this->_disp_icon($UD['mn_img']) . "' style='height:30px; width:30px; vertical-align:middle;'>&nbsp;<img src='" . $this->_disp_flag($UD['team_flag']) . "' style='height:100px; width:100px; vertical-align:middle;'></td></tr>";
                    $html .= "<tr><td width=100>&lt;&lt;</td><td width=150>{$G['in']}回オモテ</td><td width=100>&nbsp;</td></tr>";
                    $html .= "</table></div>\n";
                }
            }

            //------------------------------------------------------------//
            // サヨナラ判定
            //------------------------------------------------------------//
            if($G['side'] == 'u' && $G['in'] >= 9 && $G['pt_o'] < $G['pt_u'])
            {
                if(!$G['win_side'] || !$G['win_id'])
                {
                    $G['win_side'] = 'u';
                    $G['win_id'] = $UD_D[1];
                    $G['lose_id'] = $OD_D[1];
                }
                $html .= "</div>";
                $html .= "<div class=desc>";
                $html .= "<table class='score_board' width=100% style='border:none;'>\n";
                $html .= "<tr>";
                $html .= "<td rowspan=2><img src='" . $this->_disp_flag($OD['team_flag']) . "' style='height:60px; width:60px; vertical-align:middle;'>&nbsp;<img src='" . $this->_disp_icon($OD['mn_img']) . "' style='height:30px; width:30px; vertical-align:middle;'></td>";
                $html .= "<td colspan=3><font style='font-size:40px;'>{$G['pt_o']}&nbsp;-&nbsp;{$G['pt_u']}</font></td>";
                $html .= "<td rowspan=2><img src='" . $this->_disp_icon($UD['mn_img']) . "' style='height:30px; width:30px; vertical-align:middle;'>&nbsp;<img src='" . $this->_disp_flag($UD['team_flag']) . "' style='height:60px; width:60px; vertical-align:middle;'></td></tr>";
                $html .= "<tr><td width=100>&nbsp;</td><td width=150 style='color:red;'>サヨナラだ~!</td><td width=100>&nbsp;</td></tr>";
                $html .= "</table></div>\n";
                break;
            }
            // Last
            $G['i']++;
        }

試合の設計概要

下記は試合の設計概要です。

ポイントとしては以下の通り。

  1. 投球・打撃はランダム要素に左右される。
  2. 走塁・守備はランダム要素がない。

詳細なゲーム流れ(1投球ごと)は以下の通りです。

// 投手
HP補正
投球始点設定
球種選択
投球座標選択
初速設定
変化量取得・速度設定
キレ設定
変化方向・量設定
// 打者
打席位置設定
待ち球選択
失投計算
打者スイング設定(打つかどうか)
// 仮想投球(打者脳内)
投球開始時設定
変化時設定(キレ量が多いほど打者の直前で曲がる)
打撃時判定
・内外打ち分け計算
・振り遅れ計算(今はない)
・ミートズレ計算
・コース補正(難しいコースほど打ちにくい)
・変化量補正(変化量が多いほど打ちにくいvsミート)
・キレ補正(キレ量が多いほど打ちにくいvsミート)
・ストレート補正(球速が早いほど打ちにくい)
// 盗塁判定
// 実投球開始
投球開始時設定
if(カット時設定)
 カットはミートが影響してくる
elif(打撃時設定)
 投球開始→球・変化ポイントまで移動→球・ミートポイントまで移動→衝突判定→打球方向・力判定
else(見送り設定)
各結果判定
if(打撃時) # それ以外は省略する
打球移動判定&捕球判定 # ランダム要素なし、打球速度は物理計算されて失速していくが守備者の移動速度は一定。
送球判定 # 本塁→三塁→二塁→一塁とアウトにできるところがないか判定して送球する。送球しない選択肢はない。送球速度は一定。
走塁判定 # 走者の速度は一定。トリプルプレーまであります。守備側は最善の判断を行う。
// 以降後処理

個人的な見解ですが、堅実なチーム作りをするなら、走塁・守備重視(総合力)で勝負するべきです。
ランダム要素がないので、盗塁は走力が高い選手が出塁さえしてしまえば100%可能。守備も試合開始時のやる気・体力には影響されるものの、一定です。試合途中で疲労感が爆発することはありません。

爆発力があるチーム作りをするなら、打撃重視ですね。格上でも勝てる要素が盛りだくさんです。ただし、ランダム要素によって格下にも呆気なく負けます。

各選手の育成方法等詳細については別の機会に記載したいと思います。

-Web制作, Meisyo

執筆者:


  1. […] 名将と呼ばれた者達、めちゃくちゃソースコードが長い(この記事) […]

comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

関連記事

とても簡単なPythonインストール in Windows10

拍子抜けするほど簡単なPythonインストール。 パソコン初心者のあなたにも簡単にできます! 目次 Pythonとは? Pythonの入手 Pythonのインストール Pythonの動作確認 インスト …

no image

JavaScriptで特定地域にターゲット広告を表示

ある特定の都道府県だけ表示したい広告を作ったので、そのコードを公開します! 1.Google AJAX APIを読み込み <script type="text/javascript&q …

[Meisyo+] リリース前準備完了

名将と呼ばれた者達+の機能があらかた実装できました。 現在はゲームバランス調整のために、試合や練習などの状況を確認している最中です。 β版リリース日を8/28目安にしています。 よろしくお願いいたしま …

no image

Cで簡単プログラミング「二次関数の解」

C言語で簡単なプログラミングをしましょう! 今回は「二次関数の解」です。 ↓Cはコンパイル(機械語に翻訳)が必要なので、以下でコンパイラの「MinGW」をインストールしてください。 C言語およびC++ …

no image

[PHP]まとめ読みをPSRで改良する(2)

PHPのコーディング規則、PSRを学ぶをまとめました。 しかし、実際に作るとなるとまだまだです! やらなきゃ実際の所なんてわからんです。難しく見えてもね! 現行ページ(テストサーバー上) この記事の( …