Computer Science Canada Connect 4 With Amazing AI !! |
Author: | Scott [ Tue Apr 20, 2010 8:53 am ] |
Post subject: | Connect 4 With Amazing AI !! |
Hi, this is my first submission. It is a simple connect four using sprites. Hope you enjoy it. You can either play another human or try to beat my AI. Goodluck (: Also I know my AI tries to get four in a row off of the board, but I have moved on to other things and thought you guys might enjoy this. Please leave constructive feedback or suggestions. Thanks, Scott |
Author: | Thaviel [ Mon May 03, 2010 9:01 am ] |
Post subject: | Re: Connect 4 With Amazing AI !! |
I love connect 4 with amazing AI!! +2 bits ![]() Scott I feel kinda sorry for you. the Computer player is really cool and pretty hard to beat too and you have over 150 downloads and yet no one posts anything about it ![]() |
Author: | qmanjr5 [ Tue May 18, 2010 10:40 am ] |
Post subject: | RE:Connect 4 With Amazing AI !! |
I'll download this when I get home, I'm at school right now. Seems fun ![]() I'll also post when I beat your AI ![]() ![]() |
Author: | SNIPERDUDE [ Tue May 18, 2010 1:19 pm ] |
Post subject: | RE:Connect 4 With Amazing AI !! |
I must say, I found it rather hard to beat - so I gave up on it. Very well done, +bits |
Author: | A.J [ Tue May 18, 2010 4:45 pm ] |
Post subject: | RE:Connect 4 With Amazing AI !! |
Ah, not bad AI at all. Though my AI beat it 10/10 ! (LOL, no, I am not that self centered...but it is true ![]() very good job though + bits |
Author: | BigBear [ Wed May 19, 2010 8:32 pm ] |
Post subject: | Re: Connect 4 With Amazing AI !! |
Attached is a video of me going 3 times in a row and then at another time going twice in a row, I have recreated this many times and after i go top right corner it always lets me go again and again if I go bottom left but not if I go anywhere else. Also it doesn't go when I will win the next turn either way. |
Author: | Scott [ Fri May 21, 2010 9:18 am ] |
Post subject: | Re: Connect 4 With Amazing AI !! |
Hey, thanks for letting me know about that bug where you can keep going. Already fixed. Can you make another movie where the comp wont lose? I might have fixed it while fixing the other problem. Anyways here is the update hope you guys enjoy. Keep going at it and letting me know. Thanks, Scott |
Author: | BigBear [ Fri May 21, 2010 9:50 pm ] |
Post subject: | RE:Connect 4 With Amazing AI !! |
It was at the end of the video, i go twice before the computer does the last move |
Author: | Unnamed.t [ Tue May 25, 2010 6:23 pm ] |
Post subject: | Re: Connect 4 With Amazing AI !! |
Wow this program is great. And what I think amazing about it is that.... I BEAT YOUR AI ON THE FIRST TRYYY ![]() Lol after reading all the posts i just thought i was going to lose just like that but it is pretty hard to believe i won. The board/stadium (what ever u like to call it) looked like this (im X/x and comp is O/o) * * * * * * * * * * * * * * * * * ** * * *o*x**** this may be more visually apealing:::::OX *** * *x*x*o**** this may be more visually apealing::::XXO * * *x*x*x*x* ** this may be more visually apealing::::XXXX * * *o*o*x*o* ** this may be more visually apealing:::OOXO * *o*x*x*o*o*o* this may be more visually apealing::OXXOOO |
Author: | supaphreek [ Sat May 29, 2010 12:42 pm ] |
Post subject: | RE:Connect 4 With Amazing AI !! |
this is pretty damn good. i lost several times ![]() ![]() ![]() Edit : I WONNN ![]() |
Author: | Scott [ Fri Jun 04, 2010 11:39 am ] |
Post subject: | Re: Connect 4 With Amazing AI !! |
Tony - I guess you just understand the correct way of playing connect 4, which is to set up a double win(hint to others). Supaphreet - Good try and its supposed to be hard, your not supposed to lose to AI, or else it isnt very good AI. Thanks everyone for the feedback. |
Author: | A.J [ Fri Jun 04, 2010 11:48 am ] |
Post subject: | RE:Connect 4 With Amazing AI !! |
Your AI plays pretty well. However, it would be a good exercise to try implementing a minimax algorithm (as this game's is pretty small relative to games such as chess where minimax is very useful, it will work nicely). Also, the game Connect 4 has already been solved mathematically by James Allen and Victor Allis. Assuming both players play optimally, player 1 can force a win by going in the center column, player 2 can force a draw if player 1 plays in the two adjacent columns, and player 2 can force a win if player 1 plays in any of the four outer columns. The following link is Victor Allis' Masters Thesis regarding Connect 4: http://www.connectfour.net/Files/connect4.pdf |
Author: | Cezna [ Fri Jun 04, 2010 2:05 pm ] |
Post subject: | RE:Connect 4 With Amazing AI !! |
Great game, and very good AI. Haven't beat it, but I suck at Connect 4, but if by some fluke I do manage to beat it, I will let you know. Have you considered putting it difficulty settings for when you are playing the computer? It would probably be pretty hard to code the computer to make realistic but not overly predictable mistakes, but it would be really cool if you could do it. |
Author: | Cezna [ Tue Jun 08, 2010 11:42 am ] |
Post subject: | Re: Connect 4 With Amazing AI !! |
Beat the AI It let me go first I did this (column 1 = farthest left) column 1 column 4 column 4 column 3 column 2 column 1 column 3 |
Author: | Scott [ Wed Jun 16, 2010 12:50 pm ] |
Post subject: | Re: Connect 4 With Amazing AI !! |
Cezna - Thanks and good work. Yes it is a simplistic AI with no foresight at all. It determains it moves at that moment depending on the state of the current board without considering future moves by its oppenent. A.J - I know it has been solved and I looked into it when I began the AI. I only made this to touch on AI algorithms and expand my knowledge not to create 'skynet'. I have thought about the minimax long before and had already decided to leave that for next year possibly, so look out for a post by me next year (: Thanks, Scott |
Author: | A.J [ 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. |
Author: | Cezna [ 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. |
Author: | A.J [ 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). |
Author: | Insectoid [ 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. |
Author: | Cezna [ Wed Jun 16, 2010 6:06 pm ] |
Post subject: | RE:Connect 4 With Amazing AI !! |
Sounds great AJ, thanks! |
Author: | Scott [ 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). |
Author: | copthesaint [ 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 |
Author: | A.J [ 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. |
Author: | Cezna [ 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). |
Author: | MagicIdiot [ 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! |