Qbasicnews.com
May 31, 2020, 08:59:21 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Poll
Question: Have you played the original Atari Pong?  (Voting closed: March 26, 2005, 04:05:51 PM)
Yes (I really have) - 6 (40%)
No (I want to) - 9 (60%)
Total Voters: 14

Pages: 1 2 [3]
  Print  
Author Topic: Pong AI  (Read 17486 times)
Mitth'raw'nuruodo
Ancient Guru
****
Posts: 515



WWW
« Reply #30 on: April 02, 2005, 10:26:46 PM »

I said it wasn't bad Rattra... Cheesy

Jay:
FOR THE LAST TIME it worked fine on my XP!!! :evil:
Logged

i]"But...it was so beautifully done"[/i]
TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #31 on: April 03, 2005, 11:37:58 AM »

Quote from: "Mitth'raw'nuruodo"
I said it wasn't bad Rattra... Cheesy

Jay:
FOR THE LAST TIME it worked fine on my XP!!! :evil:


I know, what i do not get is why it worked better on a slow computer than a fas one..what DOS emulator do you have.
Logged

url=http://www.sloganizer.net/en/][/url]
Mitth'raw'nuruodo
Ancient Guru
****
Posts: 515



WWW
« Reply #32 on: April 03, 2005, 12:19:42 PM »

XP's DOS.
My computer an't slow. What processing power do you have?
Logged

i]"But...it was so beautifully done"[/i]
Rattrapmax6
__/--\__
*****
Posts: 2577



WWW
« Reply #33 on: April 03, 2005, 01:06:45 PM »

Smiley Here is my extodinary simple AI, but it has that human edgyness in the players.. they pause, go too fast, ect,.. Please note this is in FB, which means it doesn't require checks for text that goes off screen..

It my run in QB minus (SLEEP 100) with no errs, but I'm sure the paddles go off screen a few times in their frantic moving.. Ball stays on screen mind..

Also has 3point paddles, minus they rarely work under the comps checks,. :wink:

Code:
'THIS WAS DONE IN FREEBASIC!
'With that siad,..
'Enjoy!

DECLARE SUB game(point1, point2)

SCREEN 13
PRINT "Pong AI system by Kevin(x.t.r.GRAPHICS)"
PRINT "Simulated to varible human reaction times.."
PRINT
PRINT "Press any key to continue...."
SLEEP
CLS
y1 = 1: y2 = 1
px = 20: py = 12
pxv = 1: pyv = 1
DO
   'Clear Screen
   LINE (0,0)-(320, 200), 0, BF
   'Set Score:
   LOCATE 1, 5: PRINT "C1:"; point1; ", C2:";point2
   'Set paddle 1
   LOCATE y1, 2: PRINT "|"
   LOCATE y1 + 1, 2: PRINT "|"
   LOCATE y1 + 2, 2: PRINT "|"
   'Set paddle 2
   LOCATE y2, 39: PRINT "|"
   LOCATE y2 + 1, 39: PRINT "|"
   LOCATE y2 + 2, 39: PRINT "|"
   'Set ball
   LOCATE py, px: PRINT "O"
   'Buffer Screen
   WAIT &H3DA, 8
   'Move Ball
   px = px + pxv
   py = py + pyv
   'Check Ball Wall
   IF px < 1 THEN point2 = point2 + 1: px = 20: pxv = 1: pyv = 1: y1 = 1: y2 = 1: CALL game(point1, point2)
   IF px > 39 THEN point1 = point1 + 1: px = 20: pxv = -1:pyv = 1: y1 = 1: y2 = 1: CALL game(point1, point2)
   IF py < 1 THEN pyv = 2: py = 1
   IF py > 22 THEN pyv = -2: py = 22
   'Check Ball Paddle
   'Paddle 1
   'IF py > y1 - 1 AND py < y1 + 3 AND px = 3 THEN pyv = -2: pxv = -1
   IF py = y1 AND px < 3 THEN pyv = -1: pxv = 1
   IF py = y1 + 1 AND px < 3 THEN pyv = 0: pxv = 1
   IF py = y1 + 2 AND px < 3 THEN pyv = 1: pxv = 1
   'Paddle 2
   IF py = y1 AND px > 38 THEN pyv = -1: pxv = -1
   IF py = y1 + 1 AND px > 38 THEN pyv = 0: pxv = -1
   IF py = y1 + 2 AND px > 38 THEN pyv = 1: pxv = -1
   'Paddle Reaction
   'Paddle1
   yv1 = INT(RND * 3) + 1
   IF py > y1 + 1 THEN y1 = y1 + yv1
   IF py < y1 + 1 THEN y1 = y1 - yv1
   IF py <> y1 AND yv1 = 3 THEN y1 = y1 + 1
   IF py <> y1 AND yv1 = 1 THEN y1 = y1 - 1

   'Paddle2
   yv2 = INT(RND * 3) + 1
   IF py > y2 + 1 THEN y2 = y2 + yv2
   IF py < y2 + 1 THEN y2 = y2 - yv2
   IF py <> y2 AND yv2 = 3 THEN y2 = y2 + 1
   IF py <> y2 AND yv2 = 1 THEN y2 = y2 - 1
   SLEEP 100
