othelloゲームでAIの次の動きをシミュレートしたいのですが、次の動きを返す代わりに、クローンをシミュレートするのではなく、ゲームが終了する。クローンでのAlpha-betaプルーニングがJavaでない場合
public class GameState implements Cloneable{
private Node[][] board; // Game board
private int scorePlayer, scoreAI; // Player scores (will start at 0)
private ArrayList<Node> validNodes; // List holding all nodes possible to add pieces to
/**
* Creates the game state
*/
public GameState(){
// create size x size board
this.board = new Node[Setting.BOARD_SIZE][Setting.BOARD_SIZE];
validNodes = new ArrayList<>();
scorePlayer = 0;
scoreAI = 0;
protected GameState clone() {
return new GameState(this);
}------------------------ CLONE METHOD----------------
public int search(GameState board, Player player, int alpha, int beta, int depth, ScoreEval function) {
int record = Integer.MIN_VALUE;
Node maxMove = null;
int result;
GameState subBoard = board.clone();
if (depth <= 0 || board.getValidMoves().size()==0) {
record = function.evaluate(board, player);
} else {
ArrayList<Node> possibleMoves = board.getValidMoves();
if (!possibleMoves.isEmpty()) {
for (int i =0; i<possibleMoves.size();i++) {
Node nod = possibleMoves.get(i);
subBoard = board.clone();
subBoard.setPiece(nod.x,nod.y, player.type);
if(player.type==Setting.TILE_AI){
result = -search(subBoard, aiAss1.Controller.pHum, alpha, beta, depth - 1, function);
}
else{
result = -search(subBoard, aiAss1.Controller.pAI, alpha, beta, depth - 1, function);
}
if (result > record) {
record = result;
maxMove = nod;
}
}
} else {
record = -search(subBoard, player, alpha, beta, depth - 1, function);
}
}
bestMove = maxMove;
return record;
}
ボードの内部状態をコピーしていますか? (すべての変更可能なオブジェクト) –
'clone()'メソッドが壊れています。あなたは浅いコピーを作成している可能性が最も高いです。 – Kayaman
'GameState'の' clone'の実装を追加してください – QBrute