public int Evaluate(Board.Board board, int evaluatingPlayer) { int score = 0; int winningPositionFor = board.CheckTerminalPosition(); int signum = evaluatingPlayer == 0 ? 1 : -1; if (winningPositionFor == 0) { score += 1000; } if (winningPositionFor == 1) { score -= 1000; } score = score * signum; score = score + CountGoldCaptures(board) * GOLD_CAPTURES_WEIGHT * signum + CountSilverCaptures(board) * SILVER_CAPTURES_WEIGHT * signum + CalculateSouthBias(board) * SOUTH_BIAS_WEIGHT / board.width * signum + CalculateFlagshipLiberties(board) * FLAGSHIP_LIBERTY_WEIGHT * signum; return(score); }
public int Evaluate(Board.Board board, int searchingPlayer) { int score = 0; int winningPositionFor = board.CheckTerminalPosition(); if (winningPositionFor == 0) { score += 1000; } if (winningPositionFor == 1) { score -= 1000; } score = searchingPlayer == 0 ? score : (score * -1); return(score); }
private int AB(ref Board.Board board, int alpha, int beta, int depth) // maybe can implement minimal search window and deep pruning by giving alpha and beta as reference { if (depth == 0 || board.CheckTerminalPosition() >= 0) { return(evaluationHeuristic.Evaluate(board, board.activePlayer) + random.Next(-randomRange, randomRange)); } LinkedList <(int, int)> moves = board.GetLegalMoves(); if (moves.Count == 0) { return(evaluationHeuristic.Evaluate(board, board.activePlayer) + random.Next(-randomRange, randomRange)); } int score = int.MinValue / 2; int value = score; foreach ((int, int)move in moves) { board.Move(move); if (board.remainingActions <= 1) { value = AB(ref board, Math.Max(alpha, score), beta, depth - 1); } else { value = -AB(ref board, -1 * beta, -1 * Math.Max(alpha, score), depth - 1); } if (value > score) { score = value; } board.Undo(); if (score > beta) { break; } } return(score); }
public int Evaluate(Board.Board board, int evaluatingPlayer) { int score = 0; int winningPositionFor = board.CheckTerminalPosition(); int signum = evaluatingPlayer == 0 ? 1 : -1; if (winningPositionFor == 0) { score += 1000; } if (winningPositionFor == 1) { score -= 1000; } score = score * signum; score += (JudgeMaterialBalance(board) * MATERIAL_BALANCE_WEIGHT * signum); return(score); }
private int AB(ref Board.Board board, int alpha, int beta, int depth) // maybe can implement minimal search window and deep pruning by giving alpha and beta as reference { if (depth == 0) { //selective deepening in case of captures, might want to extend to other more or less forcing moves ("check", looming escpae) // right now seems to slow down the calculations considerably, if tt doesnt help, might consider also to simplify it to only search recapturing sequences if (board.captures.Count > 0 && board.captures.Last.Value.Item1 == (board.turnCounter - 1)) { int selectScore = int.MinValue / 2; int selectValue = selectScore; LinkedList <(int, int)> forcingMoves = board.GetForcingMoves(); foreach ((int, int)move in forcingMoves) { board.Move(move); if (board.remainingActions <= 1) { selectValue = AB(ref board, Math.Max(alpha, selectScore), beta, 0); } else { selectValue = -AB(ref board, -1 * beta, -1 * Math.Max(alpha, selectScore), 0); } if (selectValue > selectScore) { selectScore = selectValue; } board.Undo(); if (selectScore > beta) { break; } } return(selectScore); } return(evaluationHeuristic.Evaluate(board, board.activePlayer) + random.Next(-randomRange, randomRange)); } if (depth == 0 || board.CheckTerminalPosition() >= 0) { return(evaluationHeuristic.Evaluate(board, board.activePlayer) + random.Next(-randomRange, randomRange)); } LinkedList <(int, int)> moves = board.GetLegalMoves(); if (moves.Count == 0) { return(evaluationHeuristic.Evaluate(board, board.activePlayer) + random.Next(-randomRange, randomRange)); } int score = int.MinValue / 2; int value = score; foreach ((int, int)move in moves) { board.Move(move); if (board.remainingActions <= 1) { value = AB(ref board, Math.Max(alpha, score), beta, depth - 1); } else { value = -AB(ref board, -1 * beta, -1 * Math.Max(alpha, score), depth - 1); } if (value > score) { score = value; } board.Undo(); if (score > beta) { break; } } return(score); }