Attonos's picture
a ted tomu najdi cestu at je to nahodne zazrfak
768f8c8 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Maze Solver | CodeWizard</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Fira Code', monospace;
background-color: #0f172a;
color: white;
}
.maze-cell {
width: 30px;
height: 30px;
border: 1px solid #334155;
}
.wall {
background-color: #1e293b;
}
.path {
background-color: #0f172a;
}
.start {
background-color: #10b981;
}
.end {
background-color: #ef4444;
}
.solution {
background-color: #6366f1;
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.7; }
}
.maze-container {
background-color: #1e293b;
}
</style>
</head>
<body>
<!-- Navigation -->
<nav class="py-6 px-6 md:px-12 flex justify-between items-center">
<div class="flex items-center space-x-2">
<i data-feather="cpu" class="text-purple-400"></i>
<span class="text-xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-purple-400 to-blue-500">Maze Solver</span>
</div>
<div class="hidden md:flex space-x-8">
<a href="index.html" class="hover:text-purple-300 transition">Main</a>
<a href="quantum.html" class="hover:text-purple-300 transition">Quantum</a>
<a href="visual.html" class="hover:text-purple-300 transition">Visual</a>
<a href="hexa.html" class="hover:text-purple-300 transition">HEXA</a>
<a href="game.html" class="hover:text-purple-300 transition">Game Lab</a>
</div>
</nav>
<main class="container mx-auto px-6 md:px-12 py-8">
<div class="text-center mb-8">
<h1 class="text-4xl md:text-5xl font-bold mb-4">
<span class="bg-clip-text text-transparent bg-gradient-to-r from-purple-400 to-blue-500">Maze</span> Solver
</h1>
<p class="text-lg text-gray-300">Watch our AI agents solve randomly generated mazes</p>
</div>
<div class="flex flex-col md:flex-row gap-8">
<div class="md:w-1/3">
<div class="glass-card p-6 rounded-xl mb-6">
<h3 class="text-xl font-bold mb-4">Controls</h3>
<div class="space-y-4">
<button id="generate-btn" class="w-full py-2 px-4 bg-purple-600 hover:bg-purple-700 rounded-lg transition">
Generate Maze
</button>
<button id="solve-btn" class="w-full py-2 px-4 bg-blue-600 hover:bg-blue-700 rounded-lg transition">
Solve Maze
</button>
<div class="flex items-center justify-between">
<label for="size-slider" class="text-sm">Maze Size:</label>
<span id="size-value" class="text-sm">15</span>
</div>
<input type="range" id="size-slider" min="5" max="25" value="15" class="w-full">
</div>
</div>
<div class="glass-card p-6 rounded-xl">
<h3 class="text-xl font-bold mb-4">Legend</h3>
<div class="grid grid-cols-2 gap-4">
<div class="flex items-center">
<div class="maze-cell wall mr-2"></div>
<span>Wall</span>
</div>
<div class="flex items-center">
<div class="maze-cell path mr-2"></div>
<span>Path</span>
</div>
<div class="flex items-center">
<div class="maze-cell start mr-2"></div>
<span>Start</span>
</div>
<div class="flex items-center">
<div class="maze-cell end mr-2"></div>
<span>End</span>
</div>
<div class="flex items-center">
<div class="maze-cell solution mr-2"></div>
<span>Solution</span>
</div>
</div>
</div>
</div>
<div class="md:w-2/3">
<div class="glass-card p-6 rounded-xl">
<div id="maze" class="maze-container mx-auto overflow-auto p-4 rounded-lg"></div>
</div>
</div>
</div>
</main>
<footer class="py-8 px-6 md:px-12 mt-12 border-t border-gray-700">
<div class="container mx-auto text-center">
<p class="text-gray-400">© 2023 CodeWizard Maze Solver. All paths lead somewhere.</p>
</div>
</footer>
<script>
document.addEventListener('DOMContentLoaded', () => {
feather.replace();
const mazeElement = document.getElementById('maze');
const generateBtn = document.getElementById('generate-btn');
const solveBtn = document.getElementById('solve-btn');
const sizeSlider = document.getElementById('size-slider');
const sizeValue = document.getElementById('size-value');
let mazeSize = 15;
let maze = [];
let solutionPath = [];
sizeSlider.addEventListener('input', () => {
mazeSize = parseInt(sizeSlider.value);
sizeValue.textContent = mazeSize;
});
generateBtn.addEventListener('click', generateMaze);
solveBtn.addEventListener('click', solveMaze);
function generateMaze() {
maze = [];
solutionPath = [];
// Create empty maze grid
for (let i = 0; i < mazeSize; i++) {
maze[i] = [];
for (let j = 0; j < mazeSize; j++) {
maze[i][j] = Math.random() > 0.7 ? 1 : 0; // 1 = wall, 0 = path
}
}
// Ensure start and end points
maze[0][0] = 0; // Start
maze[mazeSize-1][mazeSize-1] = 0; // End
renderMaze();
}
function renderMaze() {
mazeElement.innerHTML = '';
mazeElement.style.width = `${mazeSize * 32 + 8}px`;
mazeElement.style.height = `${mazeSize * 32 + 8}px`;
for (let i = 0; i < mazeSize; i++) {
const row = document.createElement('div');
row.className = 'flex';
for (let j = 0; j < mazeSize; j++) {
const cell = document.createElement('div');
cell.className = 'maze-cell';
if (i === 0 && j === 0) {
cell.classList.add('start');
} else if (i === mazeSize-1 && j === mazeSize-1) {
cell.classList.add('end');
} else if (maze[i][j] === 1) {
cell.classList.add('wall');
} else if (solutionPath.some(coord => coord[0] === i && coord[1] === j)) {
cell.classList.add('solution');
} else {
cell.classList.add('path');
}
row.appendChild(cell);
}
mazeElement.appendChild(row);
}
}
function solveMaze() {
if (maze.length === 0) {
alert('Please generate a maze first!');
return;
}
// Reset solution
solutionPath = [];
// Simple pathfinding (DFS)
const visited = Array(mazeSize).fill().map(() => Array(mazeSize).fill(false));
const path = [];
function dfs(x, y) {
if (x < 0 || y < 0 || x >= mazeSize || y >= mazeSize || maze[x][y] === 1 || visited[x][y]) {
return false;
}
visited[x][y] = true;
path.push([x, y]);
if (x === mazeSize-1 && y === mazeSize-1) {
return true;
}
if (dfs(x+1, y) || dfs(x, y+1) || dfs(x-1, y) || dfs(x, y-1)) {
return true;
}
path.pop();
return false;
}
if (dfs(0, 0)) {
solutionPath = [...path];
renderMaze();
// Animate the solution
solutionPath.forEach((coord, index) => {
setTimeout(() => {
const cell = mazeElement.children[coord[0]].children[coord[1]];
cell.classList.add('solution');
}, index * 50);
});
} else {
alert("No path found! Try generating a new maze.");
}
}
// Generate initial maze
generateMaze();
});
</script>
</body>
</html>