Let’s Make Some Bees Swarm
Make a new C++ project and add SFML—which you saw here—so you can draw the bees buzzing. The code with this book has a Bees static library for the algorithm. This is called by a unit test project and a main project named ABC. Make the library first, and feel free to add tests as you go. The tests aren’t shown here.
Code Your ABC
Start by defining a Coordinate class:
| struct Coordinate |
| { |
| double x; |
| double y; |
| }; |
You need a Bee class with a home, current position, a favored food spot, and a role. They start out at home. Add a buzz to drive how far the bees move each time. You’ll fill in the remaining parts to this shortly:
| class Bee |
| { |
| public: |
| explicit Bee(Role role, ... |
Get Genetic Algorithms and Machine Learning for Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.