-
Notifications
You must be signed in to change notification settings - Fork 0
/
player_mathe.go
43 lines (38 loc) · 1.17 KB
/
player_mathe.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
package atlantis
import (
"fmt"
)
type Mathe struct {
}
func (m Mathe) NextBoard(b *Board, player int) *Board {
_, bestBoard := m.findMaxWalze(b, player, 2 /* maxDepth */, 0 /* depth */) // Look 2 moves deep.
return bestBoard
}
// Will look 'maxDepth' moves deep (minimum: 1) to find the most long-term-explosive next move possible.
func (m Mathe) findMaxWalze(b *Board, player, maxDepth, depth int) (bestScore float64, bestBoard *Board) {
// Recursive case: we must go deeper.
if depth < maxDepth {
evaluateNextBoard := func(t Turn) {
valid, b2 := DoMoves(b, t)
if !valid {
panic(fmt.Sprintf("Bad turn generated: %v on %v", t, *b))
}
DoAllTopplesAndGrow(b2, player)
score, _ := m.findMaxWalze(b2, player, maxDepth, depth+1)
if score > bestScore {
bestScore = score
bestBoard = b2
}
}
ForEveryPossibleTurn(b, player, evaluateNextBoard)
return
}
// Base case: we've reached maxDepth, do the actual evaluation.
// Evaluation criterium: maximum number of growing points, maximum number of dead points.
for _, point := range b.Points {
if point.IsDead || (point.HasTower() && point.Tower.IsGrowingPoint) {
bestScore += 1.0
}
}
return
}