Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: C4 – Connect Four, with AI (kenrick95.github.io)
48 points by kenrick95 on Jan 14, 2015 | hide | past | favorite | 34 comments



How 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.


Awesome! 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/

Thanks for sharing it and congratulations!


Nice job, do you recommend the Artificial Intelligence MOOC? Is it fun?


It'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-berkel...


We 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-fou...

You can use any language since it just talks over pipes. There's a few bots in there you can play against.


Also, if you'd like some light reading, Victor Allis proved a winning strategy in 1988: http://www.informatik.uni-trier.de/~fernau/DSL0607/Masterthe.... It's a great read, I recommend it.


I 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

Edit --

Github is here: https://github.com/RyanMarcus/connect4

Looks like my AI beats your AI. ;)


Just beat yours at 5 moves ahead


I'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. :)


Not to be a pessimist, but Connect Four is a solved problem: 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)?


I'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 :)


Nice 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?


Normally it tries its best to avoid that situation, but sometimes your scenario happens and I did not know why.


Finally got a win, took me about 10 rounds. Really cool thanks for sharing.


Had a win in the first round but that was pure luck. :-)


Had a win in the first round because I played Connect 4 aggressively against my brother for years when I was a kid!


I won in the 2nd round.


Every once in a while a new game pops up on HN and I always pay the price in time. Not complaining!


Note to future readers: This is how we ended up training our new robot overlords wasn't it?


Wow, I really suck at Connect Four.


Wow another developer named kenrick :)


Hi, another Kenrick :)


Really nice work and very cool


Nice, I just beat it :)


I admit that the AI is not perfect. :)


My Fhourstones solver and a perfect playing applet may be found at http://tromp.github.io/c4/c4.html


No need to apologize, even if it's perfect, the first player can always win by playing the right moves.


a perfect AI would be rather boring anyway!


I 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.


Unless 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 . .


It 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.


Just a clarification: The latest commit is around a month ago. https://github.com/kenrick95/c4


Interesting, this method has lead to the game freezing a couple times. And another time it seemed that the computer just skipped it's turn.


only got a draw by this method




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: