-
Notifications
You must be signed in to change notification settings - Fork 3
/
engine.go
54 lines (46 loc) · 1.22 KB
/
engine.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
package engine
import (
"github.com/hmgle/godogpaw/alphabetasearch"
"github.com/sirupsen/logrus"
)
type Engine struct {
p *Position
}
func (e *Engine) GetInfo() (name, version, author string) {
return "godogpaw", "0.1", "hmgle"
}
func (e *Engine) Prepare() {
}
func (e *Engine) Position(fen string) {
e.p = NewPositionByFen(fen)
}
func (e *Engine) Move(movDsc string) {
e.p.MakeMoveByDsc(movDsc)
}
func (e *Engine) Search(depth uint8) (movDesc string, score int) {
val := e.p.Evaluate()
logrus.WithFields(logrus.Fields{
"val": val,
}).Debugf("搜索前局面估值")
bestMov, score := alphabetasearch.SearchMain(e.p, depth, -(kingVal + 100), kingVal+100)
// mov := Move(bestMov)
// from, to := mov.From(), mov.To()
{ // XXX DEBUG
e.p.MakeMove(bestMov)
val = e.p.Evaluate()
logrus.WithFields(logrus.Fields{
"val": val,
"redStrengthVal": e.p.redStrengthVal,
"blackStrengthVal": e.p.blackStrengthVal,
"redPstVal": e.p.redPstVal,
"blackPstVal": e.p.blackPstVal,
}).Debugf("搜索后执行着法后的局面估值")
if bestMov != 0 {
e.p.UnMakeMove(bestMov)
}
}
return Move(bestMov).String(), score
}
func (e *Engine) Perft(depth uint) (nodes int) {
return e.p.Perft(depth)
}