Spaces:
Running
Running
Update index.html
Browse files- index.html +58 -27
index.html
CHANGED
@@ -300,18 +300,29 @@
|
|
300 |
return starPoints.some(point => point[0] === row && point[1] === col);
|
301 |
}
|
302 |
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
}
|
313 |
-
}
|
314 |
}
|
|
|
|
|
|
|
315 |
|
316 |
isValidMove(row, col) {
|
317 |
if(this.board[row][col] !== null) return false;
|
@@ -325,17 +336,30 @@
|
|
325 |
return !suicide || captures.length > 0;
|
326 |
}
|
327 |
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
339 |
|
340 |
renderStone(row, col) {
|
341 |
const intersection = document.querySelector(`[data-row="${row}"][data-col="${col}"]`);
|
@@ -427,14 +451,21 @@
|
|
427 |
return this.isGroupCaptured(group);
|
428 |
}
|
429 |
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
|
|
|
|
|
|
|
|
436 |
}
|
437 |
-
}
|
|
|
|
|
|
|
438 |
|
439 |
reset() {
|
440 |
this.board = Array(this.size).fill().map(() => Array(this.size).fill(null));
|
|
|
300 |
return starPoints.some(point => point[0] === row && point[1] === col);
|
301 |
}
|
302 |
|
303 |
+
handleMove(e) {
|
304 |
+
const row = parseInt(e.target.dataset.row);
|
305 |
+
const col = parseInt(e.target.dataset.col);
|
306 |
|
307 |
+
if (this.gameMode === 'ai' && this.currentPlayer === 'white') {
|
308 |
+
return; // AI μ°¨λ‘μλ νλ μ΄μ΄κ° λμ λμ μ μμ
|
309 |
+
}
|
310 |
+
|
311 |
+
if (this.isValidMove(row, col)) {
|
312 |
+
this.placeStone(row, col);
|
313 |
+
|
314 |
+
if (this.gameMode === 'ai' && this.currentPlayer === 'white') {
|
315 |
+
setTimeout(() => {
|
316 |
+
if (this.difficulty === 'easy') {
|
317 |
+
this.makeRandomMove();
|
318 |
+
} else {
|
319 |
+
this.makeStrategicMove();
|
320 |
}
|
321 |
+
}, 500);
|
322 |
}
|
323 |
+
}
|
324 |
+
}
|
325 |
+
|
326 |
|
327 |
isValidMove(row, col) {
|
328 |
if(this.board[row][col] !== null) return false;
|
|
|
336 |
return !suicide || captures.length > 0;
|
337 |
}
|
338 |
|
339 |
+
placeStone(row, col) {
|
340 |
+
if (this.board[row][col] !== null) return;
|
341 |
+
|
342 |
+
this.board[row][col] = this.currentPlayer;
|
343 |
+
this.renderStone(row, col);
|
344 |
+
|
345 |
+
const captures = this.checkCaptures(row, col);
|
346 |
+
this.removeCaptures(captures);
|
347 |
+
|
348 |
+
this.lastMove = [row, col];
|
349 |
+
this.currentPlayer = this.currentPlayer === 'black' ? 'white' : 'black';
|
350 |
+
this.updateDisplay();
|
351 |
+
|
352 |
+
// AI μ°¨λ‘ μλ μ§ν
|
353 |
+
if (this.gameMode === 'ai' && this.currentPlayer === 'white') {
|
354 |
+
setTimeout(() => {
|
355 |
+
if (this.difficulty === 'easy') {
|
356 |
+
this.makeRandomMove();
|
357 |
+
} else {
|
358 |
+
this.makeStrategicMove();
|
359 |
+
}
|
360 |
+
}, 500);
|
361 |
+
}
|
362 |
+
}
|
363 |
|
364 |
renderStone(row, col) {
|
365 |
const intersection = document.querySelector(`[data-row="${row}"][data-col="${col}"]`);
|
|
|
451 |
return this.isGroupCaptured(group);
|
452 |
}
|
453 |
|
454 |
+
pass() {
|
455 |
+
this.currentPlayer = this.currentPlayer === 'black' ? 'white' : 'black';
|
456 |
+
this.updateDisplay();
|
457 |
+
|
458 |
+
if (this.gameMode === 'ai' && this.currentPlayer === 'white') {
|
459 |
+
setTimeout(() => {
|
460 |
+
if (this.difficulty === 'easy') {
|
461 |
+
this.makeRandomMove();
|
462 |
+
} else {
|
463 |
+
this.makeStrategicMove();
|
464 |
}
|
465 |
+
}, 500);
|
466 |
+
}
|
467 |
+
}
|
468 |
+
}
|
469 |
|
470 |
reset() {
|
471 |
this.board = Array(this.size).fill().map(() => Array(this.size).fill(null));
|