This commit is contained in:
2025-10-20 22:27:15 +05:00
parent 88643415aa
commit a9af432e27
22 changed files with 378 additions and 3122 deletions

View File

@@ -26,6 +26,8 @@ function init() {
initMap();
resizeCanvas();
drawMap();
updateControlsState();
updateStepInfo();
}
// Инициализация пустой карты
@@ -148,9 +150,11 @@ function simulateTrajectory(accelerations, start) {
let y = start.y;
let vx = 0;
let vy = 0;
let passedCheckpoints = new Set();
let totalSteps = accelerations.length;
// Начальная позиция
traj.push({ x, y, vx, vy, ax: 0, ay: 0 });
traj.push({ x, y, vx, vy, ax: 0, ay: 0, passedCheckpoints: 0, score: 0 });
// Применяем каждое ускорение
for (let i = 0; i < accelerations.length; i++) {
@@ -164,7 +168,21 @@ function simulateTrajectory(accelerations, start) {
x += vx;
y += vy;
traj.push({ x, y, vx, vy, ax, ay });
// Проверяем, попали ли на чекпоинт
const checkpointKey = `${Math.floor(x)},${Math.floor(y)}`;
if (map[Math.floor(y)] && map[Math.floor(y)][Math.floor(x)] === 4) {
passedCheckpoints.add(checkpointKey);
}
// Вычисляем очки по формуле: 100 * количество пройденных чекпоинтов ^ 1.3 / количество шагов
const checkpointCount = passedCheckpoints.size;
const score = totalSteps > 0 ? Math.round(100 * Math.pow(checkpointCount, 1.3) / totalSteps) : 0;
traj.push({
x, y, vx, vy, ax, ay,
passedCheckpoints: checkpointCount,
score: score
});
}
return traj;
@@ -237,11 +255,8 @@ function loadSolution(event) {
trajectory = simulateTrajectory(solution, startPosition);
currentStep = 0;
// Показываем панель визуализации
document.getElementById('playbackControls').classList.remove('hidden');
document.getElementById('stepInfo').classList.remove('hidden');
// Обновляем информацию
// Обновляем состояние кнопок и информацию
updateControlsState();
updateStepInfo();
drawMap();
@@ -261,9 +276,28 @@ function loadSolution(event) {
event.target.value = '';
}
// Обновление состояния элементов управления
function updateControlsState() {
const hasTrajectory = trajectory && trajectory.length > 0;
document.getElementById('playBtn').disabled = !hasTrajectory;
document.getElementById('pauseBtn').disabled = !hasTrajectory || !isPlaying;
document.getElementById('resetBtn').disabled = !hasTrajectory;
document.getElementById('backBtn').disabled = !hasTrajectory;
document.getElementById('forwardBtn').disabled = !hasTrajectory;
document.getElementById('speedSlider').disabled = !hasTrajectory;
}
// Обновление информации о текущем шаге
function updateStepInfo() {
if (!trajectory || trajectory.length === 0) return;
if (!trajectory || trajectory.length === 0) {
document.getElementById('stepNumber').textContent = '0 / 0';
document.getElementById('positionValue').textContent = '(0, 0)';
document.getElementById('velocityValue').textContent = '(0, 0)';
document.getElementById('accelerationValue').textContent = '(0, 0)';
document.getElementById('scoreValue').textContent = '0';
return;
}
const current = trajectory[currentStep];
@@ -271,6 +305,7 @@ function updateStepInfo() {
document.getElementById('positionValue').textContent = `(${current.x}, ${current.y})`;
document.getElementById('velocityValue').textContent = `(${current.vx}, ${current.vy})`;
document.getElementById('accelerationValue').textContent = `(${current.ax}, ${current.ay})`;
document.getElementById('scoreValue').textContent = current.score || 0;
}
// Воспроизведение визуализации
@@ -278,8 +313,7 @@ function playVisualization() {
if (!trajectory || trajectory.length === 0) return;
isPlaying = true;
document.getElementById('playBtn').disabled = true;
document.getElementById('pauseBtn').disabled = false;
updateControlsState();
playbackInterval = setInterval(() => {
if (currentStep < trajectory.length - 1) {
@@ -295,8 +329,7 @@ function playVisualization() {
// Пауза воспроизведения
function pauseVisualization() {
isPlaying = false;
document.getElementById('playBtn').disabled = false;
document.getElementById('pauseBtn').disabled = true;
updateControlsState();
if (playbackInterval) {
clearInterval(playbackInterval);
@@ -354,9 +387,8 @@ function clearVisualization() {
currentStep = 0;
startPosition = null;
document.getElementById('playbackControls').classList.add('hidden');
document.getElementById('stepInfo').classList.add('hidden');
updateControlsState();
updateStepInfo();
drawMap();
}