You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ntool-biz/ngochess/gtp/util.go

39 lines
738 B
Go

package gtp
import (
"fmt"
"git.noahlan.cn/noahlan/ntool/nmath"
"strings"
)
const alpha = "abcdefghjklmnopqrstuvwxyz" // 无 'I' 的alpha
const alphaUpper = "ABCDEFGHJKLMNOPQRSTUVWXYZ"
func Point(x, y int) string {
if x < 0 || x >= 25 || y < 0 || y >= 25 {
return "PASS"
}
return fmt.Sprintf("%s%d", byteToString(alphaUpper[x]), y+1)
}
func byteToString(b byte) string {
return string([]byte{b})
}
func ParsePoint(pos string) (x, y int) {
if strings.ToUpper(pos) == "PASS" {
return 255, 255
}
x = byteToIndex(alpha, pos[0])
if x == -1 {
x = byteToIndex(alphaUpper, pos[0])
}
y, _ = nmath.Int(pos[1:])
y = y - 1
return
}
func byteToIndex(str string, b byte) int {
return strings.Index(str, string([]byte{b}))
}