-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCritic.lua
More file actions
149 lines (144 loc) · 3.73 KB
/
Critic.lua
File metadata and controls
149 lines (144 loc) · 3.73 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
require('./AI/Const')
local Actor = require('./AI/USER_AI/Actor')
local Array = require('./AI/USER_AI/Array')
local Set = require('./AI/USER_AI/Set')
-- Env class: Begin
local Env = {}
Env.new = function(class, servant, config)
local obj = {}
obj.clock = GetTick()
obj.cache = {}
do
local master = GetV(V_OWNER, servant)
-- Allocation
local keyed = {}
local whole = Array:new()
local other = Array:new()
local amity = Array:new()
local beast = Array:new()
for index, value in ipairs(GetActors(servant)) do
if value and 0 < value then
local actor = Actor:new(value)
keyed[value] = actor
whole:push(actor)
if not actor:getID() then
-- nil
elseif actor:getID() == master then
obj.master = actor
elseif actor:getID() == servant then
obj.servant = actor
elseif actor:isMonster() then
beast:push(actor)
elseif false then
amity:push(actor)
else
other:push(actor)
end
end
end
obj.servant = obj.servant or Actor.new(servant)
obj.master = obj.master or Actor.new(master)
obj.keyed = keyed
obj.whole = whole
obj.beast = beast
obj.amity = amity
obj.other = other
end
return setmetatable(obj, {__index=class})
end
Env.getClock = function(self)
return self.clock
end
Env.getWhole = function(self)
return self.whole
end
Env.getActorByID = function(self, id)
return self.keyed[id]
end
Env.getActorsByPosition = function(self, ground)
return self.whole:filter(function(actor)
return actor:getPosition() == ground
end)
end
Env.getMaster = function(self)
return self.master
end
Env.getMasterID = function(self)
return self:getMaster():getID()
end
Env.getServant = function(self)
return self.servant
end
Env.getServantID = function(self)
return self:getServant():getID()
end
Env.getPeerDistance = function(self, p)
local servant = self:getServant()
local master = self:getMaster()
return servant and master and servant:getDistanceToTarget(master, p)
end
Env.getBeast = function(self)
return self.beast
end
Env.getAmity = function(self)
return self.amity
end
Env.getOther = function(self)
return self.other
end
Env.getTargetOf = function(self, hero)
return self:getActorByID(hero:getTargetID())
end
Env.getThreatOf = function(self, hero)
local id = hero:getID()
return self:getWhole():filter(function(actor)
return actor:getTargetID() == id
end)
end
Env.getLegion = function(self)
local masterID = self:getMasterID()
return self:getBeast():filter(function(actor)
return actor:getMasterID() == masterID and actor:isLegion()
end)
end
Env.getPlants = function(self)
local masterID = self:getMasterID()
return self:getBeast():filter(function(actor)
return actor:getMasterID() == masterID and actor:isPlants()
end)
end
Env.getSphere = function(self)
local masterID = self:getMasterID()
return self:getBeast():filter(function(actor)
return actor:getMasterID() == masterID and actor:isSphere()
end)
end
Env.tostring = function(self, visit)
local check = visit or Set:new()
local index = check:insert(self)
return string.format('Env<table %d> {clock=%d, whole=%d}', index, self.clock, #whole)
end
-- Env class: End
-- Critic class: Begin
local Critic = {}
Critic.new = function(class)
return setmetatable({}, {__index=class, __tostring=class.tostring})
end
Critic.store = function(self)
return self
end
Critic.restore = function(self)
return self
end
Critic.observe = function(self, servant)
return Env:new(servant, self.config)
end
Critic.execute = function(self, cmd, env)
end
Critic.tostring = function(self, visit)
local check = visit or Set:new()
local index = check:insert(self)
return string.format('Critic<table %d> {}', index)
end
-- Critic class: End
return Critic