Hawk-Dove game in Julia

Joe Moeller

Tue Aug 29 2023

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


Owen Lynch

Tue Aug 29 2023

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.

Joe Moeller

Thu Aug 31 2023

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?

Joe Moeller

Thu Aug 31 2023

Ok, I just did your multiple dispatch idea.

Kris Brown

Thu Aug 31 2023

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

Owen Lynch

Thu Aug 31 2023

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.