Docfile commited on
Commit
39851f5
·
verified ·
1 Parent(s): d4c0bb8

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +415 -164
templates/index.html CHANGED
@@ -3,192 +3,443 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Jeu d'Échecs</title>
7
- <!-- Tailwind CSS via CDN -->
8
- <script src="https://cdn.tailwindcss.com"></script>
 
 
 
 
 
9
  <style>
10
- /* Pour une meilleure interaction avec le SVG */
11
- .chess-board svg {
12
- cursor: default; /* Ou 'pointer' sur les pièces si on gère les clics SVG */
 
 
 
 
 
13
  }
14
- .square { /* Styles pour les cases si on n'utilise pas SVG pour le rendu cliquable */
15
- width: 40px; height: 40px;
16
- display: flex; align-items: center; justify-content: center;
17
- border: 1px solid #ccc;
 
 
 
18
  }
19
- .selected-square {
20
- background-color: rgba(255, 255, 0, 0.5) !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  }
22
  </style>
23
  </head>
24
- <body class="bg-gray-100 flex flex-col items-center justify-center min-h-screen p-4">
25
-
26
- <div class="bg-white p-6 rounded-lg shadow-xl w-full max-w-3xl">
27
- <h1 class="text-3xl font-bold text-center text-gray-700 mb-6">Jeu d'Échecs</h1>
28
-
29
- <div class="controls mb-4 flex flex-wrap gap-2 justify-center">
30
- <button id="newGameHuman" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
31
- Nouvelle Partie (Humain vs Humain)
32
- </button>
33
- <button id="newGameAIWhite" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
34
- Nouvelle Partie (Jouer Blancs vs IA)
35
- </button>
36
- <button id="newGameAIBlack" class="bg-gray-700 hover:bg-gray-900 text-white font-bold py-2 px-4 rounded">
37
- Nouvelle Partie (Jouer Noirs vs IA)
38
- </button>
39
- </div>
40
-
41
- <div class="game-area flex flex-col md:flex-row gap-4 items-start">
42
- <!-- Échiquier (rendu par chess.svg) -->
43
- <div id="boardDisplay" class="chess-board mx-auto md:mx-0 border-2 border-gray-500" style="width: 350px; height: 350px;">
44
- <!-- Le SVG de l'échiquier sera injecté ici -->
45
- {{ initial_board_svg|safe if initial_board_svg else "Chargement de l'échiquier..." }}
46
  </div>
47
-
48
- <!-- Informations et contrôles de la partie -->
49
- <div class="info-panel flex-grow p-4 bg-gray-50 rounded-md shadow">
50
- <h2 class="text-xl font-semibold mb-2">Informations</h2>
51
- <p id="turnInfo" class="mb-1">Tour: Chargement...</p>
52
- <p id="statusInfo" class="mb-3 font-medium">Statut: Chargement...</p>
53
-
54
- <h3 class="text-lg font-semibold mb-1">Jouer un coup (ex: e2e4):</h3>
55
- <div class="move-input flex gap-2 mb-3">
56
- <input type="text" id="moveInput" placeholder="e.g., e2e4"
57
- class="flex-grow p-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500">
58
- <button id="submitMove" class="bg-indigo-500 hover:bg-indigo-700 text-white font-bold py-2 px-3 rounded">
59
- Jouer
60
- </button>
61
  </div>
62
- <p class="text-xs text-gray-500 mb-3">
63
- Alternative: cliquez sur la case de départ puis la case d'arrivée sur un échiquier interactif (non implémenté ici, utilisez l'input).
64
- </p>
65
-
66
- <h3 class="text-lg font-semibold mb-1">Derniers coups:</h3>
67
- <p id="playerMoveInfo" class="text-sm"></p>
68
- <p id="aiMoveInfo" class="text-sm"></p>
 
 
 
 
 
 
 
 
 
 
 
69
  </div>
70
  </div>
71
  </div>
72
 
73
  <script>
