-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgn.go
99 lines (75 loc) · 1.38 KB
/
pgn.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
89
90
91
92
93
94
95
96
97
98
99
package pgn
type Game struct {
tags map[string]string
moves map[int]*Move
result string
}
func New(pgn string) (*Game, error) {
l := newLexer(pgn)
p := newParser(l)
game, err := p.ParsePGN()
if err != nil {
return nil, err
}
return game, nil
}
func (g *Game) GetTag(name string) string {
return g.tags[name]
}
func (g *Game) SetTag(tag, value string) {
g.tags[tag] = value
}
func (g *Game) TagPairs() map[string]string {
return g.tags
}
func (g *Game) Event() string {
return g.tags["Event"]
}
func (g *Game) Site() string {
return g.tags["Site"]
}
func (g *Game) Round() string {
return g.tags["Round"]
}
func (g *Game) Date() string {
return g.tags["Date"]
}
func (g *Game) White() string {
return g.tags["White"]
}
func (g *Game) Black() string {
return g.tags["Black"]
}
func (g *Game) Result() string {
return g.result
}
func (g *Game) SetResult(result string) {
g.result = result
}
func (g *Game) GetMove(number int) *Move {
return g.moves[number]
}
func (g *Game) SetMove(number int, move *Move) {
g.moves[number] = move
}
func (g *Game) Moves() map[int]*Move {
return g.moves
}
func (g *Game) IsDraw() bool {
if g.result == "1/2-1/2" {
return true
}
return false
}
func (g *Game) Winner() string {
if g.result == "1-0" {
return "White"
}
if g.result == "0-1" {
return "Black"
}
if g.result == "1/2-1/2" {
return "Draw"
}
return "Unknown"
}