I have coded some q-learning, and when i tryed to start enviroment and print it i got an error…
Here is script code:
local Env = require(script['Enviroment'])
local Actor = require(script['Actor'])
local Agent = require(script['Agent'])
w = Env.new(7)
w:play() -- here error
w:print()
Here is enviroment full code:
Code
local Enviroment = {}
local Actor = require(script['Parent']['Actor'])
local Agent = require(script['Parent']['Agent'])
local Enemy = require(script['Parent']['Enemy'])
function Enviroment.new(n)
local self = setmetatable({}, Enviroment)
self.n = n
self.P = Agent.new(Actor, 1, 1, self.n)
self.ens = {Enemy.new(Actor,3,3,self.n), Enemy.new(Actor,4,4,self.n), Enemy.new(Actor,5,5,self.n)}
return self
end
function Enviroment:step()
for i, en in pairs(self.ens) do
en:move()
end
self.P:move()
end
function Enviroment:print()
for i=1, 100 do print("\n") end
local pvector = self.P:getXY()
local wmap = {}
for j=1, self.n do
wmap[j] = {}
for i=1, self.n do
wmap[j][i] = 0
end
end
self.wmap = wmap
self.wmap[pvector.x][pvector.y] = 1
for i, en in pairs(self.ens) do
local evector = en:getXY()
self.wmap[evector.x][evector.y] = 2
end
for i, v in pairs(self.wmap) do
print(v)
end
end
function Enviroment:play()
local pvector = self.P:getXY()
local bl = true
for i, en in pairs(self.ens) do
local evector = en:getXY()
bl = bl and pvector ~= evector
end
local iter = 0
while bl do
wait(1)
self:print()
self:step()
local pvector = self.P:getXY()
bl = true
for i, en in pairs(self.ens) do
local evector = en:getXY()
bl = bl and pvector ~= evector
print(pvector, " | ", evector)
end
print("______")
iter = iter + 1
end
print(iter)
end
return Enviroment
Anybody can help me?
I think error in function play, in while loop, but maybe not