74
- const boardDisplay = document.getElementById('boardDisplay');
75
- const turnInfo = document.getElementById('turnInfo');
76
- const statusInfo = document.getElementById('statusInfo');
77
- const moveInput = document.getElementById('moveInput');
78
- const playerMoveInfo = document.getElementById('playerMoveInfo');
79
- const aiMoveInfo = document.getElementById('aiMoveInfo');
80
-
81
- let currentFen = "{{ initial_fen }}"; // FEN initial passé par Flask
82
- let selectedSquare = null; // Pour une interaction de clic sur le plateau (non implémenté visuellement ici)
83
-
84
- async function updateBoard(data) {
85
- if (data.error) {
86
- statusInfo.textContent = `Erreur: ${data.error}`;
87
- if (data.board_svg) boardDisplay.innerHTML = data.board_svg; // Mettre à jour même en cas d'erreur de coup
88
- return;
89
- }
90
- currentFen = data.fen;
91
- boardDisplay.innerHTML = data.board_svg; // chess.svg fournit le plateau
92
- turnInfo.textContent = `Tour: ${data.turn}`;
93
- statusInfo.textContent = `Statut: ${data.status}`;
94
- moveInput.value = '';
95
-
96
- playerMoveInfo.textContent = data.player_move_san ? `Votre coup: ${data.player_move_san}` : "";
97
- aiMoveInfo.textContent = data.ai_move_san ? `Coup IA: ${data.ai_move_san}` : "";
98
-
99
- if (data.game_over) {
100
- moveInput.disabled = true;
101
- document.getElementById('submitMove').disabled = true;
102
- // On pourrait ajouter une alerte ou un modal
103
- setTimeout(() => alert(`Partie terminée ! ${data.status}`), 100);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  } else {
105
- moveInput.disabled = false;
106
- document.getElementById('submitMove').disabled = false;
107
  }
108
  }
109
-
110
- async function submitMove() {
111
- const move = moveInput.value.trim().toLowerCase();
112
- if (!move.match(/^[a-h][1-8][a-h][1-8]([qrbn])?$/)) { // Validation basique du format UCI
113
- statusInfo.textContent = "Format de coup invalide (ex: e2e4, e7e8q).";
114
- return;
115
- }
116
-
117
- playerMoveInfo.textContent = ""; // Clear previous move info
118
- aiMoveInfo.textContent = "";
119
-
120
- try {
121
- const response = await fetch('/move', {
122
- method: 'POST',
123
- headers: { 'Content-Type': 'application/json' },
124
- body: JSON.stringify({ move: move })
125
- });
126
- const data = await response.json();
127
- updateBoard(data);
128
- } catch (error) {
129
- console.error('Erreur lors de la soumission du coup:', error);
130
- statusInfo.textContent = 'Erreur de communication avec le serveur.';
131
- }
132
  }
133
-
134
- async function startNewGame(mode, playerPlaysWhite = true) {
135
- playerMoveInfo.textContent = "";
136
- aiMoveInfo.textContent = "";
137
- try {
138
- const response = await fetch('/new_game', {
139
- method: 'POST',
140
- headers: { 'Content-Type': 'application/json' },
141
- body: JSON.stringify({ mode: mode, player_color_white: playerPlaysWhite})
142
- });
143
- const data = await response.json();
144
- updateBoard(data);
145
- statusInfo.textContent = `Nouvelle partie commencée. ${mode === 'ai' ? (playerPlaysWhite ? 'Vous jouez les Blancs.' : 'L\'IA joue les Blancs.') : 'Humain vs Humain.'}`;
146
- } catch (error) {
147
- console.error('Erreur lors du démarrage de la nouvelle partie:', error);
148
- statusInfo.textContent = 'Erreur de communication avec le serveur.';
149
- }
150
  }
