Raven7 commited on
Commit
c57c264
β€’
1 Parent(s): c2ce6ca

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +50 -166
index.html CHANGED
@@ -301,28 +301,29 @@
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;
@@ -492,171 +493,65 @@
492
 
493
  // GoGame 클래슀 λ‚΄μ˜ makeStrategicMove λ©”μ†Œλ“œλ₯Ό λ‹€μŒκ³Ό 같이 μˆ˜μ •
494
  makeStrategicMove() {
495
- // ν˜„μž¬ λ³΄λ“œ μƒνƒœ 평가
496
- const boardScore = this.evaluateBoard();
497
-
498
- // κ°€λŠ₯ν•œ λͺ¨λ“  수의 점수λ₯Ό 계산
499
  let bestScore = -Infinity;
500
  let bestMove = null;
501
-
502
- for(let i = 0; i < this.size; i++) {
503
- for(let j = 0; j < this.size; j++) {
504
- if(this.isValidMove(i, j)) {
505
- // κ°€μƒμœΌλ‘œ λŒμ„ 놓아보고 점수 계산
506
- this.board[i][j] = 'white';
507
- const score = this.calculateMoveScore(i, j, boardScore);
508
- this.board[i][j] = null;
509
-
510
- if(score > bestScore) {
511
  bestScore = score;
512
  bestMove = [i, j];
513
  }
514
  }
515
  }
516
  }
517
-
518
- if(bestMove) {
 
519
  this.placeStone(bestMove[0], bestMove[1]);
520
  } else {
521
  this.pass();
522
  }
523
  }
524
 
525
- evaluateBoard() {
526
- const evaluation = {
527
- territory: this.evaluateTerritory(),
528
- influence: this.evaluateInfluence(),
529
- connections: this.evaluateConnections(),
530
- captures: this.captures
531
- };
532
- return evaluation;
533
- }
534
-
535
- calculateMoveScore(row, col, boardScore) {
536
- let score = 0;
537
-
538
- // 1. μ˜ν†  점수
539
- score += this.calculateTerritoryScore(row, col) * 2;
540
-
541
- // 2. μ—°κ²°μ„± 점수
542
- score += this.calculateConnectionScore(row, col) * 1.5;
543
-
544
- // 3. 곡격/λ°©μ–΄ 점수
545
- score += this.calculateTacticalScore(row, col);
546
-
547
- // 4. μœ„ν—˜ νšŒν”Ό 점수
548
- score += this.calculateSafetyScore(row, col);
549
-
550
- // 5. μ „λž΅μ  μœ„μΉ˜ 점수
551
- score += this.calculateStrategicScore(row, col);
552
-
553
- return score;
554
- }
555
-
556
- calculateTerritoryScore(row, col) {
557
  let score = 0;
558
- const radius = 3;
559
-
560
- for(let i = Math.max(0, row-radius); i <= Math.min(this.size-1, row+radius); i++) {
561
- for(let j = Math.max(0, col-radius); j <= Math.min(this.size-1, col+radius); j++) {
562
- const distance = Math.abs(row-i) + Math.abs(col-j);
563
- if(distance <= radius) {
564
- if(this.board[i][j] === null) score += (radius - distance + 1);
565
- else if(this.board[i][j] === 'white') score += 2;
566
- else score -= 1;
567
- }
568
- }
569
- }
570
- return score;
571
- }
572
 
573
- calculateConnectionScore(row, col) {
574
- let score = 0;
575
  const neighbors = this.getNeighbors(row, col);
576
-
577
- for(const [nRow, nCol] of neighbors) {
578
- if(this.board[nRow][nCol] === 'white') {
579
- score += 10;
580
- // 두 돌이 μ—°κ²°λ˜λ©΄ 더 높은 점수
581
- if(this.areConnected(row, col, nRow, nCol)) score += 5;
582
- }
583
- }
584
- return score;
585
- }
586
-
587
- calculateTacticalScore(row, col) {
588
- let score = 0;
589
- const neighbors = this.getNeighbors(row, col);
590
-
591
- // μƒλŒ€ 돌 곡격 기회 확인
592
- for(const [nRow, nCol] of neighbors) {
593
- if(this.board[nRow][nCol] === 'black') {
594
- const group = this.getGroup(nRow, nCol);
595
- const liberties = this.countLiberties(group);
596
- if(liberties <= 2) score += (20 - liberties * 5);
597
- }
598
  }
599
-
600
- return score;
601
- }
602
 
