This repository has been archived by the owner on Mar 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgtpclient.go
111 lines (105 loc) · 3.05 KB
/
gtpclient.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package gtp
import (
"fmt"
"strings"
)
type GTPClient struct {
conn *GTPConnection
protocol_version string
Result string
}
func NewGtpClient(conn *GTPConnection) *GTPClient {
util := GTPClient{}
util.conn = conn
go conn.GetOtherInfo(func(r string) {
util.Result=r
})
ver, _ := conn.Exec("protocol_version")
if strings.Contains(ver, "ERROR") {
util.protocol_version = ver
} else {
util.protocol_version = "2"
}
return &util
}
func (self GTPClient) KnowCommand(cmd string) (bool) {
value, err := self.conn.Exec("known_command " + cmd)
if err != nil {
return false
}
if strings.ToLower(strings.TrimSpace(value)) != "true" {
return false
}
return true
}
func (self GTPClient) GenMove(color string) (string, error) {
color = strings.ToUpper(color)
command := "black"
if color == "B" {
command = "black"
} else if color == "W" {
command = "white"
}
command = "genmove " + command
return self.conn.Exec(command)
}
func (self GTPClient) Komi(komi float32) (string, error) {
return self.conn.Exec(fmt.Sprintf("komi %d", komi))
}
func (self GTPClient) Custom(com string) (string, error) {
return self.conn.Exec(com)
}
func (self GTPClient) Handicap(handicap int) (string, error) {
return self.conn.Exec(fmt.Sprintf("fixed_handicap %d", handicap))
}
func (self GTPClient) Move(color, coor string) (string, error) {
color = strings.ToUpper(color)
command := "black"
if color == "B" {
command = "black"
} else if color == "W" {
command = "white"
}
return self.conn.Exec(fmt.Sprintf("play %s %s", command, coor))
}
func (self GTPClient) LoadSgf(file string, move int) (string, error) {
command := fmt.Sprintf("loadsgf %s", file)
return self.conn.Exec(command)
}
func (self GTPClient) FinalStatusList(cmd string) (string, error) {
command := fmt.Sprintf("final_status_list %s", cmd)
return self.conn.Exec(command)
}
func (self GTPClient) SetLevel(seed int) (string, error) {
command := fmt.Sprintf("level %d", seed)
return self.conn.Exec(command)
}
func (self GTPClient) SetRandomSeed(seed int) (string, error) {
command := fmt.Sprintf("set_random_seed %d", seed)
return self.conn.Exec(command)
}
func (self GTPClient) BoardSize(size int) (string, error) {
command := fmt.Sprintf("boardsize %d", size)
return self.conn.Exec(command)
}
func (self GTPClient) ShowBoard() (string, error) {
return self.conn.Exec("showboard")
}
func (self GTPClient) ClearBoard() (string, error) {
return self.conn.Exec("clear_board")
}
func (self GTPClient) PrintSgf() (string, error) {
return self.conn.Exec("printsgf")
}
func (self GTPClient) TimeSetting(baseTime, byoTime, byoStones int) (string, error) {
return self.conn.Exec(fmt.Sprintf("time_settings %d %d %d", baseTime, byoTime, byoStones))
}
func (self GTPClient) KGSTimeSetting(mainTime, readTime, readLimit int) (string, error) {
return self.conn.Exec(fmt.Sprintf("kgs-time_settings byoyomi %d %d %d", mainTime, readTime, readLimit))
}
func (self GTPClient) FinalScore() (string, error) {
return self.conn.Exec("final_score")
}
func (self GTPClient) Quit() (string, error) {
return self.conn.Exec("Quit")
}