151
-
152
- document.getElementById('submitMove').addEventListener('click', submitMove);
153
- moveInput.addEventListener('keypress', function(event) {
154
- if (event.key === 'Enter') {
155
- submitMove();
156
- }
157
- });
158
-
159
- document.getElementById('newGameHuman').addEventListener('click', () => startNewGame('human'));
160
- document.getElementById('newGameAIWhite').addEventListener('click', () => startNewGame('ai', true));
161
- document.getElementById('newGameAIBlack').addEventListener('click', () => startNewGame('ai', false));
162
-
163
- // Initialiser l'état au chargement de la page (si une partie est en cours via session)
164
- async function initializeBoardState() {
165
- if (boardDisplay.innerHTML.includes("Chargement")) { // Si le SVG n'a pas été injecté par le serveur
166
- try {
167
- const response = await fetch('/get_board_state');
168
- const data = await response.json();
169
- updateBoard(data);
170
- } catch (error) {
171
- console.error('Erreur de récupération de l\'état initial:', error);
172
- statusInfo.textContent = 'Erreur de chargement de la partie.';
173
  }
174
- } else { // Le SVG est déjà là, il faut juste mettre à jour les infos de statut
175
- try {
176
- const response = await fetch('/get_board_state'); // Récupérer le statut actuel
177
- const data = await response.json();
178
- turnInfo.textContent = `Tour: ${data.turn}`;
179
- statusInfo.textContent = `Statut: ${data.status}`;
180
- if (data.game_over) {
181
- moveInput.disabled = true;
182
- document.getElementById('submitMove').disabled = true;
183
- }
184
- } catch (error) {
185
- console.error('Erreur de récupération de l\'état initial (infos):', error);
186
  }
187
  }
188
  }
189
-
190
- window.onload = initializeBoardState;
191
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  </script>
193
  </body>
194
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Chess vs Stockfish</title>
7
+
8
+ <!-- Chess.js et Chessboard.js -->
9
+ <link rel="stylesheet" href="https://unpkg.com/@chrisoakman/[email protected]/dist/chessboard-1.0.0.min.css">
10
+ <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
11
+ <script src="https://unpkg.com/[email protected]/chess.min.js"></script>
12
+ <script src="https://unpkg.com/@chrisoakman/[email protected]/dist/chessboard-1.0.0.min.js"></script>
13
+
14
  <style>
15
+ body {
16
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
17
+ max-width: 1200px;
18
+ margin: 0 auto;
19
+ padding: 20px;
20
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
21
+ min-height: 100vh;
22
+ box-sizing: border-box;
23
  }
24
+
25
+ .container {
26
+ background: rgba(255, 255, 255, 0.95);
27
+ border-radius: 20px;
28
+ padding: 30px;
29
+ box-shadow: 0 20px 40px rgba(0,0,0,0.1);
30
+ backdrop-filter: blur(10px);
31
  }
