コンピュータープログラムにカードゲームをプレイさせるために、ミニマックス検索(アルファベータプルーニングを使用)、またはむしろネガマックス検索を使用したいと思います。
カードゲームは実際には4人のプレイヤーで構成されています。そこで、ミニマックス法などを使えるようにするために、ゲームを「他人」に対して「私」に単純化しています。それぞれの「移動」の後、ゲーム自体から現在の状態の評価を客観的に読み取ることができます。4人のプレイヤー全員がカードを置いたとき、最も高いプレイヤーがすべてのプレイヤーに勝ちます-そしてカードの値がカウントされます。
他の3人のプレイヤー間のカードの分配が正確にどのようになっているのかわからないので、自分のものではないカードですべての可能な分配(「世界」)をシミュレートする必要があると思いました。あなたは12枚のカードを持っています、他の3人のプレーヤーは合計で36枚のカードを持っています。
したがって、私のアプローチはこのアルゴリズムです。ここで、player
はプログラムが動きを見つける必要があるかもしれない3人のコンピュータープレーヤーを象徴する1から3の間の数字です。そして-player
、対戦相手、つまり他の3人のプレイヤー全員を表します。
private Card computerPickCard(GameState state, ArrayList<Card> cards) {
int bestScore = Integer.MIN_VALUE;
Card bestMove = null;
int nCards = cards.size();
for (int i = 0; i < nCards; i++) {
if (state.moveIsLegal(cards.get(i))) { // if you are allowed to place this card
int score;
GameState futureState = state.testMove(cards.get(i)); // a move is the placing of a card (which returns a new game state)
score = negamaxSearch(-state.getPlayersTurn(), futureState, 1, Integer.MIN_VALUE, Integer.MAX_VALUE);
if (score > bestScore) {
bestScore = score;
bestMove = cards.get(i);
}
}
}
// now bestMove is the card to place
}
private int negamaxSearch(int player, GameState state, int depthLeft, int alpha, int beta) {
ArrayList<Card> cards;
if (player >= 1 && player <= 3) {
cards = state.getCards(player);
}
else {
if (player == -1) {
cards = state.getCards(0);
cards.addAll(state.getCards(2));
cards.addAll(state.getCards(3));
}
else if (player == -2) {
cards = state.getCards(0);
cards.addAll(state.getCards(1));
cards.addAll(state.getCards(3));
}
else {
cards = state.getCards(0);
cards.addAll(state.getCards(1));
cards.addAll(state.getCards(2));
}
}
if (depthLeft <= 0 || state.isEnd()) { // end of recursion as the game is finished or max depth is reached
if (player >= 1 && player <= 3) {
return state.getCurrentPoints(player); // player's points as a positive value (for self)
}
else {
return -state.getCurrentPoints(-player); // player's points as a negative value (for others)
}
}
else {
int score;
int nCards = cards.size();
if (player > 0) { // make one move (it's player's turn)
for (int i = 0; i < nCards; i++) {
GameState futureState = state.testMove(cards.get(i));
if (futureState != null) { // wenn Zug gültig ist
score = negamaxSuche(-player, futureState, depthLeft-1, -beta, -alpha);
if (score >= beta) {
return score;
}
if (score > alpha) {
alpha = score; // alpha acts like max
}
}
}
return alpha;
}
else { // make three moves (it's the others' turn)
for (int i = 0; i < nCards; i++) {
GameState futureState = state.testMove(cards.get(i));
if (futureState != null) { // if move is valid
for (int k = 0; k < nCards; k++) {
if (k != i) {
GameState futureStateLevel2 = futureState.testMove(cards.get(k));
if (futureStateLevel2 != null) { // if move is valid
for (int m = 0; m < nCards; m++) {
if (m != i && m != k) {
GameState futureStateLevel3 = futureStateLevel2.testMove(cards.get(m));
if (futureStateLevel3 != null) { // if move is valid
score = negamaxSuche(-player, futureStateLevel3, depthLeft-1, -beta, -alpha);
if (score >= beta) {
return score;
}
if (score > alpha) {
alpha = score; // alpha acts like max
}
}
}
}
}
}
}
}
}
return alpha;
}
}
}
これはうまくいくようですが、深さが1(depthLeft=1
)の場合、プログラムはすでに平均50,000ムーブ(配置されたカード)を計算する必要があります。もちろん、これは多すぎます!
だから私の質問は:
- 実装はまったく正しいですか?このようなゲームをシミュレートできますか?特に不完全情報については?
- 速度と作業負荷のアルゴリズムをどのように改善できますか?
- たとえば、良い結果を維持しながら、可能な移動のセットを50%のランダムなセットに減らして、速度を向上させることはできますか?
- 私はUCTアルゴリズムが良い解決策であることに気づきました(多分)。このアルゴリズムを知っていますか?実装を手伝ってもらえますか?