[Mod] Game of Life [Experimental]

User avatar
Jordach
Member
 
Posts: 4523
Joined: Mon Oct 03, 2011 17:58
Location: Blender Scene
GitHub: Jordach
IRC: Jordach
In-game: Jordach

[Mod] Game of Life [Experimental]

by Jordach » Mon Nov 02, 2015 23:11

Hello all, as you've noticed, I've been working on a copy of Conway's Game of Life within Minetest.

However, due to how ABMs work, this code fails to work properly. It does, however, have configuration.

Secondly, there is no current way to start and stop ABMs from functioning due to Minetest's limited abilities.

Code: Select all
-- Game of Life, WTFPL

-- configure game board height:

grid_height = 20

-- configure tick time

tick_timer = 4 -- in seconds

-- register me some nodes

minetest.register_node("gol:life", {
   description = "GoL default rules",
   tiles = {"default_grass.png"},
   groups = {cracky=3},
   --sounds = default.node_sounds_defaults(),
})

minetest.register_node("gol:dead", {
   description = "GoL default dead cell",
   tiles = {"default_dirt.png"},
   groups = {cracky=3},
   --sounds = default.node_sounds_defaults(),
})

-- create the rules with ABMs.

minetest.register_abm({
   nodenames = {"gol:life"},
   interval = tick_timer,
   chance = 1,
   action = function(pos)
      if pos.y ~= grid_height then
         return
      end
      
      if pos == nil then
         return
      end
      
      local surround_count = 0   
      
      for z=-1,1 do
         
         for x=-1,1 do
            local node = minetest.get_node({pos.x+x, pos.y, pos.z+z})
            
            if node.name == "gol:dead" then
               surround_count = surround_count+1
            end
            
            if pos.x+x == pos.x and pos.z+z == pos.z then
               surround_count = surround_count - 1
               minetest.chat_send_all("center point found")
            end
         end
      end
      
      if surround_count == 2 or surround_count == 3 then
         --minetest.set_node(pos, {name="gol:life"})
         return
      end
      
      if surround_count > 3 then
         minetest.set_node(pos, {name="gol:dead"})
         return
      end

      if surround_count < 2 then
         minetest.set_node(pos, {name="gol:dead"})
         return
      end
   end,
})

minetest.register_abm({
   nodenames = {"gol:dead"},
   interval = tick_timer,
   chance = 1,
   action = function(pos)
      if pos.y ~= grid_height then
         return
      end
      
      if pos == nil then
         return
      end
      
      local surround_count = 0   
      
      for z=-1,1 do
         for x=-1,1 do
            local node = minetest.get_node({pos.x+x, pos.y, pos.z+z})
            
            if node.name == "gol:life" then
               surround_count = surround_count+1
            end
            
            if pos.x+x == pos.x and pos.z+z == pos.z then
               surround_count = surround_count - 1
               --minetest.chat_send_all("center point found")
            end
         end
      end

      if surround_count == 3 then
         minetest.set_node(pos, {name="gol:life"})
         return
      end
   end,
})


To install this experimental mod, create a folder called gol, and a file called init.lua -- copy and paste the code into it, enable the mod via configure world - and it should run.

Dependancies:

Default, for textures.
viewtopic.php?f=10&t=19056 Solar Plains Dev Server
 

User avatar
qwertymine3
Member
 
Posts: 202
Joined: Wed Jun 03, 2015 14:33
GitHub: Qwertymine
In-game: qwertymine3

Re: [Mod] Game of Life [Experimental]

by qwertymine3 » Tue Nov 03, 2015 00:50

To 'disable' the abm you could just change all of the affected blocks into unaffected blocks, and back to 'reactive' - not very elegant, but shouldn't be to bad with the voxelmanipulator
Avatar by :devnko-ennekappao:
 


Return to WIP Mods



Who is online

Users browsing this forum: MSN [Bot], Nathan.S and 4 guests