Conway's Game of Life

I’ve been trying to get my 14 year old son interested in programming and I think starting out writing some plugins would actually be a fun introduction to programming in general.

He is intrigued by Conway’s Game of Life and the many online versions of this “game”.

I’m wondering if anyone has ever seen a version that runs inside of SketchUp as a plugin/extension.

I think it might be an interesting project for him to try and create a simple plugin that runs Conway’s Game of Life inside of SketchUp.

I don’t know about Conway’s but if your son likes Harry Potter, this might just be the right Christmas/New Year present. Being a huge HP fan myself, I wish I could have this at an earlier time of my life. Now, sadly too old for this, haha.

1 Like

Conway’s Game of Life or Saturday Night Fever, I’m not sure which:

If the grid is much bigger than 20x20 it really slows down, at least on my computer.

Something like this probably needs to run at a lower level than the Ruby API.

My code is below:

### Conway Gameboard ####

model = Sketchup.active_model
entities = model.active_entities
@view = model.active_view
@faces = []

@cycles = 0
ysize = 18
xsize = 18
blk = 12

model.start_operation('Generate Game Board', true, false, true)

for j in 0..(ysize-1)

	for i in 0..(xsize-1)
		i2 = i + 1
		j2 = j + 1
		pt1 = [(i*blk),(j*blk),0]
		pt2 = [(i2*blk),(j*blk),0]
		pt3 = [(i2*blk),(j2*blk),0]
		pt4 = [(i*blk),(j2*blk),0]
		face1 = entities.add_face(pt1, pt2, pt3, pt4)
		
		face1.reverse! if (rand(4)<2)

		@faces << face1
	end
end

model.commit_operation


def calc_conway

	@update_array = []

	for facei in @faces
	
		adj_live_count = 0
		
		if facei.normal.samedirection? Z_AXIS
			facei_status = true
		else
			facei_status = false
		end
	
		adj_faces_list = @faces.find_all { |e| !facei.bounds.intersect(e.bounds).empty? }
		adj_faces_list.delete(facei)
		
		for face_adj in adj_faces_list
			if face_adj.normal.samedirection? Z_AXIS
				adj_live_count += 1
			end	
		end
	
		if facei_status
			# Cell is Live
			if adj_live_count < 2
				@update_array << true
			elsif adj_live_count < 4
				@update_array << false
			else
				@update_array << true
			end
		else
			# Cell is Dead
			if adj_live_count == 3
				@update_array << true
			else
				@update_array << false
			end
		end
	end

	counter = 0
	for facei in @faces
		if @update_array[counter]
			facei.reverse!
		end
		counter += 1
	end

	@view.refresh
	@cycles += 1

	if @cycles > 200
		UI.stop_timer(@conwaytimer)
	end
end


model.start_operation('Run Game of Life', true, false, true)

@conwaytimer = UI.start_timer(0.02, true) { calc_conway }

model.commit_operation
1 Like

This is a good example of complex emergent behavior given simple rules. Not to dissimilar from the chemistry that governs life.

This little exercise has kind of got my wheels turning some more. Maybe it would be possible to code my artificial life project using SketchUp and the API as the virtual 3D world…

1 Like

maybe your son could update this old example game…

javascript controlled from the keyboard drives the the knight in a choice of 3 environments…

It’s to big to u/l here so PM an email address and I’ll send my copy, if you want…

john

4 Likes

There is an option were he could build and program a game in Ruby. It runs on Mac or Windows not in SketchUp itself. BUT all the modeling and 2D images for the sprite sheets can be done in SketchUp. Also if you have Layout you can assemble the sheets with it. They also provide a link to free assets to help get the scenes up and running …

You are still using Ruby as the base and doubling up on things. Learning coding / programming and learning to use SketchUp. You have two shared experiences possibly making to easier to grasp and help keeping his interest up. It cost me $15 but it is an investment

https://pragprog.com/book/msgpkids/learn-game-programming-with-ruby

They have another one to build Mazes but I have not looked into that one, it is also on the same site…

ProgMaze

…Peace…

1 Like

Game of Life brings back a lot of pleasant memories for me. The Game of Life is a very fond memory for me but really not that great of a game for me because of you just spin the spinner and kind of see what happens with a few choices. here’s the best replacement game for life is Lost Inca Gold Free is about walking down into this temple looking for treasure and split it equally and at any point, you can leave.

you can download this game here: https://androidcrew.com/app/air.LostIncaGoldFree

Did any try this out?

1 Like