diff --git a/ngochess/gtp/util.go b/ngochess/gtp/util.go new file mode 100644 index 0000000..b9e774c --- /dev/null +++ b/ngochess/gtp/util.go @@ -0,0 +1,31 @@ +package gtp + +import ( + "fmt" + "git.noahlan.cn/noahlan/ntool/nmath" + "strings" +) + +const alpha = "abcdefghjklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ" // 无 'I' 的alpha + +func Point(x, y int) string { + if x < 0 || x >= 50 || y < 0 || y >= 50 { + return "" + } + return fmt.Sprintf("%s%d", byteToString(alpha[x]), y+1) +} + +func byteToString(b byte) string { + return string([]byte{b}) +} + +func ParsePoint(pos string) (x, y int) { + x = byteToIndex(pos[0]) + y, _ = nmath.Int(pos[1:]) + y = y - 1 + return +} + +func byteToIndex(b byte) int { + return strings.Index(alpha, string([]byte{b})) +}