/
file.go
55 lines (48 loc) · 837 Bytes
/
file.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 core
import "fmt"
// A File is a column on the chess board.
type File uint64
// File constants.
const (
FileA File = iota
FileB
FileC
FileD
FileE
FileF
FileG
FileH
)
func (f File) String() string {
switch f {
case FileA:
return "FileA"
case FileB:
return "FileB"
case FileC:
return "FileC"
case FileD:
return "FileD"
case FileE:
return "FileE"
case FileF:
return "FileF"
case FileG:
return "FileG"
case FileH:
return "FileH"
default:
return fmt.Sprintf("File(%d)", f)
}
}
func (f File) Valid() bool {
return f >= FileA && f <= FileH
}
// Left returns the file to the left of f, wrapping around if necessary.
func (f File) Left() File {
return (f - 1) % 8
}
// Right returns the file to the right of f, wrapping around if necessary.
func (f File) Right() File {
return (f + 1) % 8
}