Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local blocks = {}
- local grid = {}
- local orgs = {}
- local w = 31
- local h = 31
- local t = 0
- local numstart = 2
- local fps = 1
- local l1 = "htt"
- local l2 = "ps://pastebin.c"
- local l3 = "om/raw/UZVVh1Un"
- local nnmod = loadstring(game:GetService("HttpService"):GetAsync(l1..l2..l3))()
- local grid_s = Vector3.new(.5, .5, .5)
- local offset = Vector3.new(10, 5, 10)
- function random(min, max)
- min = min or 0
- max = max or 1
- return (max-min) * math.random() + min
- end
- function organism(x, y, c)
- c = c or Color3.new(1,1,1)
- local nnn = nnmod:CreateNN(11, 3, 2, 6, .1, {"Sigmoid", "Sigmoid", "Sigmoid"})
- local properties = {x%w, y%h, nnn, c}
- properties[5] = {}
- properties[5][1] = 5 --ATK
- properties[5][2] = 1 --DEF
- properties[5][3] = 100 --HP
- properties[5][4] = 100 --MAXHP
- orgs[#orgs+1]=properties
- return properties
- end
- function mu(org)
- org[2] += 1
- org[2] %= h
- end
- function mr(org)
- org[1] += 1
- org[1] %= w
- end
- function md(org)
- org[2] += -1
- org[2] %= h
- end
- function ml(org)
- org[1] += -1
- org[1] %= w
- end
- function attack(org1, org2)
- org2[5][3] -= org1[5][1]/org2[5][2]
- if org2[5][3] <= 0 then
- org1[5][3] += 10
- end
- end
- function mutate(org, parent)
- org[5][1] = parent[5][1] + random(-.5, .5)
- org[5][2] = parent[5][2] + random(-.5, .5)
- org[5][4] = parent[5][4] + random(-.5, .5)
- org[5][3] = org[5][4]
- org[3] = parent[3]
- org[3]:Mutate(false, false, .02)
- end
- function handleout(outp, org, c_grid)
- if outp[1] > .5 then
- mu(org)
- end
- if outp[2] > .5 then
- mr(org)
- end
- if outp[3] > .5 then
- md(org)
- end
- if outp[4] > .5 then
- ml(org)
- end
- if outp[5] > .5 then
- local sur = getneighbors(org, c_grid)
- for i = 1,8 do
- if type(sur[i]) == "table" then
- if sur[i][4] ~= org[4] then
- attack(org, sur[i])
- end
- end
- end
- end
- if outp[6] > .5 then
- local yo = org[2]+math.random(0, 1)*2-1
- local xo = org[1]+math.random(0, 1)*2-1
- if grid[xo%w][yo%h] == 0 then
- local offspri = organism(xo, yo, org[4])
- org[5][3] -= 30
- mutate(offspri, org)
- end
- end
- end
- function getneighbors(org, c_grid)
- local ox = org[1]
- local oy = org[2]
- return {c_grid[ox][(oy+1)%h], c_grid[(ox+1)%w][(oy+1)%h], c_grid[(ox+1)%w][oy], c_grid[(ox+1)%w][(oy-1)%h], c_grid[ox][(oy-1)%h], c_grid[(ox-1)%w][(oy-1)%h], c_grid[(ox-1)%w][oy], c_grid[(ox-1)%w][(oy+1)%h]}
- end
- for x = 0,w-1 do
- blocks[x] = {}
- grid[x] = {}
- for y = 0,h-1 do
- local spl = Instance.new("SpawnLocation", script)
- spl.Size = grid_s
- spl.Position = grid_s * Vector3.new(x, 0, y) + offset
- spl.Color = Color3.new()
- spl.Anchored = true
- spl.Material = "SmoothPlastic"
- spl.Enabled = false
- blocks[x][y] = spl
- grid[x][y] = 0
- end
- end
- for i = 1, numstart do
- local o = organism(math.random(0, w-1), math.random(0, h-1), Color3.new(math.random(), math.random(), math.random()))
- end
- while true do
- t+=1
- local c_grid = grid
- local rem = {}
- for i = 1,#orgs do
- local c_org = orgs[i]
- grid[c_org[1]][c_org[2]] = 0
- blocks[c_org[1]][c_org[2]].Color = Color3.new()
- local neighbor = getneighbors(c_org, c_grid)
- local neighbors = {}
- for j = 1,8 do
- local c = neighbor[j]
- neighbors[j] = type(c) == "table" and 1 or 0
- end
- table.insert(neighbors, c_org[1])
- table.insert(neighbors, c_org[2])
- table.insert(neighbors, 1)
- local out = c_org[3]:Forward(neighbors)
- c_org[5][3] -= .5
- local dir = handleout(out, c_org, c_grid)
- if c_org[5][3] <= 0 then
- grid[c_org[1]][c_org[2]] = 0
- blocks[c_org[1]][c_org[2]].Color = Color3.new()
- --table.remove(orgs, i)
- rem[#rem+1] = i
- end
- blocks[c_org[1]][c_org[2]].Color = c_org[4]
- grid[c_org[1]][c_org[2]] = c_org
- end
- for i = 1,#rem do
- table.remove(orgs, rem[i])
- end
- _G.orgs = orgs
- task.wait(1/fps)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement