Lonely Lion

Chris McAvoy likes kites

Ruby Bees

with one comment

I finished the Ruby implementation of my world famous Bee Simulator. It’s especially fun as it’s the first functional implementation. I’ve made starts in Perl, Python, and Rails, but gave up on each in turn. Feel free to read into that as you see fit.

I’m really happy with how the ultimate “Bee API” turned out. Here’s the Bee logic method in all its glory:

def tick
if @nectar > 0 and is_hive?
log("dumping nectar in hive")
deposit
return
elsif @nectar > 0
go(where_hive?)
return
end

if ! is_flower?
direction = Cardinal[rand(Cardinal.length)]
move.send(direction)
return
end
f = get_flower
log("found flower")
suck_nectar if f.has_nectar?
log("sucked nectar")
end

Kind of a neat API, in my humble opinion. It needs tweaked, but it’s good for now. I’d also like to give the Bee’s their own DSL, so that I can easily make this into a web app that lets users test their own theories of bee logic. If you want to take a look at the code, it’s available via subversion here: http://lonelylion.com/mcavoy_public/trunk/bee_ruby/

Written by Chris

July 7th, 2006 at 9:18 am

Posted in BeeSim,Projects,Ruby

  • http://www.multiply.org/ jason

    you should try this again in perl using Moose. Or try it using a functional language.

Switch to our mobile site