-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot-loader.lua
More file actions
102 lines (86 loc) · 2.33 KB
/
Copy pathbot-loader.lua
File metadata and controls
102 lines (86 loc) · 2.33 KB
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
local bot = require 'GaiAI'
local lume = require 'libs/lume'
local loader = {}
local function printf(f)
local rows = lume.split(f, '|')
log.info('>>>>>')
for _, v in ipairs(rows) do
if #v > 0 then
local row = ''
for i = #v, 1, -1 do
if v:sub(i, i) ~= ',' then
row = row .. (v:sub(i, i) == '0' and '_' or 'X')
end
end
log.trace(row)
end
end
log.info('<<<<<')
end
local loaded = ...
if loaded == true then
while true do
local requestChannel = love.thread.getChannel('request')
local request = requestChannel:pop()
if request == true then
local move = bot.move()
local producer = love.thread.getChannel('move')
producer:push(move)
end
end
else
local thinkFinished
local pathToThisFile = (...):gsub('%.', '/') .. '.lua'
local _move
local function getFinishedMoveIfAvailable()
local consumer = love.thread.getChannel('move')
local move = consumer:pop()
if move then
_move = move
if DEBUG then log.trace(move) end
thinkFinished()
end
end
function loader.start()
bot.configure(BOT_PARAMS['TSPINB2B'], BOT_HOLDALLOWED, BOT_ALLSPIN, BOT_TSDONLY, BOT_SEARCHWIDTH)
local thread = love.thread.newThread(pathToThisFile)
thread:start(true)
loader.thread = thread
end
function loader.updateBot(queue, curr, hold, field, combo, b2b, incoming)
-- printf(field)
bot.updatequeue(queue)
bot.updatecurrent(curr)
bot.updatehold(hold)
bot.updatefield(field)
bot.updatecombo(combo)
bot.updateb2b(b2b)
bot.updateincoming(incoming)
end
function loader.think(thinkFinishedCallback)
bot.updatethinking(true)
thinkFinished = thinkFinishedCallback or function() end
local request = love.thread.getChannel('request')
request:push(true)
end
function loader.terminate()
bot.updatethinking(false)
end
function loader.update()
if loader.thread then
if loader.thread:isRunning() and bot.alive() then
getFinishedMoveIfAvailable()
else
local errorMessage = loader.thread:getError()
assert(not errorMessage, errorMessage)
end
end
end
function loader.getMove()
return _move
end
function loader.findPath(field, piece, x, y, r, hold)
return bot.findPath(field, piece, x, y, r, hold)
end
return loader
end