LOOP UNTIL INKEY$ = CHR$(27)

SUB game(point1, point2)
   IF point1 > 9 THEN
      IF point1 > point2 THEN CLS: PRINT "C1 WINS!!": SLEEP: END
   END IF
   IF point2 > 9 THEN
      IF point2 > point1 THEN CLS: PRINT "C2 WINS!!": SLEEP: END
   END IF
END SUB


Enjoy!!  Cheesy
Logged

Kevin (x.t.r.GRAPHICS)

TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #34 on: April 04, 2005, 01:35:50 PM »

Quote from: "Mitth'raw'nuruodo"
XP's DOS.
My computer an't slow. What processing power do you have?


I tried it again and it worked fine.
the computer does occationally start slow i have to stop one thing from working to get it too work at its normal speed...the thing stopped running at start up for a while so i assumed my dad had stopped it permantly, looks like this was not the case. I ran it again AFTER checking what was running and found/stopped the thing which slows it down and it runs fine.
Logged

url=http://www.sloganizer.net/en/][/url]
Mitth'raw'nuruodo
Ancient Guru
****
Posts: 515



WWW
« Reply #35 on: April 04, 2005, 04:56:05 PM »

That's good, you like it?
Try the first one.

If you want you can make it into a game. Cheesy
Just don't make it crappy. :wink:
Logged

i]"But...it was so beautifully done"[/i]
shiftLynx
Wandering Guru
***
Posts: 340



WWW
« Reply #36 on: April 04, 2005, 05:10:38 PM »

Here are some ideas to include ontop of pong to make the game a bit more challenging. It will remove the need for "error" to be emulated (pretend AI with absolutely no learning).

1. Make the paddle velocity slow enough for even a perfect algorithm to intercept the ball.

2. Allow the paddles to be positioned at different angles; this may be a continuous angle, or a discrete angle. Either way, there is opportunity here for the program to actually -learn- rather than be programmed what to do.

The agent playing the game should be aware of at least 2 variables: the angle of the enemies paddle and the distance from itself to the ball (no sense of direction).

You could then use a basic artificial neural network (a perceptron would suffice, actually) to control the movement predictions and you could use a really simplistic genetic algorithm to decide which direction to move. Basically you want the bot to learn about the effect of the enemy paddle on the ball's deflection direction.

It might actually be quite fun to change the way pong is played a bit - have the paddles moving at a constant velocity and allow the players to modify the velocity of the paddles (taking into account a maximum speed, of course). When the paddles reach the top/bottom of the screen, they bounce back with elastic deflection, etc.

By adding this much complexity to the game, you could at least start to create a small opponent worthy of being said to "learn". Wink

These ideas would really be better suited for a graphical version of pong rather than textmode.

-shiftLynx
Logged

img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Pyrokid
Wandering Guru
***
Posts: 355



WWW
« Reply #37 on: April 12, 2005, 09:25:05 PM »

Nice ratrap but its a little jumpy i got the same problem but its qb but both the comps are pritty close in intelegence so they dont make as many mistakes

Code:

RANDOMIZE TIMER
CLS
SCREEN 13
ballx = 160
bally = 100
IF INT(RND * 2000) > 1000 THEN
ballobjx = 1
ELSE
ballobjx = -1
END IF
IF INT(RND * 2000) > 1000 THEN
ballobjy = 1
ELSE
ballobjy = -1
END IF


comp1s = 0
comp2s = 0
comp1 = 100
comp2 = 100
CLS
DO

