Results 1 to 8 of 8
Thread: How to make AI dumber
- 07-23-2011, 02:21 AM #1
Member
- Join Date
- Jul 2011
- Posts
- 53
- Rep Power
- 0
How to make AI dumber
Well I'm programming a Pong clone and I'm wondering how to make the enemy paddle "dumber" or "more human" if you prefer it that way

Fairly simple code:
The Ai checks if the middlepoint of the ball (y-coordinate) is higher or lower then the middle of the paddle. (with a fault of 5) and in response adjusts its position with 5 pixels.Java Code:public void AI() { if (middlepaddle-ycoordinateball<-5) { y2=y2+5; } else if (middlepaddle-ycoordinateball>5) { y2=y2-5; } }
At this moment the AI is unbeatable.
I have tried changing the pixels it adjusts itself to lower values. But that makes the aI not convincing, it makes it beatable though but I want a convincing aI.
Thnx in advance,
Reskaillev
- 07-23-2011, 09:31 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Maybe you can add some randomness to the y2 coordinate? e.g.
... where variable r is an instance of the Random class; you can play a bit with how big the random numbers should be to avoid turning your AI into a complete idiot ;-)Java Code:public void AI() { if (middlepaddle-ycoordinateball<-5) { y2=y2+r.nextInt(15); } else if (middlepaddle-ycoordinateball>5) { y2=y2-r.nextInt(15); } }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-23-2011, 03:46 PM #3
Also you could check to see if the ball is on the AI's side of the court. If it is, then track it towards the ball. If its not, you could invoke a random movement on its side. Kind of like how players some times move their paddle while their waiting for the ball to come back.
- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
- 07-24-2011, 03:11 AM #4
Member
- Join Date
- Jul 2011
- Posts
- 53
- Rep Power
- 0
Thnx a lot for those answers!
It's much appreciated
-
No, no, no. I'm sorry, but I think that you're missing the boat. The key to making your AI dumber is to create and call the proper methods. For example:
This never fails for my apps, and will work for yours, guaranteed!Java Code:MyAI ai = new MyAI(); ai.setName("Jos"); while (true) { ai.consumeGrolsch(); }
- 07-24-2011, 04:36 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
No! As written ai will never get to be used because of the infinite loop.
You shouldn't be calling consumeGrolsch() on the EDT anyway, the results are never pretty. And you MUST read the docs and catch the exceptions that this method is declared to throw. It is sufficient to respond to IntoxificationException by sending some random string to System.err. But you cannot suppress the OutOfGrolschException: use BeverageUtilities.replenishStock(), that's what it is there for.
There is no need to be overcareful about synchronising variables in MyAI that might be accessed by consumeGrolsch() from other threads as it is well known that after a few method calls the "synchronised" keyword no longer has any effect. Your code should note that the method is not thread safe, but that you don't really care.
- 07-24-2011, 08:02 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
I feel so flattered ...
kindest regards,
Jos ;-)When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-24-2011, 10:13 PM #8
Member
- Join Date
- Jul 2011
- Posts
- 53
- Rep Power
- 0
Similar Threads
-
how to make .exe
By vibaviattigala in forum New To JavaReplies: 4Last Post: 07-22-2011, 10:07 PM -
how do i make a jar to an exe?
By jack13580 in forum New To JavaReplies: 23Last Post: 12-19-2010, 04:15 AM -
Trying to make a bot
By ighor10 in forum New To JavaReplies: 4Last Post: 04-10-2010, 03:29 AM -
how can i make bufferedreader
By chyeeqi in forum New To JavaReplies: 4Last Post: 08-21-2009, 05:24 PM -
Make it just A, Help me please
By yuuchan in forum New To JavaReplies: 3Last Post: 04-25-2009, 02:09 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks