一,檢查MCTS代碼
```
getBestUCTChild() {
const C = 3600; // 探索常數,配合你的遊戲分數(100, 150)量級調整
let bestValue = -Infinity;
let bestChild = null;
// 若當前節點是 AI 行動,選擇分數最大化;若是對手行動,對手會選擇讓 AI 分數最小化的路線
const isAI = this.state.player === currentPlayer;
for (const child of this.children) {
if (child.visits === 0) return child;
const expectedScore = child.totalScore / child.visits;
const exploration = C * Math.sqrt(Math.log(this.visits) / child.visits);
let uctValue;
if (isAI) {
uctValue = expectedScore + exploration; // AI 期望最大化
} else {
uctValue = -expectedScore + exploration; // 對手期望最小化 AI 分數
}
if (uctValue > bestValue) {
bestValue = uctValue;
bestChild = child;
}
}
return bestChild;
}
```
以上是其它程式的代碼,它其中包含了:
```
if (isAI) {
uctValue = expectedScore + exploration; // AI 期望最大化
} else {
uctValue = -expectedScore + exploration; // 對手期望最小化 AI 分數
}
```
那為何本程式不作這個判定?會否發生錯誤?
為何其它程式的「探索常數」會達到3600?本程式的探索常數達到多少比較合適?
二,去掉所有跟「分差縮放分母」和「節點最低訪問次數」的代碼。
「節點最低訪問次數」等同於設為1(只要去掉,默認就是1)。
需要明確給出所要修改的地方和所要替換的代碼。
代码: 全选
修復和改進:
一,檢查MCTS代碼
```
getBestUCTChild() {
const C = 3600; // 探索常數,配合你的遊戲分數(100, 150)量級調整
let bestValue = -Infinity;
let bestChild = null;
// 若當前節點是 AI 行動,選擇分數最大化;若是對手行動,對手會選擇讓 AI 分數最小化的路線
const isAI = this.state.player === currentPlayer;
for (const child of this.children) {
if (child.visits === 0) return child;
const expectedScore = child.totalScore / child.visits;
const exploration = C * Math.sqrt(Math.log(this.visits) / child.visits);
let uctValue;
if (isAI) {
uctValue = expectedScore + exploration; // AI 期望最大化
} else {
uctValue = -expectedScore + exploration; // 對手期望最小化 AI 分數
}
if (uctValue > bestValue) {
bestValue = uctValue;
bestChild = child;
}
}
return bestChild;
}
```
以上是其它程式的代碼,它其中包含了:
```
if (isAI) {
uctValue = expectedScore + exploration; // AI 期望最大化
} else {
uctValue = -expectedScore + exploration; // 對手期望最小化 AI 分數
}
```
那為何本程式不作這個判定?會否發生錯誤?
為何其它程式的「探索常數」會達到3600?本程式的探索常數達到多少比較合適?
二,去掉所有跟「分差縮放分母」和「節點最低訪問次數」的代碼。
「節點最低訪問次數」等同於設為1(只要去掉,默認就是1)。
需要明確給出所要修改的地方和所要替換的代碼。