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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Gemifish Chess</title>
|
7 |
+
<link rel="stylesheet" href="https://unpkg.com/@chrisoakman/[email protected]/dist/chessboard-1.0.0.min.css">
|
8 |
+
<link href="https://fonts.googleapis.com/css?family=Inter:400,600&display=swap" rel="stylesheet">
|
9 |
+
<style>
|
10 |
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
11 |
+
html, body { height: 100%; overflow: hidden; }
|
12 |
+
body {
|
13 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', Arial, sans-serif;
|
14 |
+
background-color: #2c2c2c; color: #ffffff; display: flex; flex-direction: column;
|
15 |
+
}
|
16 |
+
.container { display: flex; flex: 1; min-height: 0; }
|
17 |
+
.left-panel {
|
18 |
+
flex: 0 0 600px; background-color: #2c2c2c; display: flex; flex-direction: column;
|
19 |
+
border-right: 1px solid #404040; min-height: 0; position: relative;
|
20 |
+
}
|
21 |
+
.header {
|
22 |
+
display: flex; justify-content: space-between; align-items: center; padding: 12px 16px;
|
23 |
+
background-color: #2c2c2c; border-bottom: 1px solid #404040; min-height: 56px; position: relative; z-index: 2;
|
24 |
+
}
|
25 |
+
.player-info { display: flex; align-items: center; gap: 12px; }
|
26 |
+
.avatar {
|
27 |
+
width: 32px; height: 32px; border-radius: 50%;
|
28 |
+
background: linear-gradient(135deg, #ff6b35, #f7931e); display: flex;
|
29 |
+
align-items: center; justify-content: center; flex-shrink: 0;
|
30 |
+
}
|
31 |
+
.avatar svg { width: 18px; height: 18px; fill: white; }
|
32 |
+
.player-name { font-size: 16px; font-weight: 500; }
|
33 |
+
.rating { color: #888; font-size: 14px; margin-left: 4px; }
|
34 |
+
.header-actions { position: relative; display: flex; align-items: center; gap: 12px; }
|
35 |
+
.settings-icon, .close-btn {
|
36 |
+
width: 32px; height: 32px; color: #888; cursor: pointer; display: flex;
|
37 |
+
align-items: center; justify-content: center; border-radius: 4px; flex-shrink: 0;
|
38 |
+
transition: color 0.2s, background-color 0.2s;
|
39 |
+
}
|
40 |
+
.settings-icon:hover, .close-btn:hover { color: #fff; background-color: #404040; }
|
41 |
+
.settings-icon.active-ai { color: #4a90e2; }
|
42 |
+
.settings-icon.active-ai:hover { color: #6aaeff; }
|
43 |
+
.settings-icon svg, .close-btn svg { width: 18px; height: 18px; }
|
44 |
+
|
45 |
+
/* Perbaikan utama untuk container board catur */
|
46 |
+
.chess-board-container {
|
47 |
+
flex: 1;
|
48 |
+
display: flex;
|
49 |
+
align-items: center;
|
50 |
+
justify-content: center;
|
51 |
+
background-color: #353535;
|
52 |
+
margin: 8px; /* Kurangi margin dari 16px menjadi 8px */
|
53 |
+
border-radius: 8px;
|
54 |
+
border: 1px solid #404040;
|
55 |
+
min-height: 0;
|
56 |
+
overflow: hidden;
|
57 |
+
padding: 8px; /* Kurangi padding dari 20px menjadi 8px */
|
58 |
+
position: relative;
|
59 |
+
z-index: 0;
|
60 |
+
contain: content;
|
61 |
+
}
|
62 |
+
|
63 |
+
#game-board {
|
64 |
+
width: 100%;
|
65 |
+
height: 100%;
|
66 |
+
aspect-ratio: 1/1; /* Pertahankan rasio aspek */
|
67 |
+
}
|
68 |
+
|
69 |
+
.bottom-section {
|
70 |
+
padding: 16px; border-top: 1px solid #404040; display: flex;
|
71 |
+
align-items: center; gap: 12px; min-height: 56px; position: relative; z-index: 2;
|
72 |
+
}
|
73 |
+
.guest-avatar {
|
74 |
+
width: 24px; height: 24px; background-color: #666; border-radius: 50%;
|
75 |
+
display: flex; align-items: center; justify-content: center; color: #ccc; flex-shrink: 0;
|
76 |
+
}
|
77 |
+
.guest-avatar svg { width: 14px; height: 14px; fill: currentColor; }
|
78 |
+
.guest-label { color: #ccc; font-size: 14px; }
|
79 |
+
.action-icons { margin-left: auto; display: flex; gap: 8px; }
|
80 |
+
.action-icon {
|
81 |
+
width: 28px; height: 28px; color: #888; cursor: pointer; display: flex;
|
82 |
+
align-items: center; justify-content: center; border-radius: 4px; flex-shrink: 0;
|
83 |
+
}
|
84 |
+
.action-icon:hover { color: #fff; background-color: #404040; }
|
85 |
+
.action-icon svg { width: 16px; height: 16px; fill: currentColor; }
|
86 |
+
.right-panel { flex: 1; background-color: #1e1e1e; display: flex; flex-direction: column; min-height: 0; }
|
87 |
+
.right-header {
|
88 |
+
padding: 12px 16px; border-bottom: 1px solid #404040; display: flex;
|
89 |
+
align-items: center; justify-content: space-between; min-height: 56px; flex-shrink: 0;
|
90 |
+
}
|
91 |
+
.play-bots { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 500; }
|
92 |
+
.bot-icon {
|
93 |
+
width: 24px; height: 24px; background: linear-gradient(135deg, #4a90e2, #357abd);
|
94 |
+
border-radius: 4px; display: flex; align-items: center; justify-content: center;
|
95 |
+
color: white; flex-shrink: 0;
|
96 |
+
}
|
97 |
+
.bot-icon svg { width: 14px; height: 14px; fill: currentColor; }
|
98 |
+
.moves-section { flex: 1; padding: 16px; overflow-y: auto; min-height: 0; }
|
99 |
+
.moves-header { color: #888; font-size: 14px; margin-bottom: 16px; min-height: 20px; }
|
100 |
+
.moves-list { display: flex; flex-direction: column; gap: 8px; }
|
101 |
+
.move-row { display: flex; align-items: center; gap: 16px; font-size: 14px; }
|
102 |
+
.move-number { color: #888; width: 20px; flex-shrink: 0; text-align: right; }
|
103 |
+
.move { min-width: 60px; color: #fff; padding: 2px 4px; }
|
104 |
+
.move.highlighted-move { background-color: #404040; border-radius: 3px; }
|
105 |
+
|
106 |
+
.ai-reasoning-section {
|
107 |
+
padding: 12px 16px; border-top: 1px solid #404040; background-color: #252525; flex-shrink: 0;
|
108 |
+
}
|
109 |
+
.ai-reasoning-header {
|
110 |
+
font-size: 12px; font-weight: 600; color: #aaa; letter-spacing: 0.5px;
|
111 |
+
text-transform: uppercase; margin-bottom: 8px; display: flex; align-items: center; gap: 6px;
|
112 |
+
}
|
113 |
+
#ai-reasoning-text { font-size: 14px; color: #ddd; min-height: 40px; font-style: italic; }
|
114 |
+
|
115 |
+
.controls {
|
116 |
+
padding: 16px; border-top: 1px solid #404040; display: flex;
|
117 |
+
justify-content: space-between; align-items: center; gap: 12px; flex-shrink: 0;
|
118 |
+
}
|
119 |
+
.nav-controls { display: flex; gap: 8px; }
|
120 |
+
.control-btn {
|
121 |
+
width: 36px; height: 36px; background-color: #404040; border: none; border-radius: 4px;
|
122 |
+
color: #ccc; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
|
123 |
+
}
|
124 |
+
.control-btn:disabled { color: #666; cursor: not-allowed; }
|
125 |
+
.control-btn:not(:disabled):hover { background-color: #505050; color: #fff; }
|
126 |
+
.control-btn svg { width: 18px; height: 18px; fill: currentColor; }
|
127 |
+
.resign-btn {
|
128 |
+
background-color: #d32f2f; color: white; border: none; padding: 8px 16px; border-radius: 4px;
|
129 |
+
cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 6px; flex-shrink: 0;
|
130 |
+
}
|
131 |
+
.resign-btn:hover { background-color: #b71c1c; }
|
132 |
+
.resign-btn:disabled { background-color: #5a2e2e; color: #aaa; cursor: not-allowed; }
|
133 |
+
.resign-btn svg { width: 16px; height: 16px; fill: currentColor; }
|
134 |
+
|
135 |
+
.modal-overlay {
|
136 |
+
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
|
137 |
+
background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(4px); display: none;
|
138 |
+
align-items: center; justify-content: center; z-index: 1000;
|
139 |
+
}
|
140 |
+
.modal {
|
141 |
+
width: min(480px, 90vw); background: #2c2c2c; border-radius: 12px; border: 1px solid #404040;
|
142 |
+
box-shadow: 0 8px 32px rgba(0,0,0,0.5); color: #fff; padding-bottom: 24px; position: relative;
|
143 |
+
}
|
144 |
+
.modal-header {
|
145 |
+
padding: 16px 24px; font-size: 20px; font-weight: 600; border-bottom: 1px solid #404040;
|
146 |
+
display: flex; justify-content: space-between; align-items: center;
|
147 |
+
}
|
148 |
+
.modal-close-btn {
|
149 |
+
background: none; border: none; cursor: pointer; padding: 0; margin: 0; width: 28px;
|
150 |
+
height: 28px; display: flex; align-items: center; justify-content: center;
|
151 |
+
}
|
152 |
+
.modal-content { padding: 0 24px; }
|
153 |
+
.tabs { display: flex; border-bottom: 1.5px solid #404040; margin-bottom: 0; margin-top: 8px; }
|
154 |
+
.tab {
|
155 |
+
flex: 1; text-align: center; padding: 12px 0 8px 0; font-size: 16px; font-weight: 500;
|
156 |
+
color: #fff; cursor: pointer; border: none; background: none; outline: none; border-bottom: 2.5px solid #fff;
|
157 |
+
}
|
158 |
+
.section-label {
|
159 |
+
margin-top: 20px; margin-bottom: 8px; font-size: 14px; font-weight: 600;
|
160 |
+
color: #aaa; letter-spacing: 0.5px;
|
161 |
+
}
|
162 |
+
.input-row { display: flex; align-items: center; position: relative; }
|
163 |
+
.input-box {
|
164 |
+
background: #404040; border: 1px solid #555; border-radius: 6px; color: #fff;
|
165 |
+
font-size: 14px; padding: 10px 44px 10px 12px; width: 100%;
|
166 |
+
font-family: 'Inter', 'Segoe UI', sans-serif; resize: none;
|
167 |
+
}
|
168 |
+
.pgn-area { min-height: 140px; max-height: 160px; }
|
169 |
+
.copy-btn {
|
170 |
+
position: absolute; right: 4px; top: 6px; background: none; border: none;
|
171 |
+
cursor: pointer; padding: 4px; display: flex; align-items: center; justify-content: center;
|
172 |
+
color: #aaa; border-radius: 4px;
|
173 |
+
}
|
174 |
+
.copy-btn:hover { background-color: #555; color: #fff; }
|
175 |
+
.pgn-area + .copy-btn { top: 8px; right: 8px; }
|
176 |
+
.modal-action-btn {
|
177 |
+
width: 100%; color: #fff; font-size: 18px; font-weight: 600; border: none;
|
178 |
+
border-radius: 8px; padding: 12px 0; margin-top: 18px; cursor: pointer;
|
179 |
+
display: flex; align-items: center; justify-content: center; transition: background 0.2s;
|
180 |
+
}
|
181 |
+
.modal-action-btn.download{ background: #4a90e2; }
|
182 |
+
.modal-action-btn.download:hover { background: #5a9ee6; }
|
183 |
+
.modal-action-btn.save-ai { background: #3f9142; }
|
184 |
+
.modal-action-btn.save-ai:hover { background: #4caf50; }
|
185 |
+
.modal-action-btn svg { margin-right: 10px; }
|
186 |
+
|
187 |
+
#settings-popover {
|
188 |
+
display: none; position: absolute; top: 40px; right: 0; width: 220px; background: #2c2c2c;
|
189 |
+
border: 1px solid #404040; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.4);
|
190 |
+
z-index: 1100; padding: 8px;
|
191 |
+
}
|
192 |
+
.settings-section-header {
|
193 |
+
font-size: 12px; color: #888; text-transform: uppercase; padding: 8px; font-weight: 600;
|
194 |
+
}
|
195 |
+
.theme-btn {
|
196 |
+
width: 100%; background: none; border: none; color: #ddd; padding: 8px; text-align: left;
|
197 |
+
display: flex; align-items: center; gap: 12px; border-radius: 4px; cursor: pointer;
|
198 |
+
}
|
199 |
+
.theme-btn:hover { background-color: #404040; }
|
200 |
+
.theme-btn.active { color: #fff; background-color: #4a90e2; }
|
201 |
+
.theme-swatch {
|
202 |
+
width: 40px; height: 20px; border-radius: 4px; display: flex;
|
203 |
+
overflow: hidden; border: 1px solid #555;
|
204 |
+
}
|
205 |
+
.theme-swatch-light { width: 50%; } .theme-swatch-dark { width: 50%; }
|
206 |
+
|
207 |
+
.notification {
|
208 |
+
position: fixed; top: -100px; left: 50%; transform: translateX(-50%);
|
209 |
+
background-color: #ff6b35; color: white; padding: 12px 24px; border-radius: 8px;
|
210 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.3); z-index: 2000; font-size: 15px; font-weight: 500;
|
211 |
+
transition: top 0.5s ease-in-out; display: flex; align-items: center; gap: 10px;
|
212 |
+
}
|
213 |
+
.notification.show { top: 20px; }
|
214 |
+
|
215 |
+
/* Perbaikan responsif untuk mobile */
|
216 |
+
@media (max-width: 768px) {
|
217 |
+
.container { flex-direction: column; }
|
218 |
+
.left-panel {
|
219 |
+
flex: 1;
|
220 |
+
width: 100%;
|
221 |
+
border-right: none;
|
222 |
+
border-bottom: 1px solid #404040;
|
223 |
+
min-height: auto;
|
224 |
+
}
|
225 |
+
.right-panel { flex: 1; }
|
226 |
+
.chess-board-container {
|
227 |
+
margin: 4px; /* Kurangi margin di mobile */
|
228 |
+
padding: 4px; /* Kurangi padding di mobile */
|
229 |
+
height: auto;
|
230 |
+
overflow: hidden;
|
231 |
+
}
|
232 |
+
.header, .bottom-section, .right-header, .controls { padding: 8px 12px; min-height: 48px; }
|
233 |
+
.player-info { gap: 8px; }
|
234 |
+
.avatar { width: 28px; height: 28px; }
|
235 |
+
.player-name { font-size: 14px; }
|
236 |
+
.rating { font-size: 12px; }
|
237 |
+
#game-board {
|
238 |
+
width: 100%;
|
239 |
+
height: 100%;
|
240 |
+
max-width: 100%;
|
241 |
+
max-height: none;
|
242 |
+
aspect-ratio: 1/1;
|
243 |
+
}
|
244 |
+
}
|
245 |
+
@media (max-width: 480px) {
|
246 |
+
.nav-controls { gap: 4px; }
|
247 |
+
.control-btn { width: 32px; height: 32px; }
|
248 |
+
.resign-btn { padding: 6px 12px; font-size: 12px; }
|
249 |
+
.chess-board-container {
|
250 |
+
margin: 2px; /* Kurangi margin lebih lanjut di layar kecil */
|
251 |
+
padding: 2px; /* Kurangi padding lebih lanjut di layar kecil */
|
252 |
+
}
|
253 |
+
}
|
254 |
+
|
255 |
+
/* API key input */
|
256 |
+
#api-key-input { width: 100%; padding: 10px; background: #404040; border: 1px solid #555; color: #fff; }
|
257 |
+
.credit { font-size: 12px; color: #888; margin-left: auto; }
|
258 |
+
.credit a { color: #4a90e2; text-decoration: none; }
|
259 |
+
.credit a:hover { text-decoration: underline; }
|
260 |
+
</style>
|
261 |
+
</head>
|
262 |
+
<body>
|
263 |
+
<div id="ai-notification" class="notification">
|
264 |
+
<svg fill="currentColor" width="20" height="20" viewBox="0 0 24 24"><path d="M13,14H11V10H13M13,18H11V16H13M1,21H23L12,2L1,21Z"></path></svg>
|
265 |
+
<span id="ai-notification-text"></span>
|
266 |
+
</div>
|
267 |
+
|
268 |
+
<div class="container">
|
269 |
+
<div class="left-panel">
|
270 |
+
<div class="header">
|
271 |
+
<div class="player-info"><div class="avatar"><svg viewBox="0 0 24 24"><path d="M12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22C6.47,22 2,17.5 2,12A10,10 0 0,1 12,2M15.5,8C16.3,8 17,8.7 17,9.5C17,10.3 16.3,11 15.5,11C14.7,11 14,10.3 14,9.5C14,8.7 14.7,8 15.5,8M10,9.5C10,10.3 9.3,11 8.5,11C7.7,11 7,10.3 7,9.5C7,8.7 7.7,8 8.5,8C9.3,8 10,8.7 10,9.5M12,17.23C10.25,17.23 8.71,16.5 7.81,15.42L9.07,14.34C9.69,15.12 10.8,15.23 12,15.23C13.2,15.23 14.31,15.12 14.93,14.34L16.19,15.42C15.29,16.5 13.75,17.23 12,17.23Z"/></svg></div><div><span class="player-name">Gemifish</span><span class="rating">(2000+)</span></div></div>
|
272 |
+
<div class="header-actions">
|
273 |
+
<div id="ai-btn" class="settings-icon" title="AI Personality">
|
274 |
+
<svg fill="currentColor" viewBox="0 0 24 24"><path d="M12,2A2,2 0 0,1 14,4C14,4.74 13.6,5.39 13,5.73V7H14A7,7 0 0,1 21,14H22A1,1 0 0,1 23,15V18A1,1 0 0,1 22,19H21V20A2,2 0 0,1 19,22H5A2,2 0 0,1 3,20V19H2A1,1 0 0,1 1,18V15A1,1 0 0,1 2,14H3A7,7 0 0,1 10,7H11V5.73C10.4,5.39 10,4.74 10,4A2,2 0 0,1 12,2M7.5,13A2.5,2.5 0 0,0 5,15.5A2.5,2.5 0 0,0 7.5,18A2.5,2.5 0 0,0 10,15.5A2.5,2.5 0 0,0 7.5,13M16.5,13A2.5,2.5 0 0,0 14,15.5A2.5,2.5 0 0,0 16.5,18A2.5,2.5 0 0,0 19,15.5A2.5,2.5 0 0,0 16.5,13Z"/></svg>
|
275 |
+
</div>
|
276 |
+
<div id="settings-btn" class="settings-icon" title="Settings">
|
277 |
+
<svg fill="currentColor" viewBox="0 0 24 24"><path d="M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.22,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.22,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.68 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z"/></svg>
|
278 |
+
</div>
|
279 |
+
<div id="settings-popover">
|
280 |
+
<div class="settings-section-header">Board Theme</div>
|
281 |
+
<button id="theme-brown-btn" class="theme-btn"><div class="theme-swatch"><div class="theme-swatch-light" style="background-color: #f0d9b5;"></div><div class="theme-swatch-dark" style="background-color: #b58863;"></div></div>Brown</button>
|
282 |
+
<button id="theme-blue-btn" class="theme-btn"><div class="theme-swatch"><div class="theme-swatch-light" style="background-color: #D8DEE9;"></div><div class="theme-swatch-dark" style="background-color: #819AAE;"></div></div>Blue</button>
|
283 |
+
</div>
|
284 |
+
</div>
|
285 |
+
</div>
|
286 |
+
<div class="chess-board-container"><div id="game-board"></div></div>
|
287 |
+
<div class="bottom-section">
|
288 |
+
<div class="guest-avatar"><svg viewBox="0 0 24 24"><path d="M12,4A4,4 0 0,1 16,8A4,4 0 0,1 12,12A4,4 0 0,1 8,8A4,4 0 0,1 12,4M12,14C16.42,14 20,15.79 20,18V20H4V18C4,15.79 7.58,14 12,14Z"/></svg></div>
|
289 |
+
<div class="guest-label">Guest</div>
|
290 |
+
<div class="action-icons"><div id="share-btn" class="action-icon" title="Share"><svg viewBox="0 0 24 24"><path d="M21,12L14,5V9C7,10 4,15 3,20C5.5,16.5 9,14.9 14,14.9V19L21,12Z"/></svg></div></div>
|
291 |
+
<div class="credit">Dibuat oleh <a href="https://reddit.com/u/DinnerUnlucky4661" target="_blank">/u/DinnerUnlucky4661</a> on Reddit</div>
|
292 |
+
</div>
|
293 |
+
</div>
|
294 |
+
<div class="right-panel">
|
295 |
+
<div class="right-header"><div class="play-bots"><div class="bot-icon"><svg viewBox="0 0 24 24"><path d="M12,2A2,2 0 0,1 14,4C14,4.74 13.6,5.39 13,5.73V7H14A7,7 0 0,1 21,14H22A1,1 0 0,1 23,15V18A1,1 0 0,1 22,19H21V20A2,2 0 0,1 19,22H5A2,2 0 0,1 3,20V19H2A1,1 0 0,1 1,18V15A1,1 0 0,1 2,14H3A7,7 0 0,1 10,7H11V5.73C10.4,5.39 10,4.74 10,4A2,2 0 0,1 12,2M7.5,13A2.5,2.5 0 0,0 5,15.5A2.5,2.5 0 0,0 7.5,18A2.5,2.5 0 0,0 10,15.5A2.5,2.5 0 0,0 7.5,13M16.5,13A2.5,2.5 0 0,0 14,15.5A2.5,2.5 0 0,0 16.5,18A2.5,2.5 0 0,0 19,15.5A2.5,2.5 0 0,0 16.5,13Z"/></svg></div><span>Play Bots</span></div></div>
|
296 |
+
<div class="moves-section"><div class="moves-header" id="status-display">Loading Gemifish Engine...</div><div class="moves-list" id="moves-list"></div></div>
|
297 |
+
<div class="ai-reasoning-section">
|
298 |
+
<div class="ai-reasoning-header">
|
299 |
+
<svg fill="currentColor" width="16" height="16" viewBox="0 0 24 24"><path d="M12,2A2,2 0 0,1 14,4C14,4.74 13.6,5.39 13,5.73V7H14A7,7 0 0,1 21,14H22A1,1 0 0,1 23,15V18A1,1 0 0,1 22,19H21V20A2,2 0 0,1 19,22H5A2,2 0 0,1 3,20V19H2A1,1 0 0,1 1,18V15A1,1 0 0,1 2,14H3A7,7 0 0,1 10,7H11V5.73C10.4,5.39 10,4.74 10,4A2,2 0 0,1 12,2Z"/></svg>
|
300 |
+
AI Reasoning
|
301 |
+
</div>
|
302 |
+
<p id="ai-reasoning-text">Set a personality to see the AI's thoughts here.</p>
|
303 |
+
</div>
|
304 |
+
<div class="controls">
|
305 |
+
<div class="nav-controls">
|
306 |
+
<button id="btn-first" class="control-btn"><svg viewBox="0 0 24 24"><path d="M18.41,16.59L13.82,12L18.41,7.41L17,6L11,12L17,18L18.41,16.59M6,6H8V18H6V6Z"/></svg></button>
|
307 |
+
<button id="btn-back" class="control-btn"><svg viewBox="0 0 24 24"><path d="M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z"/></svg></button>
|
308 |
+
<button id="btn-forward" class="control-btn"><svg viewBox="0 0 24 24"><path d="M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z"/></svg></button>
|
309 |
+
<button id="btn-last" class="control-btn"><svg viewBox="0 0 24 24"><path d="M5.59,7.41L10.18,12L5.59,16.59L7,18L13,12L7,6L5.59,7.41M16,6H18V18H16V6Z"/></svg></button>
|
310 |
+
</div>
|
311 |
+
<button id="resign-btn" class="resign-btn"><svg viewBox="0 0 24 24"><path d="M14.4,6L14,4H5V21H7V14H12.6L13,16H20V6H14.4Z"/></svg><span>Resign</span></button>
|
312 |
+
</div>
|
313 |
+
</div>
|
314 |
+
</div>
|
315 |
+
|
316 |
+
<div class="modal-overlay" id="pgn-modal-overlay">
|
317 |
+
<div class="modal">
|
318 |
+
<div class="modal-header">
|
319 |
+
Share Game
|
320 |
+
<button id="modal-close-btn" class="modal-close-btn"><svg width="22" height="22" viewBox="0 0 22 22"><line x1="6" y1="6" x2="16" y2="16" stroke="#bdbdbd" stroke-width="2" stroke-linecap="round"/><line x1="16" y1="6" x2="6" y2="16" stroke="#bdbdbd" stroke-width="2" stroke-linecap="round"/></svg></button>
|
321 |
+
</div>
|
322 |
+
<div class="modal-content">
|
323 |
+
<div class="tabs"><button class="tab">PGN</button></div>
|
324 |
+
<div>
|
325 |
+
<div class="section-label">FEN</div>
|
326 |
+
<div class="input-row"><input class="input-box" id="fenInput" readonly><button class="copy-btn" id="copy-fen-btn" title="Copy FEN"><svg width="22" height="22" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 4v4H4m12-4v4h4M8 20v-4H4m12 4v-4h4m-4-2h-4v4h4zM8 9H4V5h4zm12 0h-4V5h4zm-8 8H8v-4h4z"/></svg></button></div>
|
327 |
+
<div class="section-label">PGN</div>
|
328 |
+
<div class="input-row"><textarea class="input-box pgn-area" id="pgnText" readonly></textarea><button class="copy-btn" id="copy-pgn-btn" title="Copy PGN"><svg width="22" height="22" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 4v4H4m12-4v4h4M8 20v-4H4m12 4v-4h4m-4-2h-4v4h4zM8 9H4V5h4zm12 0h-4V5h4zm-8 8H8v-4h4z"/></svg></button></div>
|
329 |
+
<button class="modal-action-btn download" id="download-pgn-btn"><svg width="24" height="24" viewBox="0 0 24 24"><path d="M12 4v12m0 0l-4-4m4 4l4-4m-4 8h8a2 2 0 002-2v-2" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg>Download</button>
|
330 |
+
</div>
|
331 |
+
</div>
|
332 |
+
</div>
|
333 |
+
</div>
|
334 |
+
|
335 |
+
<div class="modal-overlay" id="ai-modal-overlay">
|
336 |
+
<div class="modal">
|
337 |
+
<div class="modal-header">
|
338 |
+
AI Personality
|
339 |
+
<button id="ai-modal-close-btn" class="modal-close-btn"><svg width="22" height="22" viewBox="0 0 22 22"><line x1="6" y1="6" x2="16" y2="16" stroke="#bdbdbd" stroke-width="2" stroke-linecap="round"/><line x1="16" y1="6" x2="6" y2="16" stroke="#bdbdbd" stroke-width="2" stroke-linecap="round"/></svg></button>
|
340 |
+
</div>
|
341 |
+
<div class="modal-content">
|
342 |
+
<div class="section-label" style="margin-top: 16px;">System Prompt</div>
|
343 |
+
<p style="font-size: 13px; color: #aaa; margin-bottom: 12px;">Describe the personality for the AI opponent. If this is empty, the AI will play using the standard Stockfish engine.</p>
|
344 |
+
<div class="input-row">
|
345 |
+
<textarea class="input-box pgn-area" id="ai-personality-input" placeholder="e.g., An aggressive pirate who loves to attack and sacrifice pieces."></textarea>
|
346 |
+
</div>
|
347 |
+
<button class="modal-action-btn save-ai" id="save-ai-personality-btn"><svg fill="currentColor" width="24" height="24" viewBox="0 0 24 24"><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/></svg>Apply Personality</button>
|
348 |
+
</div>
|
349 |
+
</div>
|
350 |
+
</div>
|
351 |
+
|
352 |
+
<!-- New Settings Modal with API Key Input -->
|
353 |
+
<div class="modal-overlay" id="settings-modal-overlay">
|
354 |
+
<div class="modal">
|
355 |
+
<div class="modal-header">
|
356 |
+
Settings
|
357 |
+
<button id="settings-modal-close-btn" class="modal-close-btn"><svg width="22" height="22" viewBox="0 0 22 22"><line x1="6" y1="6" x2="16" y2="16" stroke="#bdbdbd" stroke-width="2" stroke-linecap="round"/><line x1="16" y1="6" x2="6" y2="16" stroke="#bdbdbd" stroke-width="2" stroke-linecap="round"/></svg></button>
|
358 |
+
</div>
|
359 |
+
<div class="modal-content">
|
360 |
+
<div class="section-label">Gemini API Key (Optional)</div>
|
361 |
+
<p style="font-size: 13px; color: #aaa; margin-bottom: 12px;">Masukkan API key-mu jika default error/limit. Kosongkan untuk pakai default.</p>
|
362 |
+
<input type="text" id="api-key-input" class="input-box" placeholder="Your Gemini API Key">
|
363 |
+
<button class="modal-action-btn save-ai" id="save-settings-btn"><svg fill="currentColor" width="24" height="24" viewBox="0 0 24 24"><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/></svg>Save</button>
|
364 |
+
|
365 |
+
<!-- Existing theme buttons moved here for better UX -->
|
366 |
+
<div class="settings-section-header">Board Theme</div>
|
367 |
+
<button id="theme-brown-btn" class="theme-btn"><div class="theme-swatch"><div class="theme-swatch-light" style="background-color: #f0d9b5;"></div><div class="theme-swatch-dark" style="background-color: #b58863;"></div></div>Brown</button>
|
368 |
+
<button id="theme-blue-btn" class="theme-btn"><div class="theme-swatch"><div class="theme-swatch-light" style="background-color: #D8DEE9;"></div><div class="theme-swatch-dark" style="background-color: #819AAE;"></div></div>Blue</button>
|
369 |
+
</div>
|
370 |
+
</div>
|
371 |
+
</div>
|
372 |
+
|
373 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
374 |
+
<script src="https://unpkg.com/@chrisoakman/[email protected]/dist/chessboard-1.0.0.min.js"></script>
|
375 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.10.2/chess.min.js"></script>
|
376 |
+
|
377 |
+
<script>
|
378 |
+
var board = null, game = new Chess(), $status = $('#status-display');
|
379 |
+
var playerColor = 'w', engine = null, isGameOver = false, viewingMoveIndex = -1;
|
380 |
+
var boardThemeStyle = document.createElement('style');
|
381 |
+
document.head.appendChild(boardThemeStyle);
|
382 |
+
|
383 |
+
var aiPersonality = '';
|
384 |
+
var geminiApiKey = ''; // <-- IMPORTANT: REPLACE WITH YOUR GEMINI API KEY
|
385 |
+
var userApiKey = ''; // User-provided key
|
386 |
+
var isEngineSearching = false;
|
387 |
+
var topMovesWithEvals = [];
|
388 |
+
const useLLM = () => aiPersonality && aiPersonality.trim() !== '';
|
389 |
+
|
390 |
+
const THEMES = {
|
391 |
+
brown: { light: '#f0d9b5', dark: '#b58863' },
|
392 |
+
blue: { light: '#D8DEE9', dark: '#819AAE' }
|
393 |
+
};
|
394 |
+
const STOCKFISH_WORKER_URL = 'https://cdnjs.cloudflare.com/ajax/libs/stockfish.js/10.0.2/stockfish.js';
|
395 |
+
const pieceImagePaths = {'wP': 'https://upload.wikimedia.org/wikipedia/commons/4/45/Chess_plt45.svg','wR': 'https://upload.wikimedia.org/wikipedia/commons/7/72/Chess_rlt45.svg','wN': 'https://upload.wikimedia.org/wikipedia/commons/7/70/Chess_nlt45.svg','wB': 'https://upload.wikimedia.org/wikipedia/commons/b/b1/Chess_blt45.svg','wQ': 'https://upload.wikimedia.org/wikipedia/commons/1/15/Chess_qlt45.svg','wK': 'https://upload.wikimedia.org/wikipedia/commons/4/42/Chess_klt45.svg','bP': 'https://upload.wikimedia.org/wikipedia/commons/c/c7/Chess_pdt45.svg','bR': 'https://upload.wikimedia.org/wikipedia/commons/f/ff/Chess_rdt45.svg','bN': 'https://upload.wikimedia.org/wikipedia/commons/e/ef/Chess_ndt45.svg','bB': 'https://upload.wikimedia.org/wikipedia/commons/9/98/Chess_bdt45.svg','bQ': 'https://upload.wikimedia.org/wikipedia/commons/4/47/Chess_qdt45.svg','bK': 'https://upload.wikimedia.org/wikipedia/commons/f/f0/Chess_kdt45.svg'};
|
396 |
+
function pieceTheme(piece) { return pieceImagePaths[piece]; }
|
397 |
+
|
398 |
+
function setBoardTheme(themeName) {
|
399 |
+
const theme = THEMES[themeName];
|
400 |
+
boardThemeStyle.innerHTML = `
|
401 |
+
.square-55d63.white-1e1d7 { background-color: ${theme.light}; color: ${theme.dark}; }
|
402 |
+
.square-55d63.black-3c85d { background-color: ${theme.dark}; color: ${theme.light}; }
|
403 |
+
`;
|
404 |
+
$('.theme-btn').removeClass('active');
|
405 |
+
$(`#theme-${themeName}-btn`).addClass('active');
|
406 |
+
}
|
407 |
+
|
408 |
+
function onDragStart(source, piece) {
|
409 |
+
const canMove = !isGameOver && !isEngineSearching && !game.game_over() && game.turn() === playerColor && viewingMoveIndex === game.history().length - 1;
|
410 |
+
|
411 |
+
if (!canMove) {
|
412 |
+
console.log("Move disallowed. Current state:", {
|
413 |
+
isGameOver,
|
414 |
+
isEngineSearching,
|
415 |
+
isGameTerminated: game.game_over(),
|
416 |
+
isPlayerTurn: game.turn() === playerColor,
|
417 |
+
isViewingLatestMove: viewingMoveIndex === game.history().length - 1
|
418 |
+
});
|
419 |
+
}
|
420 |
+
return canMove;
|
421 |
+
}
|
422 |
+
|
423 |
+
function createEngineWorker() {
|
424 |
+
return fetch(STOCKFISH_WORKER_URL).then(res => res.text()).then(scriptText => {
|
425 |
+
const blob = new Blob([scriptText], { type: 'application/javascript' });
|
426 |
+
return new Worker(URL.createObjectURL(blob));
|
427 |
+
});
|
428 |
+
}
|
429 |
+
|
430 |
+
function initializeEngine() {
|
431 |
+
createEngineWorker().then(worker => {
|
432 |
+
engine = worker;
|
433 |
+
engine.onmessage = handleEngineMessage;
|
434 |
+
engine.postMessage('uci');
|
435 |
+
engine.postMessage('setoption name MultiPV value 5');
|
436 |
+
updateStatus();
|
437 |
+
}).catch(err => {
|
438 |
+
console.error("Failed to load engine:", err);
|
439 |
+
updateStatus("Error: Could not load engine.");
|
440 |
+
});
|
441 |
+
}
|
442 |
+
|
443 |
+
function showNotification(message, duration = 6000) {
|
444 |
+
const notification = $('#ai-notification');
|
445 |
+
$('#ai-notification-text').text(message);
|
446 |
+
notification.addClass('show');
|
447 |
+
setTimeout(() => { notification.removeClass('show'); }, duration);
|
448 |
+
}
|
449 |
+
|
450 |
+
function handleEngineMessage(event) {
|
451 |
+
const message = event.data;
|
452 |
+
if (useLLM()) {
|
453 |
+
if (message.startsWith('info') && message.includes('score cp')) {
|
454 |
+
const scoreMatch = message.match(/score cp (-?\d+)/);
|
455 |
+
const moveMatch = message.match(/pv\s+([a-h][1-8][a-h][1-8][qrbn]?)/);
|
456 |
+
if (scoreMatch && moveMatch) {
|
457 |
+
const score = parseInt(scoreMatch[1], 10);
|
458 |
+
const move = moveMatch[1];
|
459 |
+
if (!topMovesWithEvals.some(item => item.move === move)) {
|
460 |
+
topMovesWithEvals.push({ move, score });
|
461 |
+
}
|
462 |
+
}
|
463 |
+
}
|
464 |
+
if (message.startsWith('bestmove')) {
|
465 |
+
const bestMoveFallback = message.split(' ')[1];
|
466 |
+
decideMoveWithLLM(bestMoveFallback);
|
467 |
+
}
|
468 |
+
} else {
|
469 |
+
if (message.startsWith('bestmove')) {
|
470 |
+
isEngineSearching = false;
|
471 |
+
makeMoveOnBoard(message.split(' ')[1]);
|
472 |
+
}
|
473 |
+
}
|
474 |
+
}
|
475 |
+
|
476 |
+
async function decideMoveWithLLM(fallbackMove) {
|
477 |
+
const apiKeyToUse = userApiKey || geminiApiKey; // Use user key if provided
|
478 |
+
if (!apiKeyToUse) {
|
479 |
+
showNotification('API key kosong. Gunakan Stockfish default.');
|
480 |
+
makeMoveOnBoard(fallbackMove);
|
481 |
+
return;
|
482 |
+
}
|
483 |
+
const maxRetries = 5;
|
484 |
+
let retryCount = 0;
|
485 |
+
|
486 |
+
while (retryCount < maxRetries) {
|
487 |
+
try {
|
488 |
+
if (topMovesWithEvals.length === 0) {
|
489 |
+
console.warn("No top moves were analyzed. Using fallback move:", fallbackMove);
|
490 |
+
makeMoveOnBoard(fallbackMove);
|
491 |
+
return;
|
492 |
+
}
|
493 |
+
|
494 |
+
const fen = game.fen();
|
495 |
+
const turn = game.turn() === 'w' ? 'White' : 'Black';
|
496 |
+
const movesData = JSON.stringify(topMovesWithEvals);
|
497 |
+
|
498 |
+
const prompt = `You are a world-class chess engine and a master role-player. Your goal is to perfectly blend strong chess play with a defined personality. Your priority is 80% playing the best move and 20% fitting your character. You must select a move from the provided list.
|
499 |
+
|
500 |
+
Current State:
|
501 |
+
- Board (FEN): ${fen}
|
502 |
+
- It is ${turn}'s turn to move.
|
503 |
+
- Your designated personality is: "${aiPersonality}"
|
504 |
+
|
505 |
+
Your Task:
|
506 |
+
I have provided a JSON array of the top moves calculated by a strong chess engine. First, identify the strongest moves that don't lead to a disadvantage. From that small group of good moves, pick the one that best reflects your character. Then, explain your choice from your character's perspective.
|
507 |
+
|
508 |
+
Input Moves Data:
|
509 |
+
${movesData}
|
510 |
+
|
511 |
+
Output Format:
|
512 |
+
You MUST respond in a VALID JSON FORMAT, with no other text. The JSON object must have three keys:
|
513 |
+
- "bestMove": The chosen move from the list (e.g., "e2e4"). Required.
|
514 |
+
- "reasoning": A brief, in-character explanation for your choice. DO NOT mention scores or technical analysis. This should be your character's internal monologue. Required.
|
515 |
+
- "deviationWarning": If you were forced to deviate from your personality to avoid a blunder, provide a short message explaining why. If you did not deviate, this MUST be null.`;
|
516 |
+
|
517 |
+
updateStatus('Consulting AI personality...');
|
518 |
+
$('#ai-reasoning-text').text('Thinking...');
|
519 |
+
|
520 |
+
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${apiKeyToUse}`, {
|
521 |
+
method: 'POST',
|
522 |
+
headers: { 'Content-Type': 'application/json' },
|
523 |
+
body: JSON.stringify({ "contents": [{ "parts": [{ "text": prompt }] }] })
|
524 |
+
});
|
525 |
+
|
526 |
+
if (response.status === 429) {
|
527 |
+
const delay = Math.pow(2, retryCount) * 1000 + Math.random() * 1000;
|
528 |
+
console.warn(`Rate limit hit. Retrying in ${delay.toFixed(2)}ms...`);
|
529 |
+
await new Promise(resolve => setTimeout(resolve, delay));
|
530 |
+
retryCount++;
|
531 |
+
continue; // Go to the next iteration of the while loop to retry
|
532 |
+
}
|
533 |
+
|
534 |
+
if (!response.ok) {
|
535 |
+
throw new Error(`API request failed with status ${response.status}`);
|
536 |
+
}
|
537 |
+
|
538 |
+
const data = await response.json();
|
539 |
+
|
540 |
+
if (!data.candidates || !data.candidates[0]?.content?.parts[0]?.text) {
|
541 |
+
const reason = data.candidates?.[0]?.finishReason || 'Unknown reason';
|
542 |
+
console.error("Invalid response structure from Gemini API. Content may be blocked or missing. Finish Reason:", reason, data);
|
543 |
+
throw new Error(`Invalid response structure from Gemini API. Finish Reason: ${reason}`);
|
544 |
+
}
|
545 |
+
|
546 |
+
let rawText = data.candidates[0].content.parts[0].text;
|
547 |
+
const jsonMatch = rawText.match(/```json\s*(\{[\s\S]*\})\s*```|(\{[\s\S]*\})/);
|
548 |
+
if (!jsonMatch) {
|
549 |
+
throw new Error("LLM did not return a parsable JSON object.");
|
550 |
+
}
|
551 |
+
|
552 |
+
const jsonString = jsonMatch[1] || jsonMatch[2];
|
553 |
+
const result = JSON.parse(jsonString);
|
554 |
+
|
555 |
+
if (!result.bestMove || typeof result.reasoning === 'undefined') {
|
556 |
+
throw new Error("Parsed JSON from LLM is missing required keys ('bestMove', 'reasoning').");
|
557 |
+
}
|
558 |
+
|
559 |
+
if (result.deviationWarning) {
|
560 |
+
showNotification(result.deviationWarning);
|
561 |
+
}
|
562 |
+
$('#ai-reasoning-text').text(result.reasoning || "I have made my move.");
|
563 |
+
|
564 |
+
if (topMovesWithEvals.some(item => item.move === result.bestMove)) {
|
565 |
+
makeMoveOnBoard(result.bestMove);
|
566 |
+
} else {
|
567 |
+
console.warn(`LLM chose a move (${result.bestMove}) not in the valid list. Defaulting to best Stockfish move.`);
|
568 |
+
makeMoveOnBoard(fallbackMove);
|
569 |
+
}
|
570 |
+
return; // Exit the function successfully
|
571 |
+
|
572 |
+
} catch (error) {
|
573 |
+
console.error("An error occurred while getting the AI's move:", error);
|
574 |
+
// If we've exhausted retries, give up and use the fallback.
|
575 |
+
if (retryCount >= maxRetries - 1) {
|
576 |
+
$('#ai-reasoning-text').text("An error occurred. I will play the best move as a fallback.");
|
577 |
+
updateStatus('Error with AI. Using best move.');
|
578 |
+
makeMoveOnBoard(fallbackMove);
|
579 |
+
break; // Exit the while loop
|
580 |
+
}
|
581 |
+
}
|
582 |
+
}
|
583 |
+
isEngineSearching = false; // Ensure searching is always set to false after attempting to get a move.
|
584 |
+
}
|
585 |
+
|
586 |
+
function makeEngineMove() {
|
587 |
+
if (isGameOver || game.game_over() || !engine) return;
|
588 |
+
isEngineSearching = true;
|
589 |
+
updateStatus('Gemifish is thinking...');
|
590 |
+
|
591 |
+
topMovesWithEvals = [];
|
592 |
+
engine.postMessage('position fen ' + game.fen());
|
593 |
+
engine.postMessage('go depth 15');
|
594 |
+
}
|
595 |
+
|
596 |
+
function makeMoveOnBoard(move) {
|
597 |
+
game.move(move, { sloppy: true });
|
598 |
+
board.position(game.fen());
|
599 |
+
board.resize(); // Force resize after move to prevent cutting
|
600 |
+
viewingMoveIndex = game.history().length - 1;
|
601 |
+
updateStatus();
|
602 |
+
updateMoveHistory();
|
603 |
+
if (game.game_over()) updateStatus();
|
604 |
+
}
|
605 |
+
|
606 |
+
function onDrop(source, target) {
|
607 |
+
var move = game.move({ from: source, to: target, promotion: 'q' });
|
608 |
+
if (move === null) return 'snapback';
|
609 |
+
|
610 |
+
viewingMoveIndex = game.history().length - 1;
|
611 |
+
updateMoveHistory();
|
612 |
+
|
613 |
+
if (game.game_over()) {
|
614 |
+
updateStatus();
|
615 |
+
} else {
|
616 |
+
window.setTimeout(makeEngineMove, 250);
|
617 |
+
}
|
618 |
+
}
|
619 |
+
|
620 |
+
function onSnapEnd() {
|
621 |
+
board.position(game.fen());
|
622 |
+
// Tambahkan sedikit delay sebelum resize untuk memastikan DOM sudah diperbarui
|
623 |
+
setTimeout(() => board.resize(), 10);
|
624 |
+
}
|
625 |
+
|
626 |
+
function updateMoveHistory() {
|
627 |
+
const history = game.history({ verbose: false });
|
628 |
+
const moveList = $('#moves-list');
|
629 |
+
moveList.empty();
|
630 |
+
let moveRow;
|
631 |
+
for (let i = 0; i < history.length; i++) {
|
632 |
+
if (i % 2 === 0) {
|
633 |
+
moveRow = $('<div class="move-row"></div>').append(`<span class="move-number">${(i / 2) + 1}.</span>`);
|
634 |
+
moveList.append(moveRow);
|
635 |
+
}
|
636 |
+
const san = history[i];
|
637 |
+
const $moveSpan = $('<span class="move"></span>').text(san);
|
638 |
+
moveRow.append($moveSpan);
|
639 |
+
}
|
640 |
+
$('.moves-section').scrollTop($('.moves-section')[0].scrollHeight);
|
641 |
+
updateHighlighting();
|
642 |
+
}
|
643 |
+
|
644 |
+
function updateHighlighting() {
|
645 |
+
$('.move').removeClass('highlighted-move');
|
646 |
+
if (viewingMoveIndex > -1) $('.move').eq(viewingMoveIndex).addClass('highlighted-move');
|
647 |
+
}
|
648 |
+
|
649 |
+
function navigateToMove(index) {
|
650 |
+
const history = game.history();
|
651 |
+
if (index < -1 || index >= history.length) return;
|
652 |
+
viewingMoveIndex = index;
|
653 |
+
const tempGame = new Chess();
|
654 |
+
for (let i = 0; i <= viewingMoveIndex; i++) tempGame.move(history[i]);
|
655 |
+
board.position(tempGame.fen());
|
656 |
+
// Tambahkan sedikit delay sebelum resize untuk memastikan DOM sudah diperbarui
|
657 |
+
setTimeout(() => board.resize(), 10);
|
658 |
+
updateHighlighting();
|
659 |
+
updateNavButtons();
|
660 |
+
}
|
661 |
+
|
662 |
+
function updateStatus(customStatus) {
|
663 |
+
var status = customStatus || '';
|
664 |
+
if (!customStatus) {
|
665 |
+
if (isGameOver) {
|
666 |
+
status = "You Resigned. Gemifish Wins.";
|
667 |
+
} else {
|
668 |
+
var moveColor = game.turn() === 'b' ? 'Black' : 'White';
|
669 |
+
if (game.in_checkmate()) status = 'Game over: ' + moveColor + ' is in checkmate.';
|
670 |
+
else if (game.in_draw()) status = 'Game over: Drawn position';
|
671 |
+
else {
|
672 |
+
status = (game.turn() === playerColor ? 'Your' : "Gemifish's") + ' turn';
|
673 |
+
if (game.in_check()) status += ' (in check)';
|
674 |
+
}
|
675 |
+
}
|
676 |
+
}
|
677 |
+
if (game.game_over() || isGameOver) {
|
678 |
+
$('#resign-btn').prop('disabled', true);
|
679 |
+
}
|
680 |
+
$status.html(status);
|
681 |
+
updateNavButtons();
|
682 |
+
}
|
683 |
+
|
684 |
+
function updateNavButtons() {
|
685 |
+
const historyLength = game.history().length;
|
686 |
+
const onLatestMove = viewingMoveIndex === historyLength - 1;
|
687 |
+
$('#btn-first').prop('disabled', viewingMoveIndex <= -1);
|
688 |
+
$('#btn-back').prop('disabled', viewingMoveIndex <= -1);
|
689 |
+
$('#btn-forward').prop('disabled', onLatestMove);
|
690 |
+
$('#btn-last').prop('disabled', onLatestMove);
|
691 |
+
}
|
692 |
+
|
693 |
+
function openShareModal() {
|
694 |
+
$('#fenInput').val(game.fen());
|
695 |
+
$('#pgnText').val(game.pgn());
|
696 |
+
$('#pgn-modal-overlay').css('display', 'flex');
|
697 |
+
}
|
698 |
+
function closeShareModal() { $('#pgn-modal-overlay').css('display', 'none'); }
|
699 |
+
function openAIPersonalityModal() {
|
700 |
+
$('#ai-personality-input').val(aiPersonality);
|
701 |
+
$('#ai-modal-overlay').css('display', 'flex');
|
702 |
+
}
|
703 |
+
function closeAIPersonalityModal() { $('#ai-modal-overlay').css('display', 'none'); }
|
704 |
+
function saveAIPersonality() {
|
705 |
+
aiPersonality = $('#ai-personality-input').val();
|
706 |
+
if (useLLM()) {
|
707 |
+
$('#ai-btn').addClass('active-ai');
|
708 |
+
$('#ai-reasoning-text').text('Personality set. Make your move!');
|
709 |
+
} else {
|
710 |
+
$('#ai-btn').removeClass('active-ai');
|
711 |
+
$('#ai-reasoning-text').text('Set a personality to see the AI\'s thoughts here.');
|
712 |
+
}
|
713 |
+
closeAIPersonalityModal();
|
714 |
+
}
|
715 |
+
|
716 |
+
function copyToClipboard(elementId, btnElem) {
|
717 |
+
navigator.clipboard.writeText($(`#${elementId}`).val()).then(() => {
|
718 |
+
const originalContent = $(btnElem).html();
|
719 |
+
$(btnElem).html('Copied!');
|
720 |
+
setTimeout(() => { $(btnElem).html(originalContent); }, 2000);
|
721 |
+
}).catch(err => {
|
722 |
+
console.error('Failed to copy text: ', err);
|
723 |
+
const originalContent = $(btnElem).html();
|
724 |
+
$(btnElem).html('Error!');
|
725 |
+
setTimeout(() => { $(btnElem).html(originalContent); }, 2000);
|
726 |
+
});
|
727 |
+
}
|
728 |
+
|
729 |
+
function downloadPGN() {
|
730 |
+
const text = $('#pgnText').val();
|
731 |
+
const blob = new Blob([text], { type: 'application/vnd.chess-pgn' });
|
732 |
+
const url = URL.createObjectURL(blob);
|
733 |
+
const a = document.createElement('a'); a.href = url;
|
734 |
+
a.download = `Gemifish-vs-Guest-${new Date().toISOString().slice(0,10)}.pgn`;
|
735 |
+
document.body.appendChild(a); a.click();
|
736 |
+
document.body.removeChild(a); URL.revokeObjectURL(url);
|
737 |
+
}
|
738 |
+
|
739 |
+
// New functions for settings modal
|
740 |
+
function openSettingsModal() {
|
741 |
+
$('#api-key-input').val(userApiKey);
|
742 |
+
$('#settings-modal-overlay').css('display', 'flex');
|
743 |
+
}
|
744 |
+
function closeSettingsModal() { $('#settings-modal-overlay').css('display', 'none'); }
|
745 |
+
|
746 |
+
var config = {
|
747 |
+
draggable: true,
|
748 |
+
position: 'start',
|
749 |
+
onDragStart,
|
750 |
+
onDrop,
|
751 |
+
onSnapEnd,
|
752 |
+
pieceTheme,
|
753 |
+
showNotation: true
|
754 |
+
};
|
755 |
+
board = Chessboard('game-board', config);
|
756 |
+
|
757 |
+
// Fungsi untuk memastikan board menyesuaikan dengan container
|
758 |
+
function ensureBoardFits() {
|
759 |
+
const container = $('.chess-board-container');
|
760 |
+
// Kurangi padding dari perhitungan ukuran
|
761 |
+
const containerWidth = container.width() - 16; // Kurangi 2 * padding (8px)
|
762 |
+
const containerHeight = container.height() - 16; // Kurangi 2 * padding (8px)
|
763 |
+
|
764 |
+
// Tentukan ukuran maksimum berdasarkan container
|
765 |
+
const maxSize = Math.min(containerWidth, containerHeight);
|
766 |
+
|
767 |
+
// Atur ukuran board
|
768 |
+
$('#game-board').css({
|
769 |
+
'width': maxSize + 'px',
|
770 |
+
'height': maxSize + 'px'
|
771 |
+
});
|
772 |
+
|
773 |
+
// Resize board
|
774 |
+
board.resize();
|
775 |
+
}
|
776 |
+
|
777 |
+
// Panggil fungsi saat inisialisasi
|
778 |
+
ensureBoardFits();
|
779 |
+
|
780 |
+
// Panggil fungsi saat window di-resize
|
781 |
+
$(window).on('resize', ensureBoardFits);
|
782 |
+
|
783 |
+
// Event Handlers
|
784 |
+
$('#resign-btn').on('click', () => { if (!isGameOver && !game.game_over()) { isGameOver = true; updateStatus(); }});
|
785 |
+
$('#btn-back').on('click', () => navigateToMove(viewingMoveIndex - 1));
|
786 |
+
$('#btn-forward').on('click', () => navigateToMove(viewingMoveIndex + 1));
|
787 |
+
$('#btn-first').on('click', () => navigateToMove(-1));
|
788 |
+
$('#btn-last').on('click', () => navigateToMove(game.history().length - 1));
|
789 |
+
|
790 |
+
$('#share-btn').on('click', openShareModal);
|
791 |
+
$('#modal-close-btn').on('click', function(e) { e.stopPropagation(); closeShareModal(); });
|
792 |
+
$('#pgn-modal-overlay').on('click', function(e) { if (e.target === this || $(e.target).is('#modal-close-btn, #modal-close-btn *')) closeShareModal(); });
|
793 |
+
|
794 |
+
$('#ai-btn').on('click', openAIPersonalityModal);
|
795 |
+
$('#ai-modal-close-btn').on('click', function(e) { e.stopPropagation(); closeAIPersonalityModal(); });
|
796 |
+
$('#ai-modal-overlay').on('click', function(e) { if (e.target === this || $(e.target).is('#ai-modal-close-btn, #ai-modal-close-btn *')) closeAIPersonalityModal(); });
|
797 |
+
$('#save-ai-personality-btn').on('click', saveAIPersonality);
|
798 |
+
|
799 |
+
$('.modal').on('click', e => e.stopPropagation());
|
800 |
+
$('#copy-fen-btn').on('click', function() { copyToClipboard('fenInput', this); });
|
801 |
+
$('#copy-pgn-btn').on('click', function() { copyToClipboard('pgnText', this); });
|
802 |
+
$('#download-pgn-btn').on('click', downloadPGN);
|
803 |
+
|
804 |
+
$('#settings-btn').on('click', openSettingsModal);
|
805 |
+
$('#settings-modal-close-btn').on('click', function(e) { e.stopPropagation(); closeSettingsModal(); });
|
806 |
+
$('#settings-modal-overlay').on('click', function(e) { if (e.target === this || $(e.target).is('#settings-modal-close-btn, #settings-modal-close-btn *')) closeSettingsModal(); });
|
807 |
+
$('#save-settings-btn').on('click', () => {
|
808 |
+
userApiKey = $('#api-key-input').val().trim();
|
809 |
+
closeSettingsModal();
|
810 |
+
showNotification('Settings disimpan!');
|
811 |
+
});
|
812 |
+
$('#theme-brown-btn').on('click', () => setBoardTheme('brown'));
|
813 |
+
$('#theme-blue-btn').on('click', () => setBoardTheme('blue'));
|
814 |
+
|
815 |
+
setBoardTheme('blue');
|
816 |
+
initializeEngine();
|
817 |
+
</script>
|
818 |
+
</body>
|
819 |
+
</html>
|