Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Connect 4 With Amazing AI !!
Index -> Programming, Turing -> Turing Submissions
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
A.J




PostPosted: Wed Jun 16, 2010 1:20 pm   Post subject: RE:Connect 4 With Amazing AI !!

Well, I apologize if I came across as rude, or scrutinizing in any way. I do realize that you are coding this as an exercise to broaden your knowledge of AI. As requested, I'll gladly explain what the minimax algorithm does. Essentially what this algorithm does is minimizing the possible loss while maximizing the potential gain in the game. It is a recursive algorithm for choosing the next move in a game (in this case connect 4) by associating certain heuristics (i.e. point values, in a way) to positions. To achieve this, your AI plays as itself and the opponent (assuming perfect play by opponent, i.e. assuming that the opponent makes no mistakes) for a number of moves, and then evaluates the position that results.

For example, in the case of connect 4, your AI could play as itself, then your opponent, itself, etc... for, let's say, 5 moves. After this, it looks at the board and evaluates it using some heuristic (e.g. it could be +2 point for every 3 in a row, +1 for every possible 2 in a row, etc...). It then subtracts the number of points it gets by the number of points its opponent gets (as you don't want you opponent to win, the more points for him/her, the worse. So you subtract it by your points). Then it stores that number and says: "Making this move and playing ahead by 5 moves, it gives me x points". It then goes back to the board and thinks another 5 moves ahead, this time starting with a different move, and stores the points it then gets. After doing this for every move, he then plays the move that yielded the greatest number of points. So, in essence, he merely plays as himself and the opponent and evaluates how good/bad making a certain move can be in the future. Now, to speed things up, people set certain point values for moves initially (like in this game for instance, center piece is +3, outer columns + 1, etc...). Then, you sort your possible moves from most -> least number of points and then start your recursive "play as myself, the opponent, and so on" function with that list.

Sorry for being long winded and kind of unclear. I hope this explains things a little better.
Sponsor
Sponsor
Sponsor
sponsor
Cezna




PostPosted: Wed Jun 16, 2010 3:28 pm   Post subject: RE:Connect 4 With Amazing AI !!

I am currently making a Connect 4 game, which was inspired by but not based on yours.

In fact, I used a totally different method of checking for lines, involving looking for circles of a given colour then following a line off from any positive results and counting the length of the line (that is way to simplified to be useful, I know, but I couldn't explain it any better without posting a whole bunch of code no one would care to read).

Due to my method, it would be quite difficult to make AI in the same simple way you did (I don't mean simple as in bad, I mean simple as in algorithmic and organized).
Still, I thought I would ask for any pointers as I hope to try (that's italicized for a good reason) to put AI in my game.

Anyway, I will probably end up posting the game in the submissions section in a while (maybe if I can get a half decent AI in it), but if anyone wants to see it, I can post it sooner.
A.J




PostPosted: Wed Jun 16, 2010 3:48 pm   Post subject: RE:Connect 4 With Amazing AI !!

Well, I currently am teaching a gr 11 CS class at my high school, and the summative I gave them was to create an AI for connect 4. If any good ones come up, I could give you an .exe for you to test your program with (I remember some of the groups' ideas being very innovative).
Insectoid




PostPosted: Wed Jun 16, 2010 5:08 pm   Post subject: RE:Connect 4 With Amazing AI !!

AJ...you're a teacher? Aren't you in Gr. 12? And you teach them? Or are you just 'helping out' a fail teacher who doesn't know what he/she's doing?

Sorry to take it off-topic. Your program's not bad.
Cezna




PostPosted: Wed Jun 16, 2010 6:06 pm   Post subject: RE:Connect 4 With Amazing AI !!

Sounds great AJ, thanks!
Scott




PostPosted: Thu Jun 17, 2010 9:18 am   Post subject: Re: Connect 4 With Amazing AI !!

A.J - Thank you, your explaination is almost exactly what I thought. I would implement it in a slightly different way though probably following my current code with modification to include the minimax algorith giving each move more value(value as in the current way I do it). Also no hard feelings just thought I would mention.

Cezna - The way you explained your check for lines(the way I understood it) is the same way I did my intial attempt at it before I found reccursion to be more effective. I would like to read your code(you stated no one would), if you would not mind posting it sometime in the future. Thank you for the simple comment I quite enjoyed it, I take pride in the way I do my code.

I would also like to mention all this talk about connect 4 AI has made me want to improve it, I will be working on it untill the end of the year but probably not at a quick pace(winding down).
copthesaint




PostPosted: Thu Jun 17, 2010 11:34 am   Post subject: RE:Connect 4 With Amazing AI !!

@insectoid, Lol I was 'the teacher' in grade 10, Whenever ANYONE didnt get something, they'd come to me, my actual teacher thought it was great since all he had to too was mark, the attendance and tell everyone what they are supposed to be doing... lol
A.J




PostPosted: Thu Jun 17, 2010 11:54 am   Post subject: RE:Connect 4 With Amazing AI !!

Well, this course has a teacher, however I make the tests and mark them (as I took the gr 12 course last year in gr 11). Well, you could utilize this idea of minimax not only for your AI, but also for a good programming exercise.
Sponsor
Sponsor
Sponsor
sponsor
Cezna




PostPosted: Thu Jun 17, 2010 2:10 pm   Post subject: RE:Connect 4 With Amazing AI !!

I have created a new topic with my Connect 4 game, so if anyone wants to look through it, it's up there (I used code tags to allow people to just look through it).
MagicIdiot




PostPosted: Sun Jun 20, 2010 10:31 pm   Post subject: Re: Connect 4 With Amazing AI !!

I beat the ai after my 3rd try. I didn't just connect four, i connected 6!


Connect4_goodAI Output.bmp
 Description:
 Filesize:  1.83 MB
 Viewed:  337 Time(s)

Connect4_goodAI Output.bmp


Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 25 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: