The little dots are using an evolutionary algorithm to learn how to reach the goal with the least number of steps. They start off moving in completely random directions, but get better over generations as the evolutionary algorithm favors the ones that manage to get closer to the goal. These "fitter" dots reproduce by generating new dots that move like their parents with slight random alterations, hopefully getting even closer to the goal.

Once a dot manages to reach the goal, their fitness is determined by the number of steps they took to get there. This way, evolution can help the population of dots find a more efficient way to reach the goal.

Based on Code Bullet's tutorial, but implemented in p5.js and extended. Code on GitHub.