Update index.html
Browse files- index.html +413 -18
index.html
CHANGED
@@ -1,19 +1,414 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8" />
|
5 |
+
<title>Kubernetes TicTicToe</title>
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
+
</head>
|
9 |
+
<body class="bg-gradient-to-br from-emerald-50 to-sky-100 min-h-screen flex items-center justify-center p-6">
|
10 |
+
<div class="w-full max-w-5xl bg-white rounded-2xl shadow-xl p-6">
|
11 |
+
<h1 class="text-3xl md:text-4xl font-extrabold text-center text-emerald-700">Kubernetes TicTicToe</h1>
|
12 |
+
<p class="text-center text-sm text-gray-600 mt-2">
|
13 |
+
Source:
|
14 |
+
<a class="text-blue-600 underline" target="_blank" rel="noopener"
|
15 |
+
href="https://www.linkedin.com/pulse/kubernetes-fundamentals-orchestrating-containers-scale-michael-lively-kaxae/">
|
16 |
+
Kubernetes Fundamentals: Orchestrating Containers at Scale — Michael Lively
|
17 |
+
</a>
|
18 |
+
</p>
|
19 |
+
|
20 |
+
<div id="banner" class="hidden bg-emerald-100 border border-emerald-300 text-emerald-900 font-semibold text-center py-2 rounded mt-4"></div>
|
21 |
+
|
22 |
+
<div class="mt-6 flex flex-col md:flex-row md:space-x-6 space-y-4 md:space-y-0">
|
23 |
+
<!-- Board -->
|
24 |
+
<div id="board" class="grid grid-cols-3 gap-2 p-2 bg-gray-50 rounded-xl border-4 border-gray-200 mx-auto"></div>
|
25 |
+
|
26 |
+
<!-- Question Panel -->
|
27 |
+
<div id="questionPanel" class="md:w-1/2 w-full bg-gray-50 rounded-xl shadow-inner p-4">
|
28 |
+
<h2 id="panelQuestion" class="text-lg md:text-xl font-semibold text-gray-800">
|
29 |
+
Select a square to view the question
|
30 |
+
</h2>
|
31 |
+
<ul id="panelChoices" class="mt-4 space-y-2"></ul>
|
32 |
+
<p id="panelHint" class="mt-3 text-sm text-gray-600 hidden"></p>
|
33 |
+
<div class="mt-4 flex items-center space-x-2">
|
34 |
+
<button id="hintBtn" class="px-3 py-1.5 bg-gray-200 text-gray-700 rounded hover:bg-gray-300">Show Hint</button>
|
35 |
+
<button id="clearBtn" class="px-3 py-1.5 bg-white border rounded hover:bg-gray-100">Clear Panel</button>
|
36 |
+
</div>
|
37 |
+
</div>
|
38 |
+
</div>
|
39 |
+
|
40 |
+
<div class="flex flex-col md:flex-row md:items-center md:justify-between mt-6 space-y-3 md:space-y-0">
|
41 |
+
<p id="status" class="text-lg font-medium text-gray-800"></p>
|
42 |
+
<div class="flex items-center space-x-2">
|
43 |
+
<label class="text-sm text-gray-600">Mode:</label>
|
44 |
+
<select id="mode" class="border rounded px-2 py-1 text-sm">
|
45 |
+
<option value="two">Two Players (X vs O)</option>
|
46 |
+
<option value="solo">Solo (You are X)</option>
|
47 |
+
</select>
|
48 |
+
<button id="restartBtn" class="px-4 py-2 bg-emerald-700 text-white rounded hover:bg-emerald-800">Restart</button>
|
49 |
+
</div>
|
50 |
+
</div>
|
51 |
+
</div>
|
52 |
+
|
53 |
+
<script>
|
54 |
+
// --- Utilities ---
|
55 |
+
const randShuffle = (arr) => arr
|
56 |
+
.map(x => ({ x, r: Math.random() }))
|
57 |
+
.sort((a,b) => a.r - b.r)
|
58 |
+
.map(o => o.x);
|
59 |
+
|
60 |
+
// --- Question bank (answers identified by 'answer' index BEFORE shuffle) ---
|
61 |
+
// Based on your article content (control plane, pods, services, workloads, scaling, CI/CD with K8s, etc.)
|
62 |
+
const QUESTION_BANK = [
|
63 |
+
{
|
64 |
+
question: 'Why do teams use Kubernetes instead of managing containers manually?',
|
65 |
+
choices: [
|
66 |
+
'To run monoliths only',
|
67 |
+
'To automate scaling, healing, and rollouts',
|
68 |
+
'To replace Linux entirely',
|
69 |
+
'To remove the need for Dockerfiles'
|
70 |
+
],
|
71 |
+
answer: 2,
|
72 |
+
hint: 'Think automation: scale, balance, recover.'
|
73 |
+
},
|
74 |
+
{
|
75 |
+
question: 'In Kubernetes, what is the smallest deployable unit?',
|
76 |
+
choices: ['Container', 'Image', 'Pod', 'Node'],
|
77 |
+
answer: 3,
|
78 |
+
hint: 'It can hold one or more containers.'
|
79 |
+
},
|
80 |
+
{
|
81 |
+
question: 'Which component stores cluster state?',
|
82 |
+
choices: ['kubelet', 'kube-proxy', 'etcd', 'scheduler'],
|
83 |
+
answer: 3,
|
84 |
+
hint: 'Key–value store for desired/actual state.'
|
85 |
+
},
|
86 |
+
{
|
87 |
+
question: 'What does the scheduler do?',
|
88 |
+
choices: [
|
89 |
+
'Stores secrets',
|
90 |
+
'Assigns Pods to nodes based on resources and constraints',
|
91 |
+
'Exposes services to the internet',
|
92 |
+
'Builds images'
|
93 |
+
],
|
94 |
+
answer: 2,
|
95 |
+
hint: 'Placement decisions.'
|
96 |
+
},
|
97 |
+
{
|
98 |
+
question: 'What replaced the old Dockershim integration in Kubernetes v1.24?',
|
99 |
+
choices: ['containerd/CRI-O via CRI', 'LXC directly', 'Hyper-V only', 'Bash scripts'],
|
100 |
+
answer: 1,
|
101 |
+
hint: 'Common modern runtimes are containerd and CRI-O.'
|
102 |
+
},
|
103 |
+
{
|
104 |
+
question: 'What is a Deployment primarily used for?',
|
105 |
+
choices: [
|
106 |
+
'One Pod per node',
|
107 |
+
'Long-running stateless workloads with rolling updates',
|
108 |
+
'Cron-style scheduled jobs',
|
109 |
+
'Stable network IDs and storage for stateful apps'
|
110 |
+
],
|
111 |
+
answer: 2,
|
112 |
+
hint: 'Think rolling updates + replicas.'
|
113 |
+
},
|
114 |
+
{
|
115 |
+
question: 'Which workload ensures one Pod runs on every node?',
|
116 |
+
choices: ['StatefulSet', 'DaemonSet', 'Job', 'ReplicaSet'],
|
117 |
+
answer: 2,
|
118 |
+
hint: 'Used for log/metrics agents.'
|
119 |
+
},
|
120 |
+
{
|
121 |
+
question: 'Why do we need Services in Kubernetes?',
|
122 |
+
choices: [
|
123 |
+
'Pods are ephemeral; Services provide stable DNS and load balancing',
|
124 |
+
'To store images',
|
125 |
+
'To run kernels',
|
126 |
+
'To create CRDs automatically'
|
127 |
+
],
|
128 |
+
answer: 1,
|
129 |
+
hint: 'Stable name in front of changing Pods.'
|
130 |
+
},
|
131 |
+
{
|
132 |
+
question: 'Which command scales a Deployment to 5 replicas?',
|
133 |
+
choices: [
|
134 |
+
'kubectl scale deployment myapp --replicas=5',
|
135 |
+
'kubectl run myapp --replicas=5',
|
136 |
+
'kubectl upsize myapp 5',
|
137 |
+
'kubectl add pods myapp 5'
|
138 |
+
],
|
139 |
+
answer: 1,
|
140 |
+
hint: 'Use the scale subcommand.'
|
141 |
+
},
|
142 |
+
{
|
143 |
+
question: 'What best describes Kubernetes’ model?',
|
144 |
+
choices: [
|
145 |
+
'Imperative only',
|
146 |
+
'Declarative: you state desired end, K8s converges',
|
147 |
+
'Interactive shell only',
|
148 |
+
'All manual edits on live Pods'
|
149 |
+
],
|
150 |
+
answer: 2,
|
151 |
+
hint: 'You describe the target state; controllers do the rest.'
|
152 |
+
},
|
153 |
+
{
|
154 |
+
question: 'Which component enforces that containers are healthy on a node?',
|
155 |
+
choices: ['kubelet', 'kubeadm', 'kubectl', 'kustomize'],
|
156 |
+
answer: 1,
|
157 |
+
hint: 'Node agent.'
|
158 |
+
},
|
159 |
+
{
|
160 |
+
question: 'What does kube-proxy handle?',
|
161 |
+
choices: [
|
162 |
+
'Pod storage provisioning',
|
163 |
+
'Scheduling decisions',
|
164 |
+
'Cluster networking for Services/virtual IPs',
|
165 |
+
'RBAC policy management'
|
166 |
+
],
|
167 |
+
answer: 3,
|
168 |
+
hint: 'Traffic routing to Service backends.'
|
169 |
+
},
|
170 |
+
{
|
171 |
+
question: 'What is the main reason to use a StatefulSet?',
|
172 |
+
choices: [
|
173 |
+
'GPU scheduling',
|
174 |
+
'Stable identities and storage for stateful Pods',
|
175 |
+
'One Pod per node',
|
176 |
+
'Short-lived batch tasks'
|
177 |
+
],
|
178 |
+
answer: 2,
|
179 |
+
hint: 'Think stable network IDs and persistent volumes.'
|
180 |
+
},
|
181 |
+
{
|
182 |
+
question: 'Which command updates the image in a Deployment?',
|
183 |
+
choices: [
|
184 |
+
'kubectl set image deployment web web=nginx:1.27',
|
185 |
+
'kubectl image switch web=nginx:1.27',
|
186 |
+
'kubectl rollout change web=nginx:1.27',
|
187 |
+
'kubectl deploy image web=nginx:1.27'
|
188 |
+
],
|
189 |
+
answer: 1,
|
190 |
+
hint: 'Uses “set image … deployment …”.'
|
191 |
+
},
|
192 |
+
{
|
193 |
+
question: 'How do you undo a bad rollout?',
|
194 |
+
choices: [
|
195 |
+
'kubectl rollback last',
|
196 |
+
'kubectl rollout undo deployment web',
|
197 |
+
'kubectl reset deployment web',
|
198 |
+
'kubectl undo web now'
|
199 |
+
],
|
200 |
+
answer: 2,
|
201 |
+
hint: 'Subcommand is “rollout undo”.'
|
202 |
+
},
|
203 |
+
{
|
204 |
+
question: 'How does Kubernetes achieve self-healing?',
|
205 |
+
choices: [
|
206 |
+
'By pausing the scheduler',
|
207 |
+
'Controllers reschedule/restart Pods to match desired state',
|
208 |
+
'By disabling probes',
|
209 |
+
'By editing live containers manually'
|
210 |
+
],
|
211 |
+
answer: 2,
|
212 |
+
hint: 'Controllers reconcile actual vs. desired state.'
|
213 |
+
},
|
214 |
+
{
|
215 |
+
question: 'Why is DNS/service discovery important in K8s?',
|
216 |
+
choices: [
|
217 |
+
'Because Pod IPs change; DNS gives a stable name',
|
218 |
+
'It enables image scanning',
|
219 |
+
'It configures RBAC',
|
220 |
+
'It stores logs'
|
221 |
+
],
|
222 |
+
answer: 1,
|
223 |
+
hint: 'Pods come and go, names should not.'
|
224 |
+
},
|
225 |
+
{
|
226 |
+
question: 'How do CI/CD and Kubernetes usually integrate?',
|
227 |
+
choices: [
|
228 |
+
'CI builds/pushes image; CD applies Deployment for rolling update',
|
229 |
+
'Kubernetes builds the code directly',
|
230 |
+
'Docker Hub deploys to Pods automatically',
|
231 |
+
'kubectl compiles the source'
|
232 |
+
],
|
233 |
+
answer: 1,
|
234 |
+
hint: 'Pipeline builds→pushes, cluster rolls out.'
|
235 |
+
},
|
236 |
+
{
|
237 |
+
question: 'Which principle improves security and isolation of workloads?',
|
238 |
+
choices: [
|
239 |
+
'Running all as root',
|
240 |
+
'Namespaces, RBAC, and admission controls',
|
241 |
+
'Disabling probes',
|
242 |
+
'Editing containers in production'
|
243 |
+
],
|
244 |
+
answer: 2,
|
245 |
+
hint: 'Least privilege and boundaries.'
|
246 |
+
},
|
247 |
+
{
|
248 |
+
question: 'Why are Pods considered ephemeral?',
|
249 |
+
choices: [
|
250 |
+
'They never restart',
|
251 |
+
'They can be replaced/rescheduled anytime; controllers keep counts',
|
252 |
+
'They persist data by default',
|
253 |
+
'They run only on master nodes'
|
254 |
+
],
|
255 |
+
answer: 2,
|
256 |
+
hint: 'Treat Pods as cattle, not pets.'
|
257 |
+
}
|
258 |
+
];
|
259 |
+
|
260 |
+
// --- Game State ---
|
261 |
+
let currentPlayer, boardState, selectedCell, cellQuestions, mode;
|
262 |
+
|
263 |
+
const boardEl = document.getElementById('board');
|
264 |
+
const statusEl = document.getElementById('status');
|
265 |
+
const bannerEl = document.getElementById('banner');
|
266 |
+
const hintBtn = document.getElementById('hintBtn');
|
267 |
+
const clearBtn = document.getElementById('clearBtn');
|
268 |
+
const panelQuestion = document.getElementById('panelQuestion');
|
269 |
+
const panelChoices = document.getElementById('panelChoices');
|
270 |
+
const panelHint = document.getElementById('panelHint');
|
271 |
+
const restartBtn = document.getElementById('restartBtn');
|
272 |
+
const modeSel = document.getElementById('mode');
|
273 |
+
|
274 |
+
function initGame() {
|
275 |
+
mode = modeSel.value;
|
276 |
+
currentPlayer = 'X';
|
277 |
+
boardState = Array(9).fill('');
|
278 |
+
bannerEl.classList.add('hidden');
|
279 |
+
statusEl.innerText = '';
|
280 |
+
selectedCell = null;
|
281 |
+
|
282 |
+
// Pick 9 questions at random, then for each, shuffle choices and remap the correct answer index
|
283 |
+
const picked = randShuffle(QUESTION_BANK).slice(0, 9).map(q => {
|
284 |
+
const original = q.choices.map((c, i) => ({ text: c, idx: i + 1 }));
|
285 |
+
const shuffled = randShuffle(original);
|
286 |
+
const newChoices = shuffled.map(o => o.text);
|
287 |
+
const newAnswerIndex = shuffled.findIndex(o => o.idx === q.answer) + 1;
|
288 |
+
return {
|
289 |
+
question: q.question,
|
290 |
+
choices: newChoices,
|
291 |
+
answer: newAnswerIndex,
|
292 |
+
hint: q.hint || ''
|
293 |
+
};
|
294 |
+
});
|
295 |
+
cellQuestions = picked;
|
296 |
+
|
297 |
+
panelQuestion.innerText = 'Select a square to view the question';
|
298 |
+
panelChoices.innerHTML = '';
|
299 |
+
panelHint.classList.add('hidden');
|
300 |
+
panelHint.innerText = '';
|
301 |
+
|
302 |
+
renderBoard();
|
303 |
+
}
|
304 |
+
|
305 |
+
function renderBoard() {
|
306 |
+
boardEl.innerHTML = '';
|
307 |
+
boardState.forEach((mark, idx) => {
|
308 |
+
const btn = document.createElement('button');
|
309 |
+
let cls = 'bg-white h-24 w-24 md:h-28 md:w-28 flex items-center justify-center text-3xl font-extrabold rounded-xl shadow hover:bg-gray-100 transition';
|
310 |
+
if (mark === 'X') cls += ' text-emerald-700';
|
311 |
+
if (mark === 'O') cls += ' text-sky-700';
|
312 |
+
btn.className = cls;
|
313 |
+
btn.innerText = mark;
|
314 |
+
btn.disabled = mark !== '';
|
315 |
+
btn.addEventListener('click', () => openQuestion(idx));
|
316 |
+
boardEl.appendChild(btn);
|
317 |
+
});
|
318 |
+
statusEl.innerText = `Current: ${currentPlayer}`;
|
319 |
+
}
|
320 |
+
|
321 |
+
function openQuestion(idx) {
|
322 |
+
selectedCell = idx;
|
323 |
+
const q = cellQuestions[idx];
|
324 |
+
panelQuestion.innerText = q.question;
|
325 |
+
panelChoices.innerHTML = '';
|
326 |
+
panelHint.classList.add('hidden');
|
327 |
+
panelHint.innerText = q.hint || '';
|
328 |
+
q.choices.forEach((c, i) => {
|
329 |
+
const li = document.createElement('li');
|
330 |
+
const btn = document.createElement('button');
|
331 |
+
btn.innerText = c;
|
332 |
+
btn.className = 'w-full text-left px-4 py-2 bg-gray-100 rounded hover:bg-gray-200';
|
333 |
+
btn.addEventListener('click', () => handleAnswer(i + 1));
|
334 |
+
li.appendChild(btn);
|
335 |
+
panelChoices.appendChild(li);
|
336 |
+
});
|
337 |
+
}
|
338 |
+
|
339 |
+
function handleAnswer(choice) {
|
340 |
+
const q = cellQuestions[selectedCell];
|
341 |
+
if (choice === q.answer) {
|
342 |
+
boardState[selectedCell] = currentPlayer;
|
343 |
+
renderBoard();
|
344 |
+
if (checkWin(currentPlayer)) return endGame(`${currentPlayer} wins!`);
|
345 |
+
if (boardState.every(c => c)) return endGame('Stalemate!');
|
346 |
+
// Switch to next player (or AI turn)
|
347 |
+
currentPlayer = currentPlayer === 'X' ? 'O' : 'X';
|
348 |
+
statusEl.innerText = `Current: ${currentPlayer}`;
|
349 |
+
if (mode === 'solo' && currentPlayer === 'O') {
|
350 |
+
setTimeout(aiMove, 450);
|
351 |
+
}
|
352 |
+
} else {
|
353 |
+
alert('Incorrect! Turn missed.');
|
354 |
+
currentPlayer = currentPlayer === 'X' ? 'O' : 'X';
|
355 |
+
statusEl.innerText = `Current: ${currentPlayer}`;
|
356 |
+
if (mode === 'solo' && currentPlayer === 'O') {
|
357 |
+
setTimeout(aiMove, 450);
|
358 |
+
}
|
359 |
+
}
|
360 |
+
}
|
361 |
+
|
362 |
+
function checkWin(player) {
|
363 |
+
const wins = [
|
364 |
+
[0,1,2],[3,4,5],[6,7,8],
|
365 |
+
[0,3,6],[1,4,7],[2,5,8],
|
366 |
+
[0,4,8],[2,4,6]
|
367 |
+
];
|
368 |
+
return wins.some(combo => combo.every(i => boardState[i] === player));
|
369 |
+
}
|
370 |
+
|
371 |
+
function endGame(msg) {
|
372 |
+
bannerEl.innerText = `🎉 ${msg}`;
|
373 |
+
bannerEl.classList.remove('hidden');
|
374 |
+
document.querySelectorAll('#board button').forEach(b => b.disabled = true);
|
375 |
+
}
|
376 |
+
|
377 |
+
// Simple AI: pick the first available square and ask/answer its question randomly (50/50 correct).
|
378 |
+
// Keeps focus on learning while enabling solo play.
|
379 |
+
function aiMove() {
|
380 |
+
const open = boardState.map((v,i) => v === '' ? i : null).filter(v => v !== null);
|
381 |
+
if (open.length === 0) return;
|
382 |
+
const pick = open[Math.floor(Math.random() * open.length)];
|
383 |
+
// AI "answers" with a random chance to be correct; you can adjust difficulty here.
|
384 |
+
const q = cellQuestions[pick];
|
385 |
+
const aiCorrect = Math.random() < 0.55; // slightly better than random
|
386 |
+
if (aiCorrect) {
|
387 |
+
boardState[pick] = 'O';
|
388 |
+
renderBoard();
|
389 |
+
if (checkWin('O')) return endGame('O wins!');
|
390 |
+
if (boardState.every(c => c)) return endGame('Stalemate!');
|
391 |
+
currentPlayer = 'X';
|
392 |
+
statusEl.innerText = `Current: ${currentPlayer}`;
|
393 |
+
} else {
|
394 |
+
// AI misses turn
|
395 |
+
currentPlayer = 'X';
|
396 |
+
statusEl.innerText = `Current: ${currentPlayer}`;
|
397 |
+
}
|
398 |
+
}
|
399 |
+
|
400 |
+
hintBtn.addEventListener('click', () => panelHint.classList.toggle('hidden'));
|
401 |
+
clearBtn.addEventListener('click', () => {
|
402 |
+
panelQuestion.innerText = 'Select a square to view the question';
|
403 |
+
panelChoices.innerHTML = '';
|
404 |
+
panelHint.classList.add('hidden');
|
405 |
+
panelHint.innerText = '';
|
406 |
+
});
|
407 |
+
restartBtn.addEventListener('click', initGame);
|
408 |
+
modeSel.addEventListener('change', initGame);
|
409 |
+
|
410 |
+
// Start
|
411 |
+
initGame();
|
412 |
+
</script>
|
413 |
+
</body>
|
414 |
</html>
|