Java minimax abalone implementation -
i want implement minimax in abalone game don't know how it. exact don't know when algo need max or min player. if have understand logic, need min player , max ai ?
this wikipedia pseudo code
function minimax(node, depth, maximizingplayer) if depth = 0 or node terminal node return heuristic value of node if maximizingplayer bestvalue := -∞ each child of node val := minimax(child, depth - 1, false)) bestvalue := max(bestvalue, val); return bestvalue else bestvalue := +∞ each child of node val := minimax(child, depth - 1, true)) bestvalue := min(bestvalue, val); return bestvalue (* initial call maximizing player *) minimax(origin, depth, true)
and implementation
private integer minimax(board board, integer depth, color current, boolean maximizingplayer) { integer bestvalue; if (0 == depth) return ((current == selfcolor) ? 1 : -1) * this.evaluateboard(board, current); integer val; if (maximizingplayer) { bestvalue = -inf; (move m : board.getpossiblemoves(current)) { board.apply(m); val = minimax(board, depth - 1, current, boolean.false); bestvalue = math.max(bestvalue, val); board.revert(m); } return bestvalue; } else { bestvalue = inf; (move m : board.getpossiblemoves(current)) { board.apply(m); val = minimax(board, depth - 1, current, boolean.true); bestvalue = math.min(bestvalue, val); board.revert(m); } return bestvalue; } }
and evaluate function
private integer evaluateboard(board board, color player) { return board.ballscount(player) - board.ballscount(player.other()); }
it depends on evaluation function; in case, assuming goal have more balls on board opponent, player maximizing & ai minimizing.
Comments
Post a Comment