I implemented this in Rust some years back. It is connected to some serious research mathematics (see f.ex https://www.ams.org/notices/201008/rtx100800976p.pdf)
https://github.com/FredrikMeyer/abeliansandpile