-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeuristic.java
37 lines (34 loc) · 1.3 KB
/
Heuristic.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class Heuristic {
private static final int[][] SCORE_GRID = {
{100, -20, 10, 5, 5, 10, -20, 100},
{-20, -50, -2, -2, -2, -2, -50, -20},
{10, -2, 5, 1, 1, 5, -2, 10},
{5, -2, 1, 0, 0, 1, -2, 5},
{5, -2, 1, 0, 0, 1, -2, 5},
{10, -2, 5, 1, 1, 5, -2, 10},
{-20, -50, -2, -2, -2, -2, -50, -20},
{100, -20, 10, 5, 5, 10, -20, 100}
};
/**
* Evaluates the Othello board for the given player.
*
* @param board 2D array representing the board.
* Assume 1 represents the player's discs, -1 represents the opponent's discs, and 0 represents empty squares.
* @param player The player for whom the evaluation is being calculated (1 or -1).
* @return The evaluation score of the board.
*/
public static int evaluateBoard(int[][] board, int player, int opponent) {
int score = 0;
// Loop through the board and calculate the score
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (board[i][j] == player) {
score += SCORE_GRID[i][j];
} else if (board[i][j] == opponent) {
score -= SCORE_GRID[i][j];
}
}
}
return score;
}
}