Bejeweled Blitz bot makes your high score look just sad

Programmers don’t need to get good at a game to achieve a high score, they code a bot for that instead. Take [hypnotizd] for instance. He was learning to write in the C# language and decided to make a bot that plays Bejeweled Blitz on Facebook. He figures he took between 48 and 72 hours of coding over a couple of weeks, but remember, he was learning the language at the same time. We think you’d be hard pressed to achieve a 1.5 million range score by yourself, even with that amount of practice time.

We spoke with [hypnotizd] yesterday afternoon to get a bit of background on how he made this happen. His code (he’s not releasing it so you’ll have to write your own) scrapes the screen image as input. You can see at the beginning of the video after the break that he sizes his app to properly align each jewel in its grid. The program then identifies each game piece by finding the center of the cell and taking a 25 square-pixel average color. Many of the jewels are easily recognized in this first pass, but some are harder and require several different tests to identify. That’s the difficult part, choosing the best move is just a matter of coming up with your own rules on how the bot should play the game.

[Thanks Adam]

Comments

  1. BiOzZ says:

    Nice! i love C# personally i find it my favorite language
    i do allot of interfacing hardware with software

  2. anonymous says:

    I would love to see the source for that, simply as a learning exercise.
    (I don’t even have a Facebook account.)

  3. bandwagon says:

    I’ve always wanted to do stuff like this with a neural network, but to each his own–I just find it fascinating to watch it learn. In fact, I might just do that. I’ve just got to figure out how to capture the play-area in Linux.

    • isama says:

      I’d take screenshots or maybe use x11vnc :)

    • BLuRry says:

      Actually you don’t need a neural net — the min-max algorithm would be wonderfully sufficient. Also for pattern recognition, I wrote a pattern recognizer using the Java UI robot toolkit (built in to the SDK) and had pretty good luck with an automated farmville hack that would plant and harvest my crops. It doesn’t work anymore since they changed the UI and stuff. I used transparent PNGs to represent the different game sprites, stripping out as much detail from the sprite as I could so it performed as little pixel comparisons as possible.

      • H3llphyre says:

        I did the same thing. My only motivation was to prove to friends that what they were doing wasn’t even fun. Within a week, I had gone from not playing farmville, to being a higher level than all of my friends and all of their friends. Then I stopped “playing” because I had expanded to max and bought everything.

        Yeah, I like ruining the fun in games…

      • MeeToo says:

        I did the farmville thing too. I gave up on it cause it was taking too much time to run (I had missed the obvious. It needed to be run in a virtual machine) Mind you it worked a treat at putting the family off, that time waster :-)

  4. Sean says:

    It sounds like he’s playing Unreal Tournament, not Bejeweled. Holy crap.

  5. Jay says:

    A few years back I used to use this same general technique to play king.com games. :) Those were fun times.

  6. Mime says:

    HAHA! I love projects like this! Yeah.. Everyone pretty much just got pwnd at Bejeweled :D

    • hypnotizd says:

      One of my friends kept poking fun at me for not being able to beat their score. You can imagine the look on their face when they saw mine ;) *evil laugh*

  7. vic says:

    I love this. I can’t count how many hours I spent coding bots for pointless online games too. Great fun :-)

  8. Bobby J says:

    This is how they do bots for online poker as well. Next project?

    • hypnotizd says:

      Next project has been up in the air for awhile. I haven’t had a good idea for one yet, unfortunately. Suggestions?

      • Volfram says:

        Gunbound. I always wanted to make a Gunbound bot.

      • hypnotizd says:

        @Volfram The very first bot I ever wrote was for Gunbound, believe it or not. That was back in 2003/4. It was just a suicide bot though written in the first vb.net. I didn’t get very far with it, but it would suicide. I was pretty good with trick shotting using the boomerang bot lol. I haven’t played that game in forever, though.

  9. Badwolf says:

    Source Code would be kinda cool ya know..

  10. aperson says:

    Oh neat, I didn’t realize that was hypno at first. Minecraft addicts unite!

  11. zing says:

    I’m not entirely sure, but it looks like it might also be taking advantage of some laxness in the game by moving several gems simultaneously.

  12. Anthony says:

    @zing – Bejeweled allows you to move gems at any time, even while gems are falling. This is relatively recent (as of v3 I think), but yeah, not exploiting that beyond being able to pattern recognize and react faster than humanly possible.

  13. James Shield says:

    sounds like it may have been based on caustik’s bot which was done in 2008.

    • hypnotizd says:

      I didn’t base this on any bot in particular. I went into this project completely blind while learning C#. Lots and lots of trial and error! That’s also part of the reason it took so long for me to make it.

  14. axet says:

    mine plays starcraft version: https://github.com/axet/starjeweled/wiki/Analyse

  15. Stevie says:

    As Jay said, have seen this done with King.com games. There’s money to be made.

  16. Mark says:

    very vie similar approach was doen and commented before on Hack-a-day wrt guitar hero game. They used OpenCV to do a templat ematch on each section.
    The code was very small IIRC

  17. Chris says:

    Bots are fun and intellectually challenging to write. :)

    My first was written to play the games on a local BBS, way back when. The sysop regularly and publicly challenged people to beat his cumulative score. I’d made it to #2 on the high score list fairly, but he always managed to stay in #1 spot by a slim margin; no matter how well or often I played. I decided to dethrone him by writing a Blackjack ‘bot which would automatically dial in the wee hours of the morning, and play until it beat his score. At first I had it set up with random delays to simulate human behavior, and to detect and sound an alarm if any unusual activity was detected; just in case he was awake and broke in to chat.

    It didn’t take long to beat him. In response, his score soon jumped back up to #1. Repeat the next day. On the third day, his score increased by a huge amount, which would have taken him literally all day to achieve; and the maximum bid amount in blackjack was reduced. Suspecting he was just editing his score rather than actually playing, I removed the delays entirely; and ran the program for one final, marathon session. Which not met the “impossible” challenge, but beat him by a large amount.

    And then he instantly increased his score by an amount which would take a human playing *thousands* of hours to manage. At which point he was clearly exposed as a cheater, unwilling to let anyone win the challenge he had proposed.

    Many people complained. The popularity of his BBS dropped, and calls to my BBS surged. Years later I was at Radio Shack talking to an employee, when he mentioned he ran that BBS. I told him my username on his BBS, and his jaw dropped. He asked how I’d managed to keep beating him, as he’d never figured it out. I just said I was really good at blackjack, and left. :)

    That said, I understand why the author of this ‘bot isn’t releasing source. ‘Bots are often a labor of love. In a multiplayer environment, they can seriously change game dynamics. At least if you wrote the ‘bot, you’re still putting in the often substantial *effort* to succeed; just in a different way than most. Releasing a ‘bot publicly gives many people an unfair advantage for no effort; and can lead to detection and bans, making them useless for everyone including the author.

    I speak from experience, having written a few ‘bots since then. None were ever released, though I described how they work to a few. My name was once fairly well known in both Eve and Warcraft. :)

    I wonder how long it will be before using higher-level visual object detection like SURF or Zdenek Kalal’s “Predator” becomes commonplace in ‘bots and ‘bot toolkits?

  18. jakyl says:

    I don’t play bejeweled but my mom does. I showed her this and she officially hates me now. Apparently showing awesome code totally make any score she ever got seem insignificant angers her somehow…

  19. xorpunk says:

    All botters use .NET cause of the browser COM and they are noob syntax.

  20. Frogz says:
  21. Nachowarrior says:

    That still doesn’t beat my all time high score.

  22. Dave says:

    Why isn’t the guy releasing the source code? Well he could win a lot of money on sites like zigiz.com (paying bejeweled clone). I think _that_ is the only reason..

    Yes, I too was working on such a tool once. Was too hard, I gave up.

  23. YaBa says:

    Nice work :)
    I’ve seen, some years ago, this kind of program to play/cheat Minesweeper.
    Check it: http://www.joriswit.nl/minesweeper/solver.html

  24. Adam says:

    With all the whining for source code, I can’t believe no-one’s suggested a middle road, add a plugin system for the “come up with your own rules” part. That way, others can write plugins to implement different approaches and compete against one another.

  25. Mathorne says:

    Well, a friend of mine plays Bejeweled blitz on facebook with the ‘elite technique’ playstyle. He score’s over 1.600.000+ each week, sometimes without powerups… My record is 1.200.000 but I still play ‘normal’ because you can’t use ‘elite technique’ on Bejeweled on consoles and on spin-offs of the game.
    So humans are still better players!!! :P
    (For now…)

  26. Nick Berry says:

    I did a similar thing a couple of years ago, using a camera to grab the screen.

    http://datagenetics.com/blog/march2009/index.html

  27. badelundwala says:
  28. Tdiz says:

    Agree with @Mathorne. I have beaten the bot score by over 400,000. Glad to know code doesn’t always win and real players can prevail without cheating.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 93,779 other followers