horiyouta commited on
Commit
c3dd274
·
1 Parent(s): 861a629

2508181826

Browse files
Files changed (1) hide show
  1. web/script.js +29 -28
web/script.js CHANGED
@@ -962,38 +962,37 @@ async function handleBattle() {
962
  isBattleInProgress = true;
963
  battleBtn.disabled = true;
964
 
965
- // --- フェーズ1: 訓練 ---
966
- battleBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> モデルを訓練中...';
967
- await animateBattleLog('戦闘準備... モデルを訓練中...');
968
- logMessage('モデルの訓練を開始しました...', 'info');
969
-
970
- // EelからFetch APIに変更
971
- const trainResponse = await fetch('/api/train_player_model', {
972
- method: 'POST',
973
- headers: {
974
- 'Content-Type': 'application/json',
975
- },
976
- body: JSON.stringify(playerLayers),
977
- });
978
- const trainResult = await trainResponse.json();
979
-
980
- if (!trainResult.success) {
981
- await animateBattleLog(`エラー: ${trainResult.message}`);
982
- logMessage(`訓練エラー: ${trainResult.message}`, 'error');
983
- isBattleInProgress = false;
984
- updatePlayerModelUI();
985
- battleBtn.innerHTML = '<i class="fas fa-fist-raised"></i> バトル開始!';
986
- return;
987
- }
988
- logMessage(trainResult.message, 'success');
989
- await sleep(500);
990
 
991
  // --- フェーズ2: 戦闘ループ ---
992
  while (playerHP > 0 && enemyHP > 0) {
993
  battleBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 攻撃中...';
994
  await animateBattleLog('新たな敵をスキャン... 推論実行...');
995
 
996
- // EelからFetch APIに変更
997
  const inferenceResponse = await fetch('/api/run_inference', {
998
  method: 'POST',
999
  headers: { 'Content-Type': 'application/json' },
@@ -1006,9 +1005,11 @@ async function handleBattle() {
1006
  const result = await inferenceResponse.json();
1007
 
1008
  if (result.error) {
 
 
1009
  await animateBattleLog(`エラー: ${result.error}`);
1010
  logMessage(`推論エラー: ${result.error}`, 'error');
1011
- break;
1012
  }
1013
 
1014
  enemyImage.src = result.image_b64;
@@ -1032,7 +1033,7 @@ async function handleBattle() {
1032
 
1033
  if (enemyHP > 0 && playerHP > 0) {
1034
  await sleep(1500);
1035
- await fetchNewEnemy(); // 次の敵を準備
1036
  }
1037
  }
1038
 
 
962
  isBattleInProgress = true;
963
  battleBtn.disabled = true;
964
 
965
+ // // --- フェーズ1: 訓練 ---
966
+ // battleBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> モデルを訓練中...';
967
+ // await animateBattleLog('戦闘準備... モデルを訓練中...');
968
+ // logMessage('モデルの訓練を開始しました...', 'info');
969
+
970
+ // // EelからFetch APIに変更
971
+ // const trainResponse = await fetch('/api/train_player_model', {
972
+ // method: 'POST',
973
+ // headers: {
974
+ // 'Content-Type': 'application/json',
975
+ // },
976
+ // body: JSON.stringify(playerLayers),
977
+ // });
978
+ // const trainResult = await trainResponse.json();
979
+
980
+ // if (!trainResult.success) {
981
+ // await animateBattleLog(`エラー: ${trainResult.message}`);
982
+ // logMessage(`訓練エラー: ${trainResult.message}`, 'error');
983
+ // isBattleInProgress = false;
984
+ // updatePlayerModelUI();
985
+ // battleBtn.innerHTML = '<i class="fas fa-fist-raised"></i> バトル開始!';
986
+ // return;
987
+ // }
988
+ // logMessage(trainResult.message, 'success');
989
+ // await sleep(500);
990
 
991
  // --- フェーズ2: 戦闘ループ ---
992
  while (playerHP > 0 && enemyHP > 0) {
993
  battleBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 攻撃中...';
994
  await animateBattleLog('新たな敵をスキャン... 推論実行...');
995
 
 
996
  const inferenceResponse = await fetch('/api/run_inference', {
997
  method: 'POST',
998
  headers: { 'Content-Type': 'application/json' },
 
1005
  const result = await inferenceResponse.json();
1006
 
1007
  if (result.error) {
1008
+ // ★★★ エラーメッセージを正しく表示するように修正 ★★★
1009
+ // 「訓練エラー: undefined」の問題はここで発生していた
1010
  await animateBattleLog(`エラー: ${result.error}`);
1011
  logMessage(`推論エラー: ${result.error}`, 'error');
1012
+ break; // エラーが発生したらループを抜ける
1013
  }
1014
 
1015
  enemyImage.src = result.image_b64;
 
1033
 
1034
  if (enemyHP > 0 && playerHP > 0) {
1035
  await sleep(1500);
1036
+ await fetchNewEnemy(); // 次の敵を取得
1037
  }
1038
  }
1039