私は単純なゲームのためにnegamaxを実装しようとしています。合計を21勝に上げるプレーヤー。 3.単純加算ゲームのためのNegamax
私はないんだけど、コンピュータを簡単に0モッズに合計合同になる数を追加することで勝つ必要がありますので、https://en.wikipedia.org/wiki/Negamax#Negamax_base_algorithmが
人間のプレイヤーが最初に移動します。私はここに擬似コードを使用してい
ダイナミックムーブの生成を行います。ランダム合計に1を加えたネガマックススコアとネガマスクスコアを比較して、ラン合計に2を加算するだけです。
int total = 0;
Console.WriteLine("the current total is " + total);
while (total < 21) {
Console.WriteLine("add 1 or 2?");
total += Convert.ToInt32(Console.ReadLine());
Console.WriteLine("you increased the total to " + total);
if (total == 21) {
Console.WriteLine("you win");
break;
}
if (negamax(total + 1, 1) > negamax(total + 2, 1)) total++;
else total += 2;
Console.WriteLine("computer increased the total to " + total);
if (total == 21) {
Console.WriteLine("computer wins");
break;
}
}
negamax機能:
static int negamax(int total, int color) {
if (total == 21) {
return color * 100;
}
int bestValue = -100;
for (int i = 1; i <= 2; i++) {
if (total + i <= 21) {
int v = -1 * negamax(total + i, -1 * color);
bestValue = max(bestValue, v);
}
}
return bestValue;
}
マックス方法:AIはちょうど2たびに追加されている理由
static int max(int a, int b) {
if (a > b) return a;
return b;
}
わかりません。
あなたの 'max'メソッドを表示できますか? – stuartd
投稿に追加 –