-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluator.go
85 lines (72 loc) · 2.16 KB
/
evaluator.go
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
73
74
75
76
77
78
79
80
81
82
83
84
85
// Package evaluator gives functions that gives heuristic value of a Board structure
package main
// coinParity return an integer representing the coin parity ranged from -100 to 100
// given the pointer of a board state
func coinParity(position *Board) int {
boardSize := BoardSize
maxCounter := 0
minCounter := 0
for i := 1; i < boardSize-1; i++ {
for j := 1; j < boardSize-1; j++ {
if position.Board[i][j] == 'B' {
minCounter++
} else if position.Board[i][j] == 'W' {
maxCounter++
}
}
}
if maxCounter+minCounter != 0 {
return 100 * (maxCounter - minCounter) / (maxCounter + minCounter)
}
return 0
}
// mobility return an integer representing the number of moves possible ranged from -100 to 100
// given the pointer of a board state
func mobility(position *Board) int {
var maxCounter, minCounter int
maxCounter = position.GetMoves().Len()
position.ChangeMaxPlayer()
minCounter = position.GetMoves().Len()
position.ChangeMaxPlayer()
if maxCounter+minCounter != 0 {
return 100 * (maxCounter - minCounter) / (maxCounter + minCounter)
}
return 0
}
// cornersCaptured return an integer representing the possession of corners between -100 and 100
// given the pointer of a board state
func cornersCaptured(position *Board) int {
var maxCounter, minCounter int
if position.Board[1][1] == 'B' {
minCounter++
} else if position.Board[1][1] == 'W' {
maxCounter++
}
if position.Board[8][8] == 'B' {
minCounter++
} else if position.Board[8][8] == 'W' {
maxCounter++
}
if position.Board[8][1] == 'B' {
minCounter++
} else if position.Board[8][1] == 'W' {
maxCounter++
}
if position.Board[1][8] == 'B' {
minCounter++
} else if position.Board[1][8] == 'W' {
maxCounter++
}
if maxCounter+minCounter != 0 {
return 100 * (maxCounter - minCounter) / (maxCounter + minCounter)
}
return 0
}
/* Evaluate returns an integer, representing a heuristic evaluation of the postion. */
func Evaluate(position *Board) int {
// coin parity
mobilityIndex := mobility(position)
coinParityIndex := coinParity(position)
cornersCapturedIndex := cornersCaptured(position)
return mobilityIndex*100 + coinParityIndex*20 + cornersCapturedIndex*800
}