LOCATE 1, 1: PRINT comp1s; comp2s
LINE (0, comp1 - 25)-(10, comp1 + 25), 0, BF
LINE (310, comp2 - 25)-(320, comp2 + 25), 0, BF


LINE (ballx - 15, bally - 15)-(ballx + 15, bally + 15), 0, BF
IF INKEY$ = CHR$(27) THEN END
CIRCLE (ballx, bally), 5, 7
LINE (5, comp1 - 20)-(5, comp1 + 20)
LINE (315, comp2 - 20)-(315, comp2 + 20)

IF INT(RND * 100) < 80 THEN
IF comp1 >= bally AND ballobjx = -1 THEN comp1 = comp1 - 1
IF comp1 <= bally AND ballobjx = -1 THEN comp1 = comp1 + 1
END IF

IF INT(RND * 100) < 70 THEN
IF comp2 >= bally AND ballobjx = 1 THEN comp2 = comp2 - 1
IF comp2 <= bally AND ballobjx = 1 THEN comp2 = comp2 + 1
END IF


'collision tests
IF bally <= 7 THEN ballobjy = 1
IF bally >= 195 THEN ballobjy = -1     'these two test the top
'next 2 test the paddles
IF ballx = 5 THEN
IF bally >= comp1 - 20 AND bally <= comp1 + 20 THEN ballobjx = -ballobjx
END IF
IF ballx = 315 THEN
IF bally >= comp2 - 20 AND bally <= comp2 + 20 THEN ballobjx = -ballobjx
END IF

IF ballx > 315 THEN

PRINT "Point, Stupid computer"
SLEEP 1
CLS
ballx = 160
bally = 100
comp1s = comp1s + 1
IF INT(RND * 2000) > 1000 THEN
ballobjx = 1
ELSE
ballobjx = -1
END IF
IF INT(RND * 2000) > 1000 THEN
ballobjy = 1
ELSE
ballobjy = -1

END IF

END IF


IF ballx < 5 THEN
PRINT "Point, Smart computer"
SLEEP 1
ballx = 160
bally = 100
comp2s = comp2s + 1
IF INT(RND * 2000) > 1000 THEN
ballobjx = 1
ELSE
ballobjx = -1
END IF
IF INT(RND * 2000) > 1000 THEN
ballobjy = 1
ELSE
ballobjy = -1
END IF


CLS
END IF


ballx = ballx + ballobjx
bally = bally + ballobjy
WAIT &H3DA, 8
WAIT &H3DA, 8, 8
LOOP


Logged

his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless  effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Rattrapmax6
__/--\__
*****
Posts: 2577



WWW
« Reply #38 on: April 12, 2005, 09:39:04 PM »

Shocked A lil to jumpy? You just insulted how I play Pong.. Cheesy .. jk

That what I was simulating... :wink: ... Nevious human reactions.. :lol:
Logged

Kevin (x.t.r.GRAPHICS)

Pyrokid
Wandering Guru
***
Posts: 355



WWW
« Reply #39 on: April 12, 2005, 09:41:57 PM »

yeah but humans moving the paddle will be more smooth like if it moves the wrong way like 2 or 3 times btw i edited it so check it again
Logged

his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless  effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Rattrapmax6
__/--\__
*****
Posts: 2577



WWW
« Reply #40 on: April 12, 2005, 09:51:40 PM »

Yeah, thats much better edited,.. Cool!!,.  :wink: ,.. They lose sometimes!!
Logged

Kevin (x.t.r.GRAPHICS)

Mitth'raw'nuruodo
Ancient Guru
****
Posts: 515



WWW
« Reply #41 on: April 13, 2005, 04:57:00 PM »

Quote from: "Rattrapmax6"
Shocked A lil to jumpy? You just insulted how I play Pong.. Cheesy .. jk

That what I was simulating... :wink: ... Nevious human reactions.. :lol:

lol

Hey it was good for me
Logged

i]"But...it was so beautifully done"[/i]
Lithium
Forum Regular
**
Posts: 123


« Reply #42 on: May 18, 2005, 10:03:15 AM »

http://fbtk.qbtk.com/phpBB2/download.php?id=71

you can play against the computer, a person, or have the computer play itself. There's three levels of AI too
Logged

COUNT HACKED BY RAZVEEE

RAZVEE IS A SCRIPT KIDDIE- hacker9
Pages: 1 2 [3]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!