-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.lua
53 lines (50 loc) · 1.18 KB
/
util.lua
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
function flags()
if arg and #arg > 0 then
for i, v in ipairs(arg) do
if v == "--help" or v == "-h" then
help()
love.event.quit()
return
-- if v == "--sgf" end
-- if v == "--size" end
-- if v == "--version" end
end
end
end
end
function help()
print("dango.lua - a cross platform, lightweight Go board")
print(" Usage: love ./ [options]")
print(" Options:")
print(" --help Show this help message")
end
-- A1 --> 1-1
-- NOTE 'i' is skipped for traditional reasons
function gtp_from_engine(string)
if not string then
return false
end
local alpha, num = string:match("([A-Z])(%d+)")
if not alpha or not num then
return false
end
local x
local y = tonumber(num)
if alpha > "I" then
x = string.byte(alpha) - string.byte("A")
else
x = string.byte(alpha) - string.byte("A") + 1
end
return x, y
end
-- 1-1 --> A1
function gtp_to_engine(x, y)
local alpha
local num = tostring(y)
if x <= string.byte("I") - string.byte("A") then
alpha = string.char(string.byte("A") + x - 1)
else
alpha = string.char(string.byte("A") + x)
end
return alpha .. num
end