I saw the Bejeweled bot in this post on the programming subreddit. The bot didn't have any sort of AI though so I was inspired to make my own. I wrote it in Clojure and I implemented the bot so it can look ahead one step when playing, so it would prefer a 3 point move if it led to a 5 point move over making a 4 point move first. As it turns out there are a few downsides to this, like producing very many power-up gems that glow and change colors so they can't be properly recognized. This creates a bunch of "black holes" that the bot can't do anything with.
The project has no other dependencies than Clojure itself (and Java obviously) and can be downloaded as a standalone jar if you just want to try it out.
To be able to run the Clojure code from a REPL you need to have Clojure and lein installed. There are instructions how to install Clojure here and for lein here. When you have lein installed just cd into the root directory of the source and run
lein depsand you should be good to go. Open a REPL with
lein repl.
When you've fired up a REPL you should open up a Bejeweled window and start a game. Try to have the window as close to the left-hand top as possible. With the game-window visible run
(calibrate)at the REPL and it should be calibrating correctly. If it doesn't see the "Color" topic below. When it's calibrated all you have to do is run
(run true false)to make it start playing the game. The first parameter is if you want a countdown and the second parameter is wether or not it should play "stupidly". If it's false then it thinks ahead, if it's true then it just takes the best move available right now.
You can also use the standalone jar to run the game. It then runs the calibration quickly followed by starting to play. The calibration takes some time so you loose some game-time (like 5 seconds), but it's a way to test it out without installing Clojure. Just download the .jar and run:
java -jar bebot-0.1-standalone.jar
It turns out that different operating systems have different color profiles. I run a Mac so the program should work fine on all other Macs, but probably wont work on windows. I've added a helper function in utils.clj and a sample picture to help calibrate the colors for your operating system. Run
(ouput-colors x y)when you have the sample picture on your screen and where x and y is the approximate center of the first piece on the board (I've found that slightly below center yields the most stable colors).
The project is released under the MIT license. Do what you want with it.
ique (ique@3h.se)
You can download this project in either zip or tar formats.
You can also clone the project with Git by running:
$ git clone git://github.com/ique/bebot