32
+
33
+ h1 {
34
+ text-align: center;
35
+ color: #333;
36
+ margin-bottom: 30px;
37
+ font-size: 2.5em;
38
+ text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
39
+ }
40
+
41
+ .game-container {
42
+ display: flex;
43
+ gap: 30px;
44
+ justify-content: center;
45
+ align-items: flex-start;
46
+ flex-wrap: wrap;
47
+ }
48
+
49
+ .board-container {
50
+ flex-shrink: 0;
51
+ }
52
+
53
+ #myBoard {
54
+ border: 4px solid #8B4513;
55
+ border-radius: 10px;
56
+ box-shadow: 0 10px 25px rgba(0,0,0,0.3);
57
+ }
58
+
59
+ .info-panel {
60
+ background: #f8f9fa;
61
+ border-radius: 15px;
62
+ padding: 25px;
63
+ min-width: 300px;
64
+ box-shadow: 0 5px 15px rgba(0,0,0,0.1);
65
+ }
66
+
67
+ .status {
68
+ font-size: 1.2em;
69
+ font-weight: bold;
70
+ margin-bottom: 15px;
71
+ padding: 15px;
72
+ border-radius: 10px;
73
+ text-align: center;
74
+ }
75
+
76
+ .status.playing {
77
+ background: linear-gradient(45deg, #4CAF50, #45a049);
78
+ color: white;
79
+ }
80
+
81
+ .status.game-over {
82
+ background: linear-gradient(45deg, #f44336, #d32f2f);
83
+ color: white;
84
+ }
85
+
86
+ .controls {
87
+ display: flex;
88
+ flex-direction: column;
89
+ gap: 15px;
90
+ margin-top: 20px;
91
+ }
92
+
93
+ button {
94
+ background: linear-gradient(45deg, #667eea, #764ba2);
95
+ color: white;
96
+ border: none;
97
+ padding: 12px 20px;
98
+ border-radius: 8px;
99
+ cursor: pointer;
100
+ font-size: 1em;
101
+ font-weight: bold;
102
+ transition: all 0.3s ease;
103
+ box-shadow: 0 4px 10px rgba(0,0,0,0.2);
104
+ }
105
+
106
+ button:hover:not(:disabled) {
107
+ transform: translateY(-2px);
108
+ box-shadow: 0 6px 15px rgba(0,0,0,0.3);
109
+ }
110
+
111
+ button:disabled {
112
+ background: #ccc;
113
+ cursor: not-allowed;
114
+ transform: none;
115
+ box-shadow: none;
116
+ }
117
+
118
+ .evaluation {
119
+ background: #e3f2fd;
120
+ padding: 15px;
121
+ border-radius: 10px;
122
+ margin: 15px 0;
123
+ border-left: 4px solid #2196F3;
124
+ }
125
+
126
+ .evaluation h3 {
127
+ margin: 0 0 10px 0;
128
+ color: #1976D2;
129
+ }
130
+
131
+ .move-history {
132
+ background: #fff3e0;
133
+ padding: 15px;
134
+ border-radius: 10px;
135
+ margin: 15px 0;
136
+ border-left: 4px solid #FF9800;
137
+ max-height: 200px;
138
+ overflow-y: auto;
139
+ }
140
+
141
+ .move-history h3 {
142
+ margin: 0 0 10px 0;
143
+ color: #F57C00;
144
+ }
145
+
146
+ .loading {
147
+ display: none;
148
+ text-align: center;
149
+ color: #666;
150
+ font-style: italic;
151
+ margin: 10px 0;
152
+ }
153
+
154
+ .loading.show {
155
+ display: block;
156
+ }
157
+
158
+ .error {
159
+ background: #ffebee;
160
+ color: #c62828;
161
+ padding: 10px;
162
+ border-radius: 5px;
163
+ margin: 10px 0;
164
+ border-left: 4px solid #f44336;
165
+ }
166
+
167
+ @media (max-width: 768px) {
168
+ .game-container {
169
+ flex-direction: column;
170
+ align-items: center;
171
+ }
172
+
173
+ .info-panel {
174
+ min-width: auto;
175
+ width: 100%;
176
+ max-width: 500px;
177
+ }
178
  }
179
  </style>
180
  </head>
181
+ <body>
182
+ <div class="container">
183
+ <h1>🏁 Chess vs Stockfish</h1>
184
+
185
+ <div class="game-container">
186
+ <div class="board-container">
187
+ <div id="myBoard" style="width: 400px"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  </div>
189
+
190
+ <div class="info-panel">
191
+ <div id="status" class="status playing">À vous de jouer !</div>
192
+
193
+ <div class="loading" id="loading">
194
+ Stockfish réfléchit...
 
 
 
 
 
 
 
 
195
  </div>
196
+
197
+ <div class="evaluation">
198
+ <h3>📊 Évaluation</h3>
199
+ <div id="evaluation">Position de départ</div>
200
+ </div>
201
+
202
+ <div class="move-history">
203
+ <h3>📝 Derniers coups</h3>
204
+ <div id="moveHistory">Nouvelle partie</div>
205
+ </div>
206
+
207
+ <div class="controls">
208
+ <button id="newGameBtn">🔄 Nouvelle partie</button>
209
+ <button id="analyzeBtn">🔍 Analyser position</button>
210
+ <button id="flipBtn">🔄 Retourner échiquier</button>
211
+ </div>
212
+
213
+ <div id="error" class="error" style="display: none;"></div>
214
  </div>
215
  </div>
216
  </div>
217
 
218
  <script>
219
+ let game = new Chess();
220
+ let board = null;
221
+ let gameOver = false;
222
+ let moveHistory = [];
223
+
224
+ // Configuration de l'échiquier
225
+ const config = {
226
+ draggable: true,
227
+ position: 'start',
228
+ onDragStart: onDragStart,
229
+ onDrop: onDrop,
230
+ onSnapEnd: onSnapEnd
231
+ };
232
+
233
+ board = Chessboard('myBoard', config);
234
+
235
+ function onDragStart(source, piece, position, orientation) {
236
+ // Ne pas permettre de déplacer les pièces si c'est terminé
237
+ if (gameOver) return false;
238
+
239
+ // Ne permettre de déplacer que les pièces blanches (joueur)
240
+ if (piece.search(/^b/) !== -1) return false;
241
+
242
+ // Ne pas permettre de déplacer si ce n'est pas le tour des blancs
243
+ if (game.turn() === 'b') return false;
244
+ }
245
+
246
+ function onDrop(source, target) {
247
+ // Voir si le coup est légal
248
+ const move = game.move({
249
+ from: source,
250
+ to: target,
251
+ promotion: 'q' // Toujours promouvoir en dame pour simplifier
252
+ });
253
+
254
+ // Coup illégal
255
+ if (move === null) return 'snapback';
256
+
257
+ // Coup légal - envoyer au serveur
258
+ makeMove(move.san);
259
+ }
260
+
261
+ function onSnapEnd() {
262
+ board.position(game.fen());
263
+ }
264
+
265
+ function makeMove(userMove) {
266
+ if (gameOver) return;
267
+
268
+ showLoading(true);
269
+ hideError();
270
+
271
+ fetch('/api/move', {
272
+ method: 'POST',
273
+ headers: {
274
+ 'Content-Type': 'application/json',
275
+ },
276
+ body: JSON.stringify({
277
+ fen: game.fen(),
278
+ move: userMove
279
+ })
280
+ })
281
+ .then(response => response.json())
282
+ .then(data => {
283
+ showLoading(false);
284
+
285
+ if (data.error) {
286
+ showError(data.error);
287
+ // Rétablir la position précédente
288
+ game.undo();
289
+ board.position(game.fen());
290
+ return;
291
+ }
292
+
293
+ // Mettre à jour le jeu avec la nouvelle position
294
+ game.load(data.fen);
295
+ board.position(game.fen());
296
+
297
+ // Ajouter les coups à l'historique
298
+ if (data.stockfish_move) {
299
+ addToMoveHistory(userMove, data.stockfish_move);
300
+ } else {
301
+ addToMoveHistory(userMove, null);
302
+ }
303
+
304
+ // Mettre à jour l'évaluation
305
+ updateEvaluation(data.evaluation);
306
+
307
+ // Vérifier si la partie est terminée
308
+ if (data.game_over) {
309
+ gameOver = true;
310
+ updateStatus(data.result || 'Partie terminée', true);
311
+ } else {
312
+ updateStatus('À vous de jouer !', false);
313
+ }
314
+ })
315
+ .catch(error => {
316
+ showLoading(false);
317
+ showError('Erreur de communication: ' + error.message);
318
+ // Rétablir la position précédente
319
+ game.undo();
320
+ board.position(game.fen());
321
+ });
322
+ }
323
+
324
+ function showLoading(show) {
325
+ const loading = document.getElementById('loading');
326
+ if (show) {
327
+ loading.classList.add('show');
328
  } else {
329
+ loading.classList.remove('show');
 
330
  }
331
  }
332
+
333
+ function showError(message) {
334
+ const errorDiv = document.getElementById('error');
335
+ errorDiv.textContent = message;
336
+ errorDiv.style.display = 'block';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  }
338
+
339
+ function hideError() {
340
+ document.getElementById('error').style.display = 'none';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
  }
342
+
343
+ function updateStatus(message, isGameOver = false) {
344
+ const statusDiv = document.getElementById('status');
345
+ statusDiv.textContent = message;
346
+ statusDiv.className = isGameOver ? 'status game-over' : 'status playing';
347
+ }
348
+
349
+ function updateEvaluation(evaluation) {
350
+ const evalDiv = document.getElementById('evaluation');
351
+
352
+ if (evaluation.type === 'cp') {
353
+ const centipawns = evaluation.value;
354
+ const pawns = (centipawns / 100).toFixed(2);
355
+ if (pawns > 0) {
356
+ evalDiv.textContent = `Blancs +${pawns}`;
357
+ } else if (pawns < 0) {
358
+ evalDiv.textContent = `Noirs +${Math.abs(pawns)}`;
359
+ } else {
360
+ evalDiv.textContent = 'Position équilibrée';
 
 
 
361
  }
362
+ } else if (evaluation.type === 'mate') {
363
+ const mateIn = evaluation.value;
364
+ if (mateIn > 0) {
365
+ evalDiv.textContent = `Mat en ${mateIn} pour les blancs`;
366
+ } else if (mateIn < 0) {
367
+ evalDiv.textContent = `Mat en ${Math.abs(mateIn)} pour les noirs`;
368
+ } else {
369
+ evalDiv.textContent = 'Mat ou Pat';
 
 
 
 
370
  }
371
  }
372
  }
373
+
374
+ function addToMoveHistory(userMove, stockfishMove) {
375
+ moveHistory.push({user: userMove, stockfish: stockfishMove});
376
+
377
+ const historyDiv = document.getElementById('moveHistory');
378
+ const lastMoves = moveHistory.slice(-5); // Garder les 5 derniers coups
379
+
380
+ let historyText = '';
381
+ lastMoves.forEach((moves, index) => {
382
+ const moveNum = moveHistory.length - lastMoves.length + index + 1;
383
+ historyText += `${moveNum}. ${moves.user}`;
384
+ if (moves.stockfish) {
385
+ historyText += ` ${moves.stockfish}`;
386
+ }
387
+ historyText += '\n';
388
+ });
389
+
390
+ historyDiv.textContent = historyText || 'Aucun coup joué';
391
+ }
392
+
393
+ // Gestionnaires d'événements pour les boutons
394
+ document.getElementById('newGameBtn').addEventListener('click', function() {
395
+ fetch('/api/new_game', {method: 'POST'})
396
+ .then(response => response.json())
397
+ .then(data => {
398
+ game = new Chess();
399
+ board.start();
400
+ gameOver = false;
401
+ moveHistory = [];
402
+ updateStatus('À vous de jouer !', false);
403
+ updateEvaluation({type: 'cp', value: 0});
404
+ document.getElementById('moveHistory').textContent = 'Nouvelle partie';
405
+ hideError();
406
+ })
407
+ .catch(error => {
408
+ showError('Erreur lors du démarrage: ' + error.message);
409
+ });
410
+ });
411
+
412
+ document.getElementById('analyzeBtn').addEventListener('click', function() {
413
+ fetch('/api/analyze', {
414
+ method: 'POST',
415
+ headers: {
416
+ 'Content-Type': 'application/json',
417
+ },
418
+ body: JSON.stringify({fen: game.fen()})
419
+ })
420
+ .then(response => response.json())
421
+ .then(data => {
422
+ if (data.error) {
423
+ showError(data.error);
424
+ return;
425
+ }
426
+
427
+ updateEvaluation(data.evaluation);
428
+ if (data.best_move) {
429
+ showError(`Meilleur coup suggéré: ${data.best_move}`);
430
+ }
431
+ })
432
+ .catch(error => {
433
+ showError('Erreur d\'analyse: ' + error.message);
434
+ });
435
+ });
436
+
437
+ document.getElementById('flipBtn').addEventListener('click', function() {
438
+ board.flip();
439
+ });
440
+
441
+ // Initialiser l'évaluation de départ
442
+ updateEvaluation({type: 'cp', value: 0});
443
  </script>
444
  </body>
445
  </html>