The NEW Pong Game V13.2.1
An interesting implemnettaion of the pong game
Loading...
Searching...
No Matches
AI Class Reference

Artificial Intelligence for controlling a paddle. More...

#include <ai.hpp>

Public Member Functions

 AI (Paddle *controlledPaddle)
 Constructor for AI class.
 
void set_difficulty (int difficulty)
 Sets the AI difficulty level.
 
void updateAI (BallBase *ball, float dt)
 Updates the AI-controlled paddle's position.
 

Private Attributes

int ai_difficulty
 
Paddleracket
 

Detailed Description

Artificial Intelligence for controlling a paddle.

This class manages computer-controlled paddles, providing different difficulty levels to adjust how well the AI tracks and responds to the ball.

Constructor & Destructor Documentation

◆ AI()

AI::AI ( Paddle * controlledPaddle)

Constructor for AI class.

Parameters
controlledPaddlePointer to the paddle that will be controlled by the AI

Initializes the AI controller with a pointer to the paddle it will control and sets default difficulty to normal

Parameters
controlledPaddlePointer to the paddle to be controlled by the AI

Member Function Documentation

◆ set_difficulty()

void AI::set_difficulty ( int difficulty)

Sets the AI difficulty level.

Parameters
difficultyThe difficulty level (0=easy, 1=normal, 2=hard)

◆ updateAI()

void AI::updateAI ( BallBase * ball,
float dt )

Updates the AI-controlled paddle's position.

Updates the AI-controlled paddle's position based on the ball.

Called each frame in AI mode to move the paddle to attempt to hit the ball based on the current difficulty setting

Parameters
ballPointer to the ball to track
dtTime delta since last update (in seconds)

This method calculates where to move the paddle based on the ball's position and the current difficulty setting. Higher difficulty makes the AI react faster.

Parameters
ballPointer to the ball to track
dtTime delta since last update (in seconds)

Adjust reaction speed based on difficulty level

Easy: 60% speed - easier for player to win Normal: 100% speed - balanced Hard: 140% speed - more challenging for the player

Move the paddle based on ball position

Keep the paddle within screen bounds

Member Data Documentation

◆ ai_difficulty

int AI::ai_difficulty
private

Current difficulty level (0=easy, 1=normal, 2=hard)

◆ racket

Paddle* AI::racket
private

Pointer to the paddle controlled by the AI


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