forked from ebemunk/pgnstats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeatmap.go
67 lines (58 loc) · 1.18 KB
/
Heatmap.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
package main
import "github.com/malbrecht/chess"
//HeatSquare is a square on a chess board
type HeatSquare map[string]uint64
//Add increments the piece count of the square
func (hs HeatSquare) Add(piece chess.Piece) {
var key string
switch piece {
case chess.WK:
key = "K"
case chess.BK:
key = "k"
case chess.WQ:
key = "Q"
case chess.BQ:
key = "q"
case chess.WR:
key = "R"
case chess.BR:
key = "r"
case chess.WB:
key = "B"
case chess.BB:
key = "b"
case chess.WN:
key = "N"
case chess.BN:
key = "n"
case chess.WP:
key = "P"
case chess.BP:
key = "p"
}
hs[key]++
}
//Heatmap is a chessboard made up of 64 HeatSquares
type Heatmap [64]HeatSquare
//NewHeatmap returns an initialized Heatmap
func NewHeatmap() *Heatmap {
var hm Heatmap
for i := 0; i < 64; i++ {
hm[i] = make(HeatSquare)
}
return &hm
}
//Add adds two Heatmaps together
func (hm *Heatmap) Add(add *Heatmap) {
for i, square := range add {
for piece := range square {
hm[i][piece] += add[i][piece]
}
}
}
//Count increments the value for a given square and piece
func (hm *Heatmap) Count(piece chess.Piece, square chess.Sq) {
i := (7-square.Rank())*8 + square.File()
hm[i].Add(piece)
}