File size: 10,566 Bytes
768f8c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<!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>