Ruby Bees
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/
-
http://www.multiply.org/ jason
