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.

[youtube=http://www.youtube.com/watch?v=h4BiLeKjXSA&w=470]

[Thanks Adam]

48 thoughts on “Bejeweled Blitz Bot Makes Your High Score Look Just Sad

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

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

      1. 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…

      2. 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 :-)

      1. @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.

  2. @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.

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

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

  4. 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?

  5. 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…

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

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

  8. 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…)

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.