On main: temporary stash before history cleanup
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user