Pong AI - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QbasicNews.Com (http://qbasicnews.com/newforum/forum-3.html) +--- Forum: Challenges (http://qbasicnews.com/newforum/forum-10.html) +--- Thread: Pong AI (/thread-6624.html) |
Pong AI - j2krei08 - 03-27-2005 Hi all. Make a self-playing Pong Clone. 2 players, but computer vs. computer. It must combine ANSI characters and graphics (hint, screen 13, each char is 8x8 pixels) Pong AI - Mitthrawnuruodo - 03-27-2005 What's ANSI characters? Pong AI - thegrogen - 03-27-2005 Quote:What's ANSI characters? ASCII characters. Pong AI - Mitthrawnuruodo - 03-27-2005 Oh. ASCII characters! Why would you want ASCII characters in a game?! What the score mabey? Pong AI - Mitthrawnuruodo - 03-27-2005 Ok, It took me about an hour but here is my entry: Code: RANDOMIZE TIMER Pong AI - Rattrapmax6 - 03-27-2005 That's sweet Mitth!!!! Pong AI - Mitthrawnuruodo - 03-27-2005 Thank you... I kinda just felt like doing it quick, bout an hour 20 min, needed a break from SpaceMerc. Thanks You know that that is a really stable core there, and can easily be converted to a 1 player game, its open source if anyone wants it, just not to use to post in this challenge of course. So if anyone wants to pick off of what I have there I can explain it to you if you can't understand it, otherwise just take it. Again, I'm not going to make this better, I just did it for a break program, so enjoy! Pong AI - j2krei08 - 03-29-2005 I guess I wasn't very clear. By combining ANSI(ASCII, if you please) and graphics I mean: CHR$(219) or â (under screen 13, it prints a square 8x8(that's our ball)) and lines, say LINE(0, 40)-(0, 120) for an 80 pix line that is divisible by 8 (80 / 8 for 10 full ASCII spaces) and if ballpositionx >= linetop AND ballpositiony <=linebottom THEN (then it makes the ball deflect and continue, if it is <> then it adds a goal. The reason I haven't posted my program is this: 1. The computer I use internet isn't the computer I program on. 2. I have to go into DOS and copy the file to a floppy, then copy it to the inet computer. Then, open it in Notepad and paste it to the site. I haven't done this because I don't have internet and I have to post at school. I shall have it tomorrow! Pong AI - Mitthrawnuruodo - 03-29-2005 hey! No you wern't clear...but hey! no worries: Here's my modified entry: [syntax="qbasic"] RANDOMIZE TIMER CLEAR SCREEN 13 CLS BX% = 20 BY% = 12 IF INT(RND * (1 - 0 + 1) + 0) THEN x% = -1: ELSE x% = 1 IF INT(RND * (1 - 0 + 1) + 0) THEN y% = -1: ELSE y% = 1 BXV% = INT(RND * (2 - 1 + 1) + 1) * x% BYV% = INT(RND * (2 - 1 + 1) + 1) * y% R% = 2 score1% = 0: Score2% = 0 Paddle1X% = 2: Paddle1Y% = 10 Paddle2X% = 38: Paddle2Y% = 10 index% = 0 COLOR 4 PRINT "RULES: GO TO 10 POINTS" PRINT "IF AI SYSTEM GOES TO A NO-WIN LOOP IT RESETS" PRINT "PRESS ANY KEY TO CONTINUE" DO: LOOP WHILE INKEY$ = "" CLS DO IF BXV% < 0 THEN IF BY% > Paddle1Y% + 2 THEN Paddle1Y% = Paddle1Y% + 2 IF BY% < Paddle1Y% + 2 THEN Paddle1Y% = Paddle1Y% - 2 IF Paddle1Y% + 4 > 23 THEN Paddle1Y% = 23 - 4 IF Paddle1Y% < 1 THEN Paddle1Y% = 1 END IF IF BXV% > 0 THEN IF BY% > Paddle2Y% + 2 THEN Paddle2Y% = Paddle2Y% + 2 IF BY% < Paddle2Y% + 2 THEN Paddle2Y% = Paddle2Y% - 2 IF Paddle2Y% + 4 > 23 THEN Paddle2Y% = 23 - 4 IF Paddle2Y% < 1 THEN Paddle2Y% = 1 END IF BX% = BX% + BXV% BY% = BY% + BYV% IF BX% > 40 THEN CLS COLOR 4 PRINT "POINTPLAYER 1!" PRINT "PRESS ANY KEY TO CONTINUE" DO: LOOP WHILE INKEY$ = "" CLS BX% = 20: BY% = 12 score1% = score1% + 1 IF INT(RND * (1 - 0 + 1) + 0) THEN x% = -1: ELSE x% = 1 IF INT(RND * (1 - 0 + 1) + 0) THEN y% = -1: ELSE y% = 1 BXV% = INT(RND * (2 - 1 + 1) + 1) * x% BYV% = INT(RND * (2 - 1 + 1) + 1) * y% END IF IF BX% < 1 THEN CLS COLOR 4 PRINT "POINTPLAYER 2!" PRINT "PRESS ANY KEY TO CONTINUE" DO: LOOP WHILE INKEY$ = "" BX% = 20: BY% = 12 CLS Score2% = Score2% + 1 IF INT(RND * (1 - 0 + 1) + 0) THEN x% = -1: ELSE x% = 1 IF INT(RND * (1 - 0 + 1) + 0) THEN y% = -1: ELSE y% = 1 BXV% = INT(RND * (2 - 1 + 1) + 1) * x% BYV% = INT(RND * (2 - 1 + 1) + 1) * y% END IF IF BY% > 23 THEN BY% = 23: BYV% = BYV% * -1 IF BY% < 1 THEN BY% = 1: BYV% = BYV% * -1 LOCATE Paddle1Y%, Paddle1X%: COLOR 1: PRINT CHR$(219) LOCATE Paddle1Y% + 1, Paddle1X%: COLOR 1: PRINT CHR$(219) LOCATE Paddle1Y% + 2, Paddle1X%: COLOR 1: PRINT CHR$(219) LOCATE Paddle1Y% + 3, Paddle1X%: COLOR 1: PRINT CHR$(219) LOCATE Paddle1Y% + 4, Paddle1X%: COLOR 1: PRINT CHR$(219) LOCATE Paddle2Y%, Paddle2X%: COLOR 1: PRINT CHR$(219) LOCATE Paddle2Y% + 1, Paddle2X%: COLOR 1: PRINT CHR$(219) LOCATE Paddle2Y% + 2, Paddle2X%: COLOR 1: PRINT CHR$(219) LOCATE Paddle2Y% + 3, Paddle2X%: COLOR 1: PRINT CHR$(219) LOCATE Paddle2Y% + 4, Paddle2X%: COLOR 1: PRINT CHR$(219) LOCATE BY%, BX%: COLOR 4: PRINT CHR$(219) oBX% = BX%: oBY% = BY% oPaddle1X% = Paddle1X%: oPaddle1Y% = Paddle1Y% oPaddle2X% = Paddle2X%: oPaddle2Y% = Paddle2Y% LOCATE 1, 10: COLOR 4: PRINT score1% LOCATE 1, 30: COLOR 4: PRINT Score2% doR% = 0 doY% = 0 x2% = Paddle1X% y2% = Paddle1Y% IF x2% = BX% - 1 OR x2% = BX% THEN doY% = 1 IF doY% = 1 THEN IF y2% = BY% THEN doR% = 1 IF y2% = BY% - 1 THEN doR% = 1 IF y2% = BY% - 2 THEN doR% = 1 IF y2% = BY% - 3 THEN doR% = 1 IF y2% = BY% - 4 THEN doR% = 1 END IF IF doR% = 1 THEN BXV% = BXV% * -1 END IF doR% = 0 doY% = 0 x2% = Paddle2X% y2% = Paddle2Y% IF x2% = BX% + 1 OR x2% = BX% THEN doY% = 1 IF doY% = 1 THEN IF y2% = BY% THEN doR% = 1 IF y2% = BY% - 1 THEN doR% = 1 IF y2% = BY% - 2 THEN doR% = 1 IF y2% = BY% - 3 THEN doR% = 1 IF y2% = BY% - 4 THEN doR% = 1 END IF IF doR% = 1 THEN BXV% = BXV% * -1 END IF WAIT &H3DA, 8 WAIT &H3DA, 8, 8 LOCATE oPaddle1Y%, oPaddle1X%: COLOR 0: PRINT " " LOCATE oPaddle1Y% + 1, oPaddle1X%: COLOR 0: PRINT " " LOCATE oPaddle1Y% + 2, oPaddle1X%: COLOR 0: PRINT " " LOCATE oPaddle1Y% + 3, oPaddle1X%: COLOR 0: PRINT " " LOCATE oPaddle1Y% + 4, oPaddle1X%: COLOR 0: PRINT " " LOCATE oPaddle2Y%, oPaddle2X%: COLOR 0: PRINT " " LOCATE oPaddle2Y% + 1, oPaddle2X%: COLOR 0: PRINT " " LOCATE oPaddle2Y% + 2, oPaddle2X%: COLOR 0: PRINT " " LOCATE oPaddle2Y% + 3, oPaddle2X%: COLOR 0: PRINT " " LOCATE oPaddle2Y% + 4, oPaddle2X%: COLOR 0: PRINT " " LOCATE oBY%, oBX%: COLOR 0: PRINT CHR$(217) index% = index% + 1 IF index% >= 1500 THEN CLS COLOR 4 PRINT "TIMEOUTRESET" PRINT "PRESS ANY KEY TO CONTINUE" DO: LOOP WHILE INKEY$ = "" CLS index% = 0 BX% = 20: BY% = 12 IF INT(RND * (1 - 0 + 1) + 0) THEN x% = -1: ELSE x% = 1 IF INT(RND * (1 - 0 + 1) + 0) THEN y% = -1: ELSE y% = 1 BXV% = INT(RND * (3 - 1 + 1) + 1) * x% BYV% = INT(RND * (3 - 1 + 1) + 1) * y% END IF LOOP UNTIL score1% >= 10 OR Score2% >= 10 CLS COLOR 4 IF score1% > Score2% THEN PRINT "PLAYER 1 WINS!" ELSE IF score1% < Score2% THEN PRINT "PLAYER 2 WINS!" ELSE PRINT "TIE!" END IF END IF END [/syntax] Pong AI - j2krei08 - 03-29-2005 Cool. Here's mine. I made it last night, and ran it for 4 hours and nobody scored! cool? Code: SCREEN 13 If it's too fast, modify the FOR with the graphics in it. |