Java – alpha beta mobile sort
I have an alpha- β The basic implementation of pruning, but I don't know how to improve the moving order I've seen that it can be done with shallow search, iterative deepening, or storing the best conversion tables
What are the suggestions on how to implement one of these improvements in this algorithm?
public double alphaBetaPruning(Board board,int depth,double alpha,double beta,int player) { if (depth == 0) { return board.evaluateBoard(); } Collection<Move> children = board.generatePossibleMoves(player); if (player == 0) { for (Move move : children) { Board tempBoard = new Board(board); tempBoard.makeMove(move); int nextPlayer = next(player); double result = alphaBetaPruning(tempBoard,depth - 1,alpha,beta,nextPlayer); if ((result > alpha)) { alpha = result; if (depth == this.origDepth) { this.bestMove = move; } } if (alpha >= beta) { break; } } return alpha; } else { for (Move move : children) { Board tempBoard = new Board(board); tempBoard.makeMove(move); int nextPlayer = next(player); double result = alphaBetaPruning(tempBoard,nextPlayer); if ((result < beta)) { beta = result; if (depth == this.origDepth) { this.bestMove = move; } } if (beta <= alpha) { break; } } return beta; } } public int next(int player) { if (player == 0) { return 4; } else { return 0; } }
Solution
>Reordering nodes using shallow search is trivial: calculation
Sort should precede this [in if and else clauses]
For (move: children) {> storage movement is also insignificant - many states are calculated twice. When you complete the calculation of any state, store it [depth calculation of] is very important in HashMap! The first thing you do is when you start the calculation at the vertex - check whether the calculation already exists - if so, return the cached value. The idea behind this is that many countries can arrive from different paths, so this method - you can eliminate redundant calculation
These changes should be completed in the first line of the method [like if (cache,...) ((state, board, depth, player)) returning cache.get (new state (board, player))] please forgive me for my lack of elegance and efficiency - just explain an idea here] You should also add cache before each return statement put(…).