-
Notifications
You must be signed in to change notification settings - Fork 18
/
marshal.go
55 lines (52 loc) · 1.08 KB
/
marshal.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
package pgn
import (
"encoding/gob"
"os"
)
type exportedBoard struct {
WPawns uint64
BPawns uint64
WRooks uint64
BRooks uint64
WKnights uint64
BKnights uint64
WBishops uint64
BBishops uint64
WQueens uint64
BQueens uint64
WKings uint64
BKings uint64
LastMove Move
WCastle CastleStatus
BCastle CastleStatus
ToMove Color
Fullmove int
HalfmoveClock int
}
func (b *Board) Save(path string) error {
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()
var eb exportedBoard
eb.WPawns = b.wPawns
eb.BPawns = b.bPawns
eb.WRooks = b.wRooks
eb.BRooks = b.bRooks
eb.WKnights = b.wKnights
eb.BKnights = b.bKnights
eb.WBishops = b.wBishops
eb.BBishops = b.bBishops
eb.WQueens = b.wQueens
eb.BQueens = b.bQueens
eb.WKings = b.wKings
eb.BKings = b.bKings
eb.LastMove = b.lastMove
eb.WCastle = b.wCastle
eb.BCastle = b.bCastle
eb.ToMove = b.toMove
eb.Fullmove = b.fullmove
eb.HalfmoveClock = b.halfmoveClock
return gob.NewEncoder(file).Encode(eb)
}