summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid McMackins II <contact@mcmackins.org>2017-07-04 09:08:11 -0500
committerDavid McMackins II <contact@mcmackins.org>2017-07-04 09:08:11 -0500
commitfb1c39a829b0fec1c62760dd42eabb28194e6489 (patch)
tree5a9bc222325750766865be79a4c48e27c20c1734
parentc83456e1b1cc66e575bf9c4d75c630ee87b368da (diff)
Incremental update to MOVE processing
-rw-r--r--serverthread.lua26
1 files changed, 22 insertions, 4 deletions
diff --git a/serverthread.lua b/serverthread.lua
index 48d78d1..cf9574d 100644
--- a/serverthread.lua
+++ b/serverthread.lua
@@ -73,9 +73,11 @@ function Server:_resetgame()
self._updatequeue[1] = { 'CLEARBOARD' }
self._updatequeue[2] = { 'CLEARBOARD' }
for i,piece in ipairs(self._pieces) do
+ piece.id = i
+
for _,queue in ipairs(self._updatequeue) do
- queue:insert('PIECE ' .. i .. ' ' .. piece.x .. ' ' .. piece.y .. ' '
- .. piece.team)
+ table.insert(queue, 'PIECE ' .. i .. ' ' .. piece.x .. ' ' .. piece.y
+ .. ' ' .. piece.team)
end
end
@@ -228,8 +230,15 @@ function Server:_process()
else
self._selected = nil
self._socks[this]:send(AFFIRMATIVE)
+
+ for _,queue in ipairs(self._updatequeue) do
+ table.insert(queue, 'DESELECTED')
+ end
end
- elseif line:startswith('TRYMOVE') then
+ elseif (line:startswith('TRYMOVE')
+ or line:startswith('TRYSPLIT')
+ or line:startswith('MOVE')
+ or line:startswith('SPLIT')) then
line = line:split(' ')
if self._turn ~= this or not self._selected then
self._socks[this]:send(NEGATIVE)
@@ -242,9 +251,18 @@ function Server:_process()
if not dx or not dy then
self._socks[this]:send(ERR_SYNTAX)
else
- local move = self:_getmove(dx, dy, false)
+ local split = line[1] == 'TRYSPLIT' or line[1] == 'SPLIT'
+ local move = self:_getmove(dx, dy, split)
self._socks[this]:send(
table.concat({'Y', move.x, move.y, 'END'}, '\n'))
+
+ if not line[1]:startswith('TRY') then
+ for _,queue in ipairs(self._updatequeue) do
+ table.insert(queue, line[1] .. ' ' .. self._selected.id
+ .. ' ' move.x .. ' ' .. move.y)
+ table.insert(queue, 'DESELECTED')
+ end
+ end
end
end
elseif line == 'FORFEIT' then