Skip to content

Commit 8d458f7

Browse files
check cancel channel before saving search results
1 parent f9e9064 commit 8d458f7

File tree

8 files changed

+34
-37
lines changed

8 files changed

+34
-37
lines changed

attack.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ func getSee(brd *Board, from, to int, capturedPiece Piece) int {
119119
// this move is illegal and will be discarded by search. return the lowest possible
120120
// SEE value so that this move will be put at end of list. If cutoff occurs before then,
121121
// the cost of detecting the illegal move will be saved.
122-
// TODO: send this in UCI-compatible format
123-
fmt.Println("king capture detected in getSee()!")
122+
123+
fmt.Println("info string king capture detected in getSee()!")
124124
return SEE_MIN
125125
}
126126
t = brd.TypeAt(from)

board.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ func (brd *Board) EvadesCheck(m Move) bool {
109109
// 8/PPKR4/1Bn4P/3P3R/8/2p4r/pp4p1/r6k w - - 5 2 (r h3h5 x r)...?
110110

111111
if threats == 0 {
112-
fmt.Println("EvadesCheck() called from non-check position!")
113-
m.Print()
114-
brd.PrintDetails()
112+
fmt.Println("info string EvadesCheck() called from non-check position!")
113+
// m.Print()
114+
// brd.PrintDetails()
115115
return true // no threats to evade.
116116
}
117117

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/pkg/profile"
1616
)
1717

18-
var version = "0.2.2"
18+
var version = "0.3.0"
1919

2020
func max(a, b int) int {
2121
if a > b {

pawn_hash.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ type PawnEntry struct {
1717
rightAttacks [2]BB
1818
allAttacks [2]BB
1919
passedPawns [2]BB
20-
value [2]int
21-
key uint32
22-
count [2]uint8
20+
value [2]int
21+
key uint32
22+
count [2]uint8
2323
}
2424

2525
func NewPawnTT() *PawnTT {

piece.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
package main
77

8-
const ( // type
9-
PAWN = iota
10-
KNIGHT
11-
BISHOP
12-
ROOK
13-
QUEEN
14-
KING
15-
EMPTY // no piece located at this square
8+
const (
9+
PAWN = iota
10+
KNIGHT // 1
11+
BISHOP // 2
12+
ROOK // 3
13+
QUEEN // 4
14+
KING // 5
15+
EMPTY // 6 no piece located at this square
1616
)
1717

1818
const (

search.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type Search struct {
4848
once sync.Once
4949
allowedMoves []Move
5050
bestScore [2]int
51-
sync.Mutex
51+
// sync.Mutex
5252
cancel chan bool
5353
bestMove, ponderMove Move
5454
gt *GameTimer
@@ -91,15 +91,15 @@ func NewSearch(params SearchParams, gt *GameTimer, uci *UCIAdapter, allowedMoves
9191
func (s *Search) sendResult() {
9292
// UCIInfoString(fmt.Sprintf("Search %d aborting...\n", search_id))
9393
s.once.Do(func() {
94-
s.Lock()
94+
// s.Lock()
9595
if s.uci != nil {
9696
if s.ponder {
9797
s.uci.result <- s.Result() // queue result to be sent when requested by GUI.
9898
} else {
9999
s.uci.BestMove(s.Result()) // send result immediately
100100
}
101101
}
102-
s.Unlock()
102+
// s.Unlock()
103103
})
104104
}
105105

@@ -159,35 +159,33 @@ func (s *Search) iterativeDeepening(brd *Board) int {
159159
inCheck := brd.InCheck()
160160

161161
for d := 1; d <= s.maxDepth; d++ {
162-
select {
163-
case <-s.cancel:
164-
return sum
165-
default:
166-
}
167162

168163
stk[0].inCheck = inCheck
169164
guess, total = s.ybw(brd, stk, s.alpha, s.beta, d, 0, Y_PV, SP_NONE, false)
170165
sum += total
171166

167+
select { // if the cancel signal was received mid-search, the current guess is not useful.
168+
case <-s.cancel:
169+
return sum
170+
default:
171+
}
172+
172173
if stk[0].pv.m.IsMove() {
173-
s.Lock()
174+
// s.Lock()
174175
s.bestMove, s.bestScore[c] = stk[0].pv.m, guess
175176
if stk[0].pv.next != nil {
176177
s.ponderMove = stk[0].pv.next.m
177178
}
178-
s.Unlock()
179+
// s.Unlock()
179180
stk[0].pv.SavePV(brd, d, guess) // install PV to transposition table prior to next iteration.
180181
} else {
181182
s.sendInfo("Nil PV returned to ID\n")
182183
}
183-
// nodes_per_iteration[d] += total
184184
if d >= COMMS_MIN && (s.verbose || s.uci != nil) { // don't print info for first few plies to reduce communication traffic.
185185
s.uci.Info(Info{guess, d, sum, s.gt.Elapsed(), stk})
186186
}
187187
}
188188

189-
// TODO: BUG: 'orphaned' workers occasionally still processing after ID loop
190-
191189
return sum
192190
}
193191

stack.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ type Stack []StackItem
1515

1616
type StackItem struct {
1717
hashKey uint64 // use hash key to search for repetitions
18-
eval int
19-
killers KEntry
18+
eval int
19+
killers KEntry
2020
singularMove Move
2121

2222
sp *SplitPoint
@@ -29,10 +29,10 @@ type StackItem struct {
2929
func (thisStk *StackItem) Copy() *StackItem {
3030
return &StackItem{
3131
// split point is not copied over.
32-
pv: thisStk.pv,
33-
killers: thisStk.killers,
32+
pv: thisStk.pv,
33+
killers: thisStk.killers,
3434
singularMove: thisStk.singularMove,
35-
eval: thisStk.eval,
35+
eval: thisStk.eval,
3636
hashKey: thisStk.hashKey,
3737
inCheck: thisStk.inCheck,
3838
canNull: thisStk.canNull,

utilities.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func RunTestSuite(testSuite string, depth, timeout int) {
3636
fmt.Printf("%d.", i+1)
3737
}
3838
sum += search.nodes
39+
// search.htable.PrintMax()
3940
}
4041
secondsElapsed := time.Since(start).Seconds()
4142
mNodes := float64(sum) / 1000000.0
@@ -44,8 +45,6 @@ func RunTestSuite(testSuite string, depth, timeout int) {
4445
fmt.Printf("Total score: %d/%d\n", score, len(test))
4546
fmt.Printf("Overhead: %.4fm\n", float64(loadBalancer.Overhead())/1000000.0)
4647
fmt.Printf("Timeout: %.1fs\n", float64(timeout)/1000.0)
47-
// fmt.Printf("PV Accuracy: %d/%d (%.2f)\n\n", pv_accuracy[1], pv_accuracy[0]+pv_accuracy[1],
48-
// float64(pv_accuracy[1])/float64(pv_accuracy[0]+pv_accuracy[1]))
4948
}
5049

5150
func correctMove(epd *EPD, moveStr string) bool {

0 commit comments

Comments
 (0)