Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8298235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:41:40+00:00 2026-06-08T15:41:40+00:00

I’m making a pong game for my software development class, and I should probably

  • 0

I’m making a pong game for my software development class, and I should probably state that this is homework, hence my limited understanding. and I’m having some problems creating the AI for my NPC paddle. I’m using Kivy and Python.

Currently I can create impossible to beat AI by doing this:

#ai
self.player2.center_y = self.ball.y 

where self.player2.center_y is the y coordinate for the NPC (it only moves on the y axis) and self.ball.y is the y coordinate for the ball. I followed the tutorial on the Kivy site to create the basis of the game.

Now I have no idea about how I can create AI that will be beatable. I know I will need to limit the speed of the AI, so when the ball gets so fast it won’t be able to grab it.
The thing is, though, that I don’t actually have a speed function.

The problem with the tutorial I followed is that it doesn’t explain everything. I believe I could make a speed function by saying
"Every x seconds, the paddle will move x pixels in the y axis."

This is how the ball is served as per the kivy tutorial:

def serve_ball(self, vel=(10,0)):
    self.ball.center = self.center
    self.ball.velocity = vel

Alright, now I’ll try and understand this… vel=(10,0)): likely means, move 10 pixels X and 0 pixels Y, assign that to ball.velocity, and evidently that controls the speed…

class PongApp(App):
    def build(self):
        game = PongGame()
        game.serve_ball()
        Clock.schedule_interval(game.update, 1.0/300.0)
        return game

Clock.schedule_interval(game.update, 1.0/300.0) with regards to this, Is it safe to assume that… that is the rate at which the ball moves? i.e. 10 pixels x and 0 y, every 1/300 seconds? If i change it to something like 1/20, it moves much slower… so I would assume so.

Now I need to create a function to hold the AI… perhaps

def AI(self):
    self.AI_Speed = self.ball.velocity - 10

self.player1. refers to my paddle.

And yeah.. Now I’m stuck. I have no idea how I can use this velocity to control moving the paddle. Anyone have any Ideas? And Since my question is most likely extremely ambiguous, I will provide the source of the game incase you need a better understanding. Thank you.

http://pastebin.com/8wTLbH21

p.s. i realize this is a big question and a lot to ask, but I hope someone can answer. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:41:41+00:00Added an answer on June 8, 2026 at 3:41 pm

    Since this is such a big question, I haven’t tested this out or anything, but it seems like you want to have some sort of function that moves the AI (I’ll call it self.player2.move()). If you call this function in game.update(), then you should be able to move the AI paddle incrementally closer to where it needs to be to hit the ball.

    Some basic pseudocode for self.player2.move():

    figure out if ball is above or below paddle
    move self.AI_Speed units in the direction of the ball
    

    You might need to adjust the AI speed more to make this work, but I think it should be the right general idea. If you think about it, the unbeatable AI is basically just infinitely fast.

    Does that help get you unstuck?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.