-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove.go
65 lines (56 loc) · 1.63 KB
/
move.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
package chess
// A MoveTag represents a notable consequence of a move.
type MoveTag uint16
const (
// KingSideCastle indicates that the move is a king side castle.
KingSideCastle MoveTag = 1 << iota
// QueenSideCastle indicates that the move is a queen side castle.
QueenSideCastle
// Capture indicates that the move captures a piece.
Capture
// EnPassant indicates that the move captures via en passant.
EnPassant
// Check indicates that the move puts the opposing player in check.
Check
// inCheck indicates that the move puts the moving player in check and
// is therefore invalid.
inCheck
)
// A Move is the movement of a piece from one square to another.
type Move struct {
parent *Move
position *Position // Position after the move
nag string
comments string
command map[string]string // Store commands as key-value pairs
children []*Move // Main line and variations
number uint
tags MoveTag
s1 Square
s2 Square
promo PieceType
}
// String returns a string useful for debugging. String doesn't return
// algebraic notation.
func (m *Move) String() string {
return m.s1.String() + m.s2.String() + m.promo.String()
}
// S1 returns the origin square of the move.
func (m *Move) S1() Square {
return m.s1
}
// S2 returns the destination square of the move.
func (m *Move) S2() Square {
return m.s2
}
// Promo returns promotion piece type of the move.
func (m *Move) Promo() PieceType {
return m.promo
}
// HasTag returns true if the move contains the MoveTag given.
func (m *Move) HasTag(tag MoveTag) bool {
return (tag & m.tags) > 0
}
func (m *Move) addTag(tag MoveTag) {
m.tags |= tag
}