9 ms·
Show HN: C4 – Connect Four, with AI
- RMarcus 12y agoI wrote a C version of a connect 4 AI and used emscripten to build a JavaScript / AngularJS version. You can check it out for comparison: http://rmarcus.info/blog/2014/12/23/connect4.html http://rmarcus.info/blog/2014/12/23/connect4.html Edit -- Github is here: https://github.com/RyanMarcus/connect4 https://github.com/RyanMarcus/connect4 Looks like my AI beats your AI. ;)
- guidopallemans 12y agoJust beat yours at 5 moves ahead
- RMarcus 12y agoI've been playing at 8 for a challenge. Can't win yet, but I can draw. I left it at 5 as the default because it works well on tablets. :)
- kenrick95 12y agoHow I build this project: It was mid-2013 when I wanted to apply what I've learned from the MOOC CS188.1x Artificial Intelligence offered at edx.org. Around December 2013, I joined a bootcamp held in my university (Nanyang Technological University, Singapore) in which some of the speaker came from Mozilla. Here, I learned a lot of stuffs on JavaScript (they also introduced us to HN). Later, I thought of applying what I've learned to a game. I then started the project and finished it during January 2014.
- mrborgen 12y agoNice job, do you recommend the Artificial Intelligence MOOC? Is it fun?
- kenrick95 12y agoIt's amazing. Although quite time-consuming, the projects are nice: it was building an AI for Pac-man to maximize its score in various scenarios. The next offering is starting soon: https://www.edx.org/course/artificial-intelligence-uc-berkeleyx-cs188-1x-0 https://www.edx.org/course/artificial-intelligence-uc-berkel...
- atrilla 12y agoAwesome! It's wonderful to see these kind of side projects for deliberate practice. I also expect to build some of these at http://ai-maker.com/ http://ai-maker.com/ Thanks for sharing it and congratulations!
- JamyDev 12y agoNice, I just beat it :)
- kenrick95 12y agoI admit that the AI is not perfect. :)
- tromp 12y agoMy Fhourstones solver and a perfect playing applet may be found at http://tromp.github.io/c4/c4.html http://tromp.github.io/c4/c4.html
- stefs 12y agoa perfect AI would be rather boring anyway!
- unstabilo 12y agoNo need to apologize, even if it's perfect, the first player can always win by playing the right moves.
- kenrick 12y agoWow another developer named kenrick :)
- kenrick95 12y agoHi, another Kenrick :)
- vapter 12y agoNice work! I was actually planning to do a similar project in the near future. However, it troubles me that I was able to win when your AI didn't "block" me when I put 3 aligned circles. Shouldn't that be the very first rule for such an AI?
- kenrick95 12y agoNormally it tries its best to avoid that situation, but sometimes your scenario happens and I did not know why.
- bluehazed 12y agoWow, I really suck at Connect Four.
- alacritythief 12y agoI want to note that you can win every time by dropping wherever first, then on your next moves dropping every piece on top of the AI's pieces.
- inglesp 12y agoUnless I've totally misunderstood, I don't think you're right. For instance, on your first go, drop in column 0. Then, the AI drops in columns 1, 2, 3, 4, leading to this: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . X X X . . . X O O O O . .
- alacritythief 12y agoIt could have been fixed after my post, I won 8 times in a row and it seemed to be some kind of fluke. After trying it now, the AI actually tries harder to beat you, and my previous method is not effective anymore.
- kenrick95 12y agoJust a clarification: The latest commit is around a month ago. https://github.com/kenrick95/c4 https://github.com/kenrick95/c4
- ljk 12y agoonly got a draw by this method
- wuliwong 12y agoInteresting, this method has lead to the game freezing a couple times. And another time it seemed that the computer just skipped it's turn.
- lwgdhn 12y agoEvery once in a while a new game pops up on HN and I always pay the price in time. Not complaining!
- hitchhiker999 12y agoNote to future readers: This is how we ended up training our new robot overlords wasn't it?
- austinhutch 12y agoFinally got a win, took me about 10 rounds. Really cool thanks for sharing.
- mlamat 12y agoI won in the 2nd round.
- smilliken 12y agoWe did a friendly programming competition at MixRank last year writing AIs for Connect Four. It's really a great game for playing with AI strategies since it's so simple. You can borrow our game runner and write your own: https://github.com/smilliken/aigames/tree/master/connect-four https://github.com/smilliken/aigames/tree/master/connect-fou... You can use any language since it just talks over pipes. There's a few bots in there you can play against.
- smilliken 12y agoAlso, if you'd like some light reading, Victor Allis proved a winning strategy in 1988: http://www.informatik.uni-trier.de/~fernau/DSL0607/Masterthesis-Viergewinnt.pdf http://www.informatik.uni-trier.de/~fernau/DSL0607/Masterthe.... It's a great read, I recommend it.
- cl42 12y agoNot to be a pessimist, but Connect Four is a solved problem: http://en.wikipedia.org/wiki/Connect_Four http://en.wikipedia.org/wiki/Connect_Four Wouldn't that mean the best AI should always win if it's first (alternatively, you should always win if you're first)?
- kenrick95 12y agoI'm aware of the fact that this is a solved problem. When I experimented by making it my AI vs my AI, it did not use the optimal first move. This shows that my AI is not perfect :)
- noso 12y agoReally nice work and very cool