-
Notifications
You must be signed in to change notification settings - Fork 14
/
generate_quiets.go
88 lines (76 loc) · 2.43 KB
/
generate_quiets.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2014-2018 by Michael Dvorkin. All Rights Reserved.
// Use of this source code is governed by a MIT-style license that can
// be found in the LICENSE file.
//
// I am making my contributions/submissions to this project solely in my
// personal capacity and am not conveying any rights to any intellectual
// property of any third parties.
package donna
func (gen *MoveGen) addQuiet(move Move) *MoveGen {
gen.list[gen.tail].move = move
gen.list[gen.tail].score = game.good(move)
gen.tail++
return gen
}
// Generates pseudo-legal moves that preserve material balance, i.e.
// no captures or pawn promotions are allowed.
func (gen *MoveGen) generateQuiets() *MoveGen {
p := gen.p
color := p.color
empty := ^p.board
// Castles.
if !p.isInCheck(color) {
home := homeKing[color]
kingside, queenside := p.canCastle(color)
if kingside {
gen.addQuiet(NewCastle(p, home, home + 2))
}
if queenside {
gen.addQuiet(NewCastle(p, home, home - 2))
}
}
// Pawns.
last := let(color == White, 7, 0)
for bm := p.outposts[pawn(color)].up(color) & empty & ^maskRank[last]; bm.any(); bm = bm.pop() {
square := bm.first()
forward, backward := square + up[color], square - up[color]
if rank(color, square) == 2 && p.pieces[forward].none() {
gen.addQuiet(NewPawnMove(gen.p, backward, forward)) // Jump.
}
gen.addQuiet(NewPawnMove(gen.p, backward, square)) // Push.
}
// Knights.
for bm := p.outposts[knight(color)]; bm.any(); bm = bm.pop() {
square := bm.first()
for bm := knightMoves[square] & empty; bm.any(); bm = bm.pop() {
gen.addQuiet(NewMove(p, square, bm.first()))
}
}
// Bishops.
for bm := p.outposts[bishop(color)]; bm.any(); bm = bm.pop() {
square := bm.first()
for bm := p.bishopMoves(square) & empty; bm.any(); bm = bm.pop() {
gen.addQuiet(NewMove(p, square, bm.first()))
}
}
// Rooks.
for bm := p.outposts[rook(color)]; bm.any(); bm = bm.pop() {
square := bm.first()
for bm := p.rookMoves(square) & empty; bm.any(); bm = bm.pop() {
gen.addQuiet(NewMove(p, square, bm.first()))
}
}
// Queens.
for bm := p.outposts[queen(color)]; bm.any(); bm = bm.pop() {
square := bm.first()
for bm := (p.bishopMoves(square) | p.rookMoves(square)) & empty; bm.any(); bm = bm.pop() {
gen.addQuiet(NewMove(p, square, bm.first()))
}
}
// King.
square := p.king[color]
for bm := (kingMoves[square] & empty); bm.any(); bm = bm.pop() {
gen.addQuiet(NewMove(p, square, bm.first()))
}
return gen
}