Hawk-Dove game in Julia

I blogged about my first real attempt at programming something in Julia. I’d love to hear your thoughts.

3 Likes

This is awesome! Can you put this on github somewhere?

One thing you could try doing with this is to have two structs:

mutable struct Hawk
  health::Int
end

mutable struct Dove
  health::Int
end

and then implement the various interactions using multiple dispatch instead of having a big if/else statement. This would allow you to add a third type of bird without having to change the code of fight.

Also, I wonder this could be turned into a proper agent-based model with @kris-brown’s stuff.

3 Likes

ok, I put it on GitHub:

I like the multiple dispatch idea. I’ll do that today.

Can you point me to the agent-based stuff you’re talking about?

Ok, I just did your multiple dispatch idea.

Owen’s referring to what I talked about in this presentation (some links to full examples at the end, also this blog post) which is implemented in AlgebraicRewriting.jl

Neat! Two more trivial pieces of feedback.

  1. It’s good practice to include types of function arguments, even if you don’t technically need to, for documentation’s sake.
  2. Generally, functions are lowercase: see the Julia style guide for more details.