-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstraight_sequence_old.lua
More file actions
35 lines (29 loc) · 1 KB
/
straight_sequence_old.lua
File metadata and controls
35 lines (29 loc) · 1 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
local maf = require("lib.maf")
local vector_sequence = require("vector_sequence")
local straight_sequence = {
_class = "straight_sequence",
is_valid = function(self)
local direction_match_counter = maf.vector(0,0)
local last_vector
for _, vector in pairs (self.list) do
if last_vector then
local increment = maf.vector(((last_vector.x == vector.x) and 1) or 0, ((last_vector.y == vector.y) and 1) or 0)
direction_match_counter = direction_match_counter + increment
end
last_vector = vector
end
return ((direction_match_counter.x + 1) == #self.list) or ((direction_match_counter.y + 1) == #self.list)
end
}
setmetatable(straight_sequence, {
__index = vector_sequence,
__call = function(self, list)
local object = {
list = {}
}
setmetatable(object, { __index = straight_sequence })
object:push(list or {})
return object
end
})
return straight_sequence