603
- calculateSafetyScore(row, col) {
604
- let score = 0;
605
- const group = [[row, col]];
606
- const liberties = this.countLiberties(group);
607
-
608
- score += liberties * 5;
609
-
610
- // 눈 ν˜•μ„± κ°€λŠ₯μ„± 체크
611
- if(this.canFormEye(row, col)) score += 15;
612
-
613
- return score;
614
- }
615
 
616
- calculateStrategicScore(row, col) {
617
- let score = 0;
618
-
619
- // 쀑앙 지역 μ„ ν˜Έ
620
  const centerDistance = Math.abs(row - 9) + Math.abs(col - 9);
621
  score += Math.max(0, 10 - centerDistance);
622
-
623
- // 변에 뢙지 μ•Šλ„λ‘
624
- if(row === 0 || row === 18 || col === 0 || col === 18) score -= 5;
625
-
626
- // μŠ€νƒ€ν¬μΈνŠΈ 근처 μ„ ν˜Έ
627
- if(this.isNearStarPoint(row, col)) score += 3;
628
-
629
- return score;
630
- }
631
 
632
- countLiberties(group) {
633
- const liberties = new Set();
634
-
635
- for(const [row, col] of group) {
636
- const neighbors = this.getNeighbors(row, col);
637
- for(const [nRow, nCol] of neighbors) {
638
- if(this.board[nRow][nCol] === null) {
639
- liberties.add(`${nRow},${nCol}`);
640
- }
641
- }
642
  }
643
-
644
- return liberties.size;
645
- }
646
 
647
- canFormEye(row, col) {
648
- const neighbors = this.getNeighbors(row, col);
649
- let whiteCount = 0;
650
- let emptyCount = 0;
651
-
652
- for(const [nRow, nCol] of neighbors) {
653
- if(this.board[nRow][nCol] === 'white') whiteCount++;
654
- else if(this.board[nRow][nCol] === null) emptyCount++;
655
  }
656
-
657
- return whiteCount >= 2 && emptyCount >= 1;
658
  }
659
 
 
660
  isNearStarPoint(row, col) {
661
  const starPoints = [
662
  [3,3], [3,9], [3,15],
@@ -669,17 +564,6 @@ isNearStarPoint(row, col) {
669
  Math.abs(point[1] - col) <= 1
670
  );
671
  }
672
-
673
- areConnected(row1, col1, row2, col2) {
674
- const diagonal = Math.abs(row1 - row2) === 1 && Math.abs(col1 - col2) === 1;
675
- if(!diagonal) return true;
676
-
677
- // λŒ€κ°μ„  λ°©ν–₯ μ—°κ²° 확인
678
- const mid1 = this.board[row1][col2];
679
- const mid2 = this.board[row2][col1];
680
-
681
- return mid1 === null || mid2 === null;
682
- }
683
  }
684
 
685
  const game = new GoGame();
 
301
  }
302
 
303
  handleMove(e) {
304
+ const row = parseInt(e.target.dataset.row);
305
+ const col = parseInt(e.target.dataset.col);
306
 
307
+ // AI 차둀일 λ•ŒλŠ” ν”Œλ ˆμ΄μ–΄κ°€ λŒμ„ 놓을 수 μ—†μŒ
308
+ if (this.gameMode === 'ai' && this.currentPlayer === 'white') {
309
+ return;
310
+ }
311
 
312
+ if (this.isValidMove(row, col)) {
313
+ this.placeStone(row, col);
314
+
315
+ // AI 차둀일 λ•Œ μžλ™μœΌλ‘œ 돌 놓기
316
+ if (this.gameMode === 'ai' && this.currentPlayer === 'white') {
317
+ setTimeout(() => {
318
+ if (this.difficulty === 'easy') {
319
+ this.makeRandomMove();
320
+ } else {
321
+ this.makeStrategicMove();
322
+ }
323
+ }, 500);
324
  }
325
  }
326
+ }
327
 
