-
Notifications
You must be signed in to change notification settings - Fork 0
/
goban.go
64 lines (52 loc) · 937 Bytes
/
goban.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
package main
import (
"strings"
)
// Status enum
type Status int
const (
WHITE Status = iota
BLACK
EMPTY
OUT
)
// Goban grid
type Goban struct {
grid [][]string
}
// NewGoban returns a new goban
func NewGoban(input []string) Goban {
goban := Goban{grid: make([][]string, 0, len(input))}
for _, line := range input {
goban.grid = append(goban.grid, strings.Split(line, ""))
}
return goban
}
// GetStatus Get the status of a given position
//
// Args:
// x: the x coordinate
// y: the y coordinate
//
// Returns:
// Status
func (goban Goban) GetStatus(x int, y int) Status {
if len(goban.grid) == 0 {
return OUT
}
if x < 0 || y < 0 || y >= len(goban.grid) || x >= len(goban.grid[0]) {
return OUT
}
switch goban.grid[y][x] {
case "#":
return BLACK
case "o":
return WHITE
case ".":
return EMPTY
}
panic("GetStatus")
}
func (goban Goban) IsTaken(x int, y int) bool {
panic("Not implemented")
}