On main: temporary stash before history cleanup

This commit is contained in:
2026-01-09 21:57:55 +05:00
parent 4f9417a032
commit b3597473c7
7 changed files with 138 additions and 7 deletions

View File

@@ -292,3 +292,5 @@ racing-tools/
**Лицензия:** MIT
**Автор:** Racing Team

View File

@@ -41,3 +41,5 @@ echo " • Нарисуйте карту, обязательно добавьт
echo " • Экспортируйте в JSON для использования в решателе"
echo " • Для визуализации решений откройте ./open-player.sh"

View File

@@ -42,3 +42,5 @@ echo " • Затем загрузите решение (🎬 Загрузит
echo " • Используйте кнопки управления для анимации"
echo " • Демо-файлы: demo-with-start.json и demo-with-start-solution.json"

View File

@@ -25,10 +25,12 @@
<h3>📂 Загрузка файлов</h3>
<div class="buttons">
<button class="btn-primary" id="loadMapBtn" onclick="document.getElementById('mapInput').click()">📂 Загрузить карту</button>
<button class="btn-primary" id="solveBtn" onclick="solveMap()" disabled>🧠 Найти решение</button>
<button class="btn-success" id="loadSolutionBtn" onclick="document.getElementById('solutionInput').click()">🎬 Загрузить решение</button>
</div>
<input type="file" id="mapInput" accept=".json" onchange="loadMap(event)">
<input type="file" id="solutionInput" accept=".json" onchange="loadSolution(event)">
<div id="solverStatus" class="solver-status"></div>
</div>
<div id="playbackControls" class="visualization-panel">

View File

@@ -287,6 +287,9 @@ function loadMap(event) {
resizeCanvas();
drawMap();
// Включаем кнопку "Найти решение" после загрузки карты
document.getElementById('solveBtn').disabled = false;
document.getElementById('loadMapBtn').textContent = '✓ Карта загружена';
setTimeout(() => {
document.getElementById('loadMapBtn').textContent = '📂 Загрузить карту';
@@ -505,6 +508,125 @@ function clearVisualization() {
drawMap();
}
// Решение карты через API
async function solveMap() {
const solveBtn = document.getElementById('solveBtn');
const statusDiv = document.getElementById('solverStatus');
// Проверяем, что карта загружена
if (!map || map.length === 0) {
alert('⚠️ Сначала загрузите карту!');
return;
}
// Находим стартовую позицию
startPosition = findStartPosition(map, width, height);
if (!startPosition) {
alert('⚠️ На карте не найдена точка старта (тип 5)!');
return;
}
// Проверяем наличие чекпоинтов
let hasCheckpoint = false;
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
if (map[y][x] === 4) {
hasCheckpoint = true;
break;
}
}
if (hasCheckpoint) break;
}
if (!hasCheckpoint) {
alert('⚠️ На карте нет чекпоинтов (тип 4)!');
return;
}
// Отключаем кнопку и показываем статус
solveBtn.disabled = true;
solveBtn.textContent = '⏳ Поиск решения...';
statusDiv.innerHTML = '<div style="color: #ff9800;">⏳ Отправка запроса на сервер...</div>';
try {
const requestData = {
map: map,
maxIterations: 5000000
};
const response = await fetch('http://localhost:5000/solve', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
if (result.success) {
// Успешно найдено решение
const stats = result.statistics;
statusDiv.innerHTML = `
<div style="color: #4caf50; font-weight: bold;">✅ Решение найдено!</div>
<div style="font-size: 12px; margin-top: 5px;">
📊 Шагов: ${stats.steps}<br>
🎯 Чекпоинтов: ${stats.checkpoints}<br>
⚡ Макс. скорость: ${stats.maxSpeed}<br>
⏱️ Время: ${stats.computeTimeSeconds.toFixed(2)}s
</div>
`;
// Загружаем решение напрямую
solution = result.solution;
trajectory = simulateTrajectory(solution, startPosition);
currentStep = 0;
// Обновляем состояние кнопок и информацию
updateControlsState();
updateStepInfo();
drawMap();
// Автоматически начинаем воспроизведение
setTimeout(() => {
playVisualization();
}, 500);
} else {
// Решение не найдено
statusDiv.innerHTML = `
<div style="color: #f44336; font-weight: bold;">❌ Решение не найдено</div>
<div style="font-size: 12px; margin-top: 5px;">${result.error || 'Неизвестная ошибка'}</div>
`;
}
} catch (error) {
console.error('Ошибка при решении карты:', error);
if (error.message.includes('Failed to fetch') || error.message.includes('NetworkError')) {
statusDiv.innerHTML = `
<div style="color: #f44336; font-weight: bold;">❌ Сервер недоступен</div>
<div style="font-size: 12px; margin-top: 5px;">
Убедитесь, что сервер запущен:<br>
<code style="background: #333; padding: 2px 5px; border-radius: 3px;">./run-webservice.sh</code>
</div>
`;
} else {
statusDiv.innerHTML = `
<div style="color: #f44336; font-weight: bold;">❌ Ошибка</div>
<div style="font-size: 12px; margin-top: 5px;">${error.message}</div>
`;
}
} finally {
// Включаем кнопку обратно
solveBtn.disabled = false;
solveBtn.textContent = '🧠 Найти решение';
}
}
canvas.addEventListener('mousedown', (e) => {
if (e.button === 2 || e.shiftKey) {
isPanning = true;