makingthematrix / gailibrary

A very cheerful library for Artificial Intelligence in games
MIT License
7 stars 0 forks source link

feat: An alternate implementation of a Langton's Ant #47

Closed makingthematrix closed 5 years ago

makingthematrix commented 5 years ago
This implementation is based on the design I came up with while preparing for
a talk about Cellular Automata at Scala.IO 2018:
https://github.com/makingthematrix/ca_art
The most notable difference is how the neighborhood of the cell is retrieved:
In Rust this is done through a trait implemented by the Board, instead of
passing a function from the board to the cell. Rust requires the developer
to take care of lifetimes of everything that goes into the context, which makes
passing functions much harder than in Scala.

On the brighter note, this implementation does not use Rc! Whooo!
In general it's simpler and more FP-style than the old one. It's more limited:
What was the container (`Arena`) and the graph of spatial relations (`Grid`)
is now one `Board`, and the cells can access only cells of the same type.
But I think that with this approach I will at some point come back to the idea
of `Arena`/`Graph` distinction and it will be more mature. I think in the old
implementation I came up with it too early and that held me back for a long time.

Nevertheless, I decided to keep the old implementation. The code was moved to
the `engine` module, and the `langtonsant` module now contains examples of
the ants running in both implementations.