-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChineseCheckerMoronAgent.java
More file actions
72 lines (51 loc) · 1.85 KB
/
Copy pathChineseCheckerMoronAgent.java
File metadata and controls
72 lines (51 loc) · 1.85 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// I.Q. scores for moron: 50-70/75
public class ChineseCheckerMoronAgent implements BoardGameAgent {
final int maximumExpansionCount;
ChineseCheckerMoronAgent(int maximumExpansionCount)
{
this.maximumExpansionCount = maximumExpansionCount;
}
@Override
public int estimateDepth(BoardState boardState, Player player)
{
return 1;
}
@Override
public long estimateExpansionCount(BoardState boardState, int m, Player player)
{
return 1;
}
@Override
public double getUtility(BoardState boardState, Player player)
{
ChineseCheckerState chineseCheckerState = (ChineseCheckerState)boardState;
// utility 1
Point2D playerCog = chineseCheckerState.calculateCenterOfGravity(player);
Point2D opponentRegionCog = (player == Player.One ? chineseCheckerState.player2cog : chineseCheckerState.player1cog);
Point2D delta = Point2D.subtract(opponentRegionCog, playerCog);
double utility1 = 1.0 / (1.0 + delta.manhattan());
// utility 2
Player opponent = player.getOpponent();
int playerInplaceCount = 0;
int opponentInplaceCount = 0;
for (int y=0; y<chineseCheckerState.boardSize; y++) {
for (int x=0; x<chineseCheckerState.boardSize; x++) {
if (chineseCheckerState.initialBoardCells[y][x] == opponent && chineseCheckerState.boardCells[y][x] == player) {
playerInplaceCount++;
}
if (chineseCheckerState.initialBoardCells[y][x] == player && chineseCheckerState.boardCells[y][x] == opponent) {
opponentInplaceCount++;
}
}
}
double utility2 = (1.0 + playerInplaceCount) / (1.0 + opponentInplaceCount);
// combined utility
double combinedUtility = (1.0 + utility1) * (1.0 + utility2);
return combinedUtility;
}
@Override
public String toString()
{
return "Moron Agent 50 < IQ < 70/75";
}
}