328
  isValidMove(row, col) {
329
  if(this.board[row][col] !== null) return false;
 
493
 
494
  // GoGame 클래슀 λ‚΄μ˜ makeStrategicMove λ©”μ†Œλ“œλ₯Ό λ‹€μŒκ³Ό 같이 μˆ˜μ •
495
  makeStrategicMove() {
 
 
 
 
496
  let bestScore = -Infinity;
497
  let bestMove = null;
498
+
499
+ // λͺ¨λ“  κ°€λŠ₯ν•œ μœ„μΉ˜ 평가
500
+ for (let i = 0; i < this.size; i++) {
501
+ for (let j = 0; j < this.size; j++) {
502
+ if (this.isValidMove(i, j)) {
503
+ const score = this.evaluateMove(i, j);
504
+ if (score > bestScore) {
 
 
 
505
  bestScore = score;
506
  bestMove = [i, j];
507
  }
508
  }
509
  }
510
  }
511
+
512
+ // 졜적의 μœ„μΉ˜μ— 돌 놓기
513
+ if (bestMove) {
514
  this.placeStone(bestMove[0], bestMove[1]);
515
  } else {
516
  this.pass();
517
  }
518
  }
519
 
520
+ // μœ„μΉ˜ 평가λ₯Ό μœ„ν•œ λ©”μ†Œλ“œ μΆ”κ°€
521
+ evaluateMove(row, col) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
522
  let score = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
523
 
524
+ // 1. μ£Όλ³€ 돌 평가
 
525
  const neighbors = this.getNeighbors(row, col);
526
+ for (const [nRow, nCol] of neighbors) {
527
+ if (this.board[nRow][nCol] === 'white') score += 10;
528
+ else if (this.board[nRow][nCol] === 'black') score += 5;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
529
  }
 
 
 
530
 
531
+ // 2. ν¬μœ„ κ°€λŠ₯μ„± 평가
532
+ this.board[row][col] = 'white';
533
+ const captures = this.checkCaptures(row, col);
534
+ this.board[row][col] = null;
535
+ score += captures.length * 30;
 
 
 
 
 
 
 
536
 
537
+ // 3. 쀑앙 μ„ ν˜Έλ„
 
 
 
538
  const centerDistance = Math.abs(row - 9) + Math.abs(col - 9);
539
  score += Math.max(0, 10 - centerDistance);
 
 
 
 
 
 
 
 
 
540
 
541
+ // 4. μŠ€νƒ€ν¬μΈνŠΈ 근처 μ„ ν˜Έ
542
+ if (this.isNearStarPoint(row, col)) {
543
+ score += 5;
 
 
 
 
 
 
 
544
  }
 
 
 
545
 
546
+ // 5. κ°€μž₯자리 νšŒν”Ό
547
+ if (row === 0 || row === 18 || col === 0 || col === 18) {
548
+ score -= 5;
 
 
 
 
 
549
  }
550
+
551
+ return score;
552
  }
553
 
554
+ // μŠ€νƒ€ν¬μΈνŠΈ κ·Όμ²˜μΈμ§€ ν™•μΈν•˜λŠ” λ©”μ†Œλ“œ μΆ”κ°€
555
  isNearStarPoint(row, col) {
556
  const starPoints = [
557
  [3,3], [3,9], [3,15],
 
564
  Math.abs(point[1] - col) <= 1
565
  );
566
  }
 
 
 
 
 
 
 
 
 
 
 
567
  }
568
 
569
  const game = new GoGame();