From 72693f13193f014841214b79c7e1798121303d82 Mon Sep 17 00:00:00 2001 From: NoahLan <6995syu@163.com> Date: Mon, 18 Dec 2023 15:54:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0gtp=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ngochess/gtp/util.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 ngochess/gtp/util.go 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})) +}