-
Notifications
You must be signed in to change notification settings - Fork 2
/
train.go
52 lines (41 loc) · 1.21 KB
/
train.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
package solver
import (
"fmt"
"time"
log "github.com/igrek51/log15"
"github.com/igrek51/connect4solver/solver/common"
)
func Train(width, height, winStreak int, cacheEnabled bool) {
board := common.NewBoard(common.WithSize(width, height), common.WithWinStreak(winStreak))
fmt.Println(board.String())
solver := CreateSolver(board)
if cacheEnabled && common.CacheFileExists(board) {
common.MustLoadCache(solver.Cache(), board.W, board.H)
}
startTime := time.Now()
endings := solver.MovesEndings(board)
totalElapsed := time.Since(startTime)
logger := log.New(log.Ctx{
"solveTime": totalElapsed,
"boardWidth": width,
"boardHeight": height,
"winStreak": winStreak,
})
logger.Info("Board solved", solver.SummaryVars())
player := board.NextPlayer()
for move, ending := range endings {
if ending != common.NoMove {
playerEnding := common.EndingForPlayer(ending, player)
log.Info(fmt.Sprintf("Best ending for move %d: %v", move, playerEnding))
}
}
fmt.Println(board.String())
printEndingsLine(endings, player)
if cacheEnabled {
common.MustSaveCache(solver.Cache(), board.W, board.H)
}
totalElapsed = time.Since(startTime)
log.Info("Done", log.Ctx{
"totalTime": totalElapsed,
})
}