Darwin Neuroevolution Framework
Public Member Functions | List of all members
pong::Pong Class Reference

Domain: The classic Pong game. More...

#include <pong.h>

Inheritance diagram for pong::Pong:
darwin::Domain core::NonCopyable

Public Member Functions

size_t inputs () const override
 Number of inputs to a Brain.
 
size_t outputs () const override
 Number of outputs from a Brain.
 
bool evaluatePopulation (darwin::Population *population) const override
 Assigns fitness values to every genotype. More...
 
- Public Member Functions inherited from darwin::Domain
virtual unique_ptr< core::PropertySetcalibrateGenotype ([[maybe_unused]] const Genotype *genotype) const
 Optional: additional fitness metrics (normally not used in the population evaluation, ie a test set)
 

Detailed Description

Domain: The classic Pong game.

This is an implementation of the classic 2-player Pong game: each player controlls a paddle (which can be moved up or down). The ball bounces off the walls, and if it goes behind the paddle line, the other player scores a point.

pong_sandbox.png

All the population members participate in a tournament and the outcomes are used to calculate the individual fitness values.

Inputs

Input Value
0 my_paddle_pos
1 opponent_paddle_pos
2 ball_x
3 ball_y
4 ball_vx
5 ball_vy

Outputs

Output Value
0 move_up
1 move_down

The largest output signal determines the player action at the current step. If none of the output values is larger than 0, then the default action is "do nothing".

Member Function Documentation

◆ evaluatePopulation()

bool pong::Pong::evaluatePopulation ( darwin::Population population) const
overridevirtual

Assigns fitness values to every genotype.

Having a good fitness function is a key part of evolutionary algorithms:

  • Perhaps obvious, the fitness value should accurately estimate the quality of a particular solution
  • A "smooth" distribution is preferable since it provides a gradient which can guide the incremental search in the solutions space. (ex. if most fitness values are 1.0 or 0.0 it's hard to know which genotypes are good candidates for reproduction)
Returns
true if the evolution goal was reached

Implements darwin::Domain.


The documentation for this class was generated from the following files: