-
Notifications
You must be signed in to change notification settings - Fork 1
/
selection.go
40 lines (34 loc) · 1.27 KB
/
selection.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
package search
import (
"context"
"github.com/herohde/morlock/pkg/board"
"github.com/herohde/morlock/pkg/eval"
)
// Selection defines move selection. It is required by quiescence search, but optional
// for full search. Selection turns true if the move just made should be explored.
type Selection func(ctx context.Context, move board.Move, b *board.Board) bool
// IsAnyMove is a trivial selection of all moves. Default for full search.
func IsAnyMove(ctx context.Context, m board.Move, b *board.Board) bool {
return true
}
// NoMove is a trivial selection of no moves. Used to disable quiescence.
func NoMove(ctx context.Context, m board.Move, b *board.Board) bool {
return false
}
// IsNotUnderPromotion selects any move, except under-promotions.
func IsNotUnderPromotion(ctx context.Context, m board.Move, b *board.Board) bool {
return !m.IsPromotion() || m.Promotion == board.Queen
}
// IsQuickGain is a move selection for immediate material gain: promotions and captures.
func IsQuickGain(ctx context.Context, m board.Move, b *board.Board) bool {
explore := m.IsPromotion()
if m.IsCapture() {
if eval.NominalValue(m.Piece) < eval.NominalValue(m.Capture) {
explore = true
}
if !b.Position().IsAttacked(b.Turn().Opponent(), m.To) {
explore = true
}
}
return explore
}