メインコンテンツへスキップ
見出し画像

展開予想コード

    使い方解説動画です

    ①コード変換HTMLはコチラ


    ②展開予想用のHTMLコード
    ③はJRA公式サイトの出馬表(印刷用ページをコピペ)
    ※地方競馬は競馬Goをお使いください。

    YouTubeのコメント欄に感想くれた方には、
    結果分析コードプレゼントしますね※先着20名様

    <!DOCTYPE html>
    <html lang="ja">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>競馬展開シミュレーター(完全両対応版 V10)</title>
    <style>
      body { font-family: -apple-system, BlinkMacSystemFont, sans-serif; padding: 10px; background: #f4f6f9 ; margin: 0; }
      
      /* モード選択のデザイン */
      .mode-selector {
        display: flex; gap: 10px; margin-bottom: 10px;
        background: #fff ; padding: 10px; border-radius: 8px; border: 1px solid #ddd ;
      }
      .mode-label {
        flex: 1; text-align: center; padding: 10px; border-radius: 6px;
        background: #f0f0f0 ; color: #555 ; font-weight: bold; font-size: 14px;
        border: 2px solid transparent; cursor: pointer; transition: all 0.2s;
      }
      .mode-selector input[type="radio"] { display: none; }
      .mode-selector input[type="radio"]:checked + .mode-label {
        background: #e8f0fe ; color: #1a73e8 ; border-color: #1a73e8 ;
      }
    
      /* ガイドテキスト(誘導文) */
      .guide-text {
        font-size: 12px; color: #555 ; background: #fff ;
        padding: 10px 12px; border-radius: 6px; border-left: 4px solid #e60012 ;
        margin-bottom: 10px; line-height: 1.5; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
      }
      .guide-text strong { color: #333 ; }
      .guide-nar { border-left-color: #1a73e8 ; display: none; } /* 地方選択時は青色に */
    
      textarea { width: 100%; height: 80px; border: 2px solid #ccc ; border-radius: 5px; padding: 10px; box-sizing: border-box; font-size: 12px; margin-bottom: 10px;}
      
      .button-group { display: flex; gap: 10px; margin-bottom: 20px; }
      .btn-run { flex: 2; padding: 12px; background: #e60012 ; color: #fff ; border: none; border-radius: 8px; font-size: 16px; font-weight: bold; box-shadow: 0 4px 6px rgba(0,0,0,0.1); cursor: pointer; }
      .btn-run:active { transform: translateY(2px); box-shadow: none; }
      .btn-clear { flex: 1; padding: 12px; background: #6c757d ; color: #fff ; border: none; border-radius: 8px; font-size: 15px; font-weight: bold; box-shadow: 0 4px 6px rgba(0,0,0,0.1); cursor: pointer; }
      .btn-clear:active { transform: translateY(2px); box-shadow: none; background: #5a6268 ; }
      
      #race -info-header {
        display: none; justify-content: space-between; align-items: center; 
        padding: 10px 15px; border-radius: 8px 8px 0 0; font-weight: bold; color: #333 ;
        border: 1px solid #ccc ; border-bottom: none; background: #fff ;
      }
      .race-title { font-size: 14px; }
      .pace-badge { 
        background: #333 ; color: #fff ; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: bold;
        box-shadow: 0 2px 4px rgba(0,0,0,0.2); transition: all 0.3s ease;
      }
      .pace-high { background: #d32f2f ; }
      .pace-slow { background: #1976d2 ; }
    
      .board-container { border: 1px solid #ccc ; border-radius: 0 0 8px 8px; overflow: hidden; background: #fff ; margin-bottom: 20px;}
      .board-row { display: flex; border-bottom: 1px solid rgba(0,0,0,0.1); min-height: 60px; }
      .board-row:last-child { border-bottom: none; }
      
      .row-label { 
        width: 60px; background: rgba(255,255,255,0.9); display: flex; align-items: center; justify-content: center; 
        font-weight: bold; font-size: 14px; color: #333 ; border-right: 1px solid rgba(0,0,0,0.1); flex-shrink: 0;
      }
      
      .row-zone { 
        flex-grow: 1; padding: 10px; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 8px; 
        background: transparent;
      }
      
      .horse-node { 
        width: 40px; height: 40px; display: flex; justify-content: center; align-items: center; 
        font-weight: bold; font-size: 20px; border-radius: 8px; cursor: grab; 
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
      }
      .horse-node:active { cursor: grabbing; box-shadow: 0 4px 8px rgba(0,0,0,0.3); transform: scale(1.1); }
      
      .waku-1 { background: #ffffff ; color: #333 ; border: 1px solid #999 ; }
      .waku-2 { background: #333333 ; color: #fff ; border: 1px solid #333 ;}
      .waku-3 { background: #d32f2f ; color: #fff ; border: 1px solid #b71c1c ;}
      .waku-4 { background: #1976d2 ; color: #fff ; border: 1px solid #0d47a1 ;}
      .waku-5 { background: #fbc02d ; color: #333 ; border: 1px solid #f57f17 ;}
      .waku-6 { background: #388e3c ; color: #fff ; border: 1px solid #1b5e20 ;}
      .waku-7 { background: #f57c00 ; color: #fff ; border: 1px solid #e65100 ;}
      .waku-8 { background: #f48fb1 ; color: #333 ; border: 1px solid #c2185b ;}
      .waku-default { background: #999 ; color: #fff ; border: 1px solid #666 ;} 
      
      .sortable-ghost { opacity: 0.4; }
    
      #detail -area { display: none; margin-top: 20px; }
      
      /* 【修正】テーブルがスマホ画面にピタッと収まるための調整 */
      table { 
        width: 100%; border-collapse: collapse; background: #fff ; 
        box-shadow: 0 1px 3px rgba(0,0,0,0.1); 
        font-size: 11.5px; /* スマホ向けに少しだけ文字を小さく */
        table-layout: fixed; /* 列の幅を固定してはみ出しを防ぐ */
      }
      th, td { 
        border: 1px solid #ddd ; 
        padding: 6px 2px; /* 横の余白を削ってスペースを確保 */
        text-align: center; vertical-align: middle; 
        word-wrap: break-word; line-height: 1.3;
      }
      th { background: #f4f4f4 ; font-weight: bold; color: #333 ; }
      
      /* 各列の幅と改行ルールの指定 */
      th:nth-child(1), td:nth-child(1) { width: 34px; } /* 馬番 */
      th:nth-child(2), td:nth-child(2) { width: 33%; text-align: left; padding-left: 4px; font-weight: bold; } /* 馬名 */
      th:nth-child(3), td:nth-child(3) { width: 55px; white-space: nowrap; } /* 騎手(絶対に改行させない) */
      th:nth-child(4), td:nth-child(4) { width: auto; } /* 通過順(自然に改行させる) */
    
      .history-text { font-family: monospace; letter-spacing: -0.5px; font-size: 11px; }
      .jockey-name { color: #1976d2 ; font-weight: bold; }
      
      .table-badge {
        display: inline-flex; justify-content: center; align-items: center;
        width: 26px; height: 26px; border-radius: 50%; font-weight: bold; font-size: 14px;
        margin: 0 auto; box-sizing: border-box;
      }
    </style>
    <script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
    </head>
    <body>
    
    <div class="mode-selector">
      <input type="radio" id="mode-jra" name="raceMode" value="jra" checked onchange="toggleGuide()">
      <label for="mode-jra" class="mode-label">🏇 中央競馬 (JRA)</label>
      
      <input type="radio" id="mode-nar" name="raceMode" value="nar" onchange="toggleGuide()">
      <label for="mode-nar" class="mode-label">🐎 地方競馬</label>
    </div>
    
    <div id="guide-jra" class="guide-text">
      💡 <strong>JRA公式サイト</strong>などの出馬表をコピーして、下の枠に貼り付けてください。
    </div>
    <div id="guide-nar" class="guide-text guide-nar">
      💡 <strong>KEIBA.GO.JP(地方競馬情報サイト)</strong>などの出馬表をコピーして、下の枠に貼り付けてください。
    </div>
    
    <textarea id="raceData" placeholder="コピーした出馬表テキストをここにペースト"></textarea>
    
    <div class="button-group">
      <button class="btn-clear" onclick="resetBoard()">リセット</button>
      <button class="btn-run" id="btn-run" onclick="analyzeData()">シミュレーター起動</button>
    </div>
    
    <div id="race-info-header">
      <div class="race-title" id="race-title-text">レース情報</div>
      <div class="pace-badge" id="pace-badge-text">ミドルペース</div>
    </div>
    
    <div class="board-container" id="main-board" style="display:none;">
      <div class="board-row"><div class="row-label">逃げ</div><div class="row-zone" id="zone-nige"></div></div>
      <div class="board-row"><div class="row-label">先行</div><div class="row-zone" id="zone-senkou"></div></div>
      <div class="board-row"><div class="row-label">差し</div><div class="row-zone" id="zone-sashi"></div></div>
      <div class="board-row"><div class="row-label">追込</div><div class="row-zone" id="zone-oikomi"></div></div>
    </div>
    
    <div id="detail-area">
      <h4 style="margin:0 0 10px 0; font-size: 14px; color: #333 ;">📋 出走馬データ(直近3走の通過順)</h4>
      <div id="detail-table-container"></div>
    </div>
    
    <script>
    function toggleGuide() {
      const isNAR = document.getElementById('mode-nar').checked;
      document.getElementById('guide-jra').style.display = isNAR ? 'none' : 'block';
      document.getElementById('guide-nar').style.display = isNAR ? 'block' : 'none';
      
      const btnRun = document.getElementById('btn-run');
      btnRun.style.background = isNAR ? '#1a73e8' : '#e60012'; 
    }
    
    function resetBoard() {
      document.getElementById('raceData').value = '';
      document.getElementById('race-info-header').style.display = 'none';
      document.getElementById('main-board').style.display = 'none';
      document.getElementById('detail-area').style.display = 'none';
      
      document.getElementById('zone-nige').innerHTML = '';
      document.getElementById('zone-senkou').innerHTML = '';
      document.getElementById('zone-sashi').innerHTML = '';
      document.getElementById('zone-oikomi').innerHTML = '';
      document.getElementById('detail-table-container').innerHTML = '';
    }
    
    function updatePaceBadge() {
      const nigeCount = document.getElementById('zone-nige').children.length;
      const senkouCount = document.getElementById('zone-senkou').children.length;
      const frontHorseCount = nigeCount + senkouCount;
    
      const paceBadge = document.getElementById('pace-badge-text');
      if (frontHorseCount >= 6) {
        paceBadge.innerText = "🔥 ハイペース"; 
        paceBadge.className = "pace-badge pace-high";
      } else if (frontHorseCount <= 2) {
        paceBadge.innerText = "🐢 スローペース"; 
        paceBadge.className = "pace-badge pace-slow";
      } else {
        paceBadge.innerText = "⚖️ ミドルペース"; 
        paceBadge.className = "pace-badge";
      }
    }
    
    function analyzeData() {
      const text = document.getElementById('raceData').value;
      if(!text) return;
    
      const isNAR = document.getElementById('mode-nar').checked;
    
      let raceName = "レース情報", startTime = "--:--", raceClass = "";
      const isTurf = text.includes("芝");
      const isDirt = text.includes("ダート");
    
      if (isNAR) {
        const narMatch = text.match(/(.*?)第(\d+)競走[ \s]+(\d{1,2}:\d{2})発走/);
        if(narMatch) {
          let rawPlace = narMatch[1];
          let place = rawPlace.replace(/.*[((].[))]\s*/, '').replace(/[\s ]/g, '');
          raceName = `${place}${narMatch[2]}R`;
          startTime = narMatch[3];
        } else {
          raceName = "地方競馬レース";
        }
      } else {
        const matchRace = text.match(/([^\s]+?\d+R)/);
        raceName = matchRace ? matchRace[1] : "JRAレース";
        const matchTime = text.match(/発.?[ \t]*(\d{1,2}:\d{2})/);
        startTime = matchTime ? matchTime[1] : "--:--";
        const classMatch = text.match(/(未勝利|\d勝クラス|オープン|新馬|重賞|[GJ][123I])/);
        if(classMatch) raceClass = classMatch[1];
      }
    
      const boardHeader = document.getElementById('race-info-header');
      const boardContainer = document.getElementById('main-board');
      
      document.getElementById('race-title-text').innerText = `${raceName} ${raceClass} (発走 ${startTime})`;
    
      if (isTurf) {
        boardHeader.style.backgroundColor = "#e8f5e9"; boardContainer.style.backgroundColor = "#c8e6c9"; 
      } else if (isDirt) {
        boardHeader.style.backgroundColor = "#fdf5e6"; boardContainer.style.backgroundColor = "#d7ccc8"; 
      } else {
        boardHeader.style.backgroundColor = "#f9f9f9"; boardContainer.style.backgroundColor = "#f9f9f9";
      }
    
      const lines = text.split('\n').map(l => l.trim());
      let horses = [];
      let currentHorse = null;
    
      if (isNAR) {
        for (let i = 0; i < lines.length; i++) {
          let line = lines[i];
          let nameMatch = line.match(/^([1-8])\s+(\d{1,2})\s+([ァ-ヴー・A-Z0-9]+)\s+([^\s]+(?:([^)]+))?)/);
          
          if (nameMatch) {
            if (currentHorse) horses.push(currentHorse);
            currentHorse = { 
              waku: nameMatch[1], 
              uma: nameMatch[2], 
              name: nameMatch[3], 
              jockey: nameMatch[4].split('(')[0],
              ranks: [], avg: 99 
            };
            continue;
          }
          
          if (currentHorse) {
            let rankRegex = /(?:\d:\d{2}\.\d)\s+([\d\-]+)\s+(?:\d{2}\.\d)/g;
            let ranksMatch;
            while ((ranksMatch = rankRegex.exec(line)) !== null) {
              currentHorse.ranks.push(ranksMatch[1]);
            }
          }
        }
        if (currentHorse) horses.push(currentHorse);
    
      } else {
        for (let i = 0; i < lines.length; i++) {
          let line = lines[i];
          let nameMatch = line.match(/^(?:(\d{1,2})\s+)?([ァ-ヴー・]{2,15})\s+\d+\.\d+/);
          if (!nameMatch && i < lines.length - 1 && lines[i+1].includes('除外')) {
             nameMatch = line.match(/^(?:(\d{1,2})\s+)?([ァ-ヴー・]{2,15})$/);
          }
          
          if (nameMatch) {
            if (currentHorse) horses.push(currentHorse);
            let uma = nameMatch[1];
            let waku = "default";
            
            if (!uma) {
                for (let j = 1; j <= 3; j++) {
                    if (i - j < 0) break;
                    let prevLine = lines[i-j];
                    let wuMatch = prevLine.match(/^([1-8])\s+(\d{1,2})$/);
                    if (wuMatch) { waku = wuMatch[1]; uma = wuMatch[2]; break; }
                    let singleUmaMatch = prevLine.match(/^(\d{1,2})$/);
                    if (singleUmaMatch && i-j-1 >= 0) {
                        let singleWakuMatch = lines[i-j-1].match(/^([1-8])$/);
                        if (singleWakuMatch) { waku = singleWakuMatch[1]; uma = singleUmaMatch[1]; break; }
                    }
                }
            } else {
                if (i > 0) {
                    let wakuMatch = lines[i-1].match(/^([1-8])$/);
                    if (wakuMatch) waku = wakuMatch[1];
                }
            }
            currentHorse = { name: nameMatch[2], waku: waku, uma: uma || "?", jockey: "-", ranks: [], avg: 99 };
            continue;
          }
          
          if (currentHorse) {
            let jockeyMatch = line.match(/\d{3}kg\s+([^\s]+)\s+\d{2}\.\dkg/);
            if (jockeyMatch) currentHorse.jockey = jockeyMatch[1];
            let rankMatch = line.match(/(?:\d:\d{2}\.\d|\d{2}\.\d)\s+([\d\-]+)\s+3F/);
            if (rankMatch) currentHorse.ranks.push(rankMatch[1]);
          }
        }
        if (currentHorse) horses.push(currentHorse);
      }
    
      if (horses.length === 0) return alert('データを読み取れませんでした。コピー範囲や上部の「中央/地方」の選択が正しいか確認してください。');
    
      const zones = { nige: '', senkou: '', sashi: '', oikomi: '' };
      let tableRows = '';
    
      horses.sort((a,b) => {
          let numA = parseInt(a.uma); let numB = parseInt(b.uma);
          if(isNaN(numA)) numA = 999; if(isNaN(numB)) numB = 999;
          return numA - numB;
      }).forEach(h => {
        if(h.ranks.length === 0) return; 
        
        let sum = 0, count = 0;
        h.ranks.forEach(r => {
           const first = parseInt(r.split('-')[0]);
           if (!isNaN(first)) { sum += first; count++; }
        });
        const avg = count > 0 ? sum / count : 99;
    
        let targetZone = 'oikomi';
        if (avg <= 3.5) { targetZone = 'nige'; }
        else if (avg <= 7) { targetZone = 'senkou'; }
        else if (avg <= 11) { targetZone = 'sashi'; }
    
        const wakuClass = h.waku === "default" ? "waku-default" : `waku-${h.waku}`;
        
        zones[targetZone] += `<div class="horse-node ${wakuClass}">${h.uma}</div>`;
    
        const history3 = h.ranks.slice(0, 3).join(' / ') || '-';
        tableRows += `
          <tr>
            <td><div class="table-badge ${wakuClass}">${h.uma}</div></td>
            <td>${h.name}</td>
            <td class="jockey-name">${h.jockey}</td>
            <td class="history-text">${history3}</td>
          </tr>
        `;
      });
    
      document.getElementById('zone-nige').innerHTML = zones.nige;
      document.getElementById('zone-senkou').innerHTML = zones.senkou;
      document.getElementById('zone-sashi').innerHTML = zones.sashi;
      document.getElementById('zone-oikomi').innerHTML = zones.oikomi;
      
      document.getElementById('detail-table-container').innerHTML = `
        <table><tr><th>馬番</th><th>馬名</th><th>騎手</th><th>過去の通過順</th></tr>${tableRows}</table>
      `;
    
      boardHeader.style.display = 'flex';
      boardContainer.style.display = 'block';
      document.getElementById('detail-area').style.display = 'block';
    
      updatePaceBadge();
    
      const sortableOptions = { 
        group: 'shared', 
        animation: 150, 
        ghostClass: 'sortable-ghost',
        onSort: updatePaceBadge
      };
      new Sortable(document.getElementById('zone-nige'), sortableOptions);
      new Sortable(document.getElementById('zone-senkou'), sortableOptions);
      new Sortable(document.getElementById('zone-sashi'), sortableOptions);
      new Sortable(document.getElementById('zone-oikomi'), sortableOptions);
    }
    </script>
    </body>
    </html>
    

    あなたへのおすすめ