Skip to content

Player

src.ga.player

View source code

AI Player driven by a tiny neural network.

OBSERVATION_LABELS = ('Ball dist x', 'Ball dist y', 'Paddle pos x', 'Ball pos x', 'Ball pos y', 'Ball speed x', 'Ball speed y') module-attribute

ACTION_LABELS = ('Left', 'Right') module-attribute

IndividualPlayer

Class for an Individual (AI) in the Population.

age = 0 instance-attribute

current_hit_streak = 0 instance-attribute

current_win_streak = 0 instance-attribute

fit_scores = None instance-attribute

max_hit_streak = 0 instance-attribute

max_win_streak = 0 instance-attribute

neural_net = None instance-attribute

scores = None instance-attribute

uid = None instance-attribute

__init__()

add_hit_to_streak() -> None

Update the streak counter.

add_win_to_streak() -> None

Update the streak counter.

apply_move(zone, move_left: bool, move_right: bool) -> bool

Perform a move based on directly supplied boolean actions from the Batch Brain.

calculate_fitness() -> float

create_neural_net()

get_fitness() -> float

Get the fitness.

get_scores() -> str

increase_age() -> int

Increase age by one.

look(zone) -> np.ndarray staticmethod

look_into(zone, inputs: np.ndarray) -> None staticmethod

Fill a reusable seven-value observation buffer.

reset_defaults() -> None

Reset stats and assign new UID for brand-new offspring/pupils.

reset_hit_streak() -> None

Reset the streak counter.

reset_scores() -> None

Specifically, reset game-play stats without wiping UID or Age.

reset_winning_streak() -> None

Reset the streak counter.

think(inputs_list) -> np.ndarray

Feed-forward decision using the neural network.