-
Notifications
You must be signed in to change notification settings - Fork 0
/
ready_move.lua
54 lines (44 loc) · 2.05 KB
/
ready_move.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
54
local vector_sequence = require("vector_sequence")
local straight_sequence = require("straight_sequence")
local ready_move = {
_class = "ready_move",
min_len = 3,
is_long_enough = function(self, path)
if type(path) ~= "table" then return false end
return (#path >= self.min_len)
end,
find = function(self, field, point)
local vertical, horizontal = self:find_vertical(field, point), self:find_horizontal(field, point)
if (not vertical) and (not horizontal) then return false end
-- объединение на редкий случай вертикальной и горизонтальной тройки
local path = vector_sequence(vertical or {})
path:push(horizontal or {})
return path.list
end,
-- выглядит как позор, но времени править это нет
find_left = function(self, field, position)
local path = straight_sequence:find_left(field, position) or {}
return (self:is_long_enough(path) and path) or false
end,
find_right = function(self, field, position)
local path = straight_sequence:find_right(field, position) or {}
return (self:is_long_enough(path) and path) or false
end,
find_top = function(self, field, position)
local path = straight_sequence:find_top(field, position) or {}
return (self:is_long_enough(path) and path) or false
end,
find_down = function(self, field, position)
local path = straight_sequence:find_down(field, position) or {}
return (self:is_long_enough(path) and path) or false
end,
find_vertical = function(self, field, position)
local path = straight_sequence:find_vertical(field, position) or {}
return (self:is_long_enough(path) and path) or false
end,
find_horizontal = function(self, field, position)
local path = straight_sequence:find_horizontal(field, position) or {}
return (self:is_long_enough(path) and path) or false
end,
}
return ready_move