Does anyone have any recommendations for resources or methods on how to create a bot in java which can play a flash game?
I am thinking of using the Robot class to watch the screen and make actions, but I need ways of finding images in images, etc. I am sure this has been done before but google searches return alot of nonsense..
It is possible to create 3D games in Flash, but it is very advanced and requires significant knowledge of the language. Almost every successful Flash game has been 2D. Flash games are also best suited for quick sessions.
I have just built a casual card playing bot (not poker) in about 3 days and it was overwhelmingly easy. The method below will work for most button based games. Of course for 3D games and fast moving 2D graphics you will need a different approach.
It's strange that there is so little useful information out there. All the articles on writing bots will link to Windows stuff with DLLs, hooks, memory snooping and all kinds of other tricks. And of course, you dont need any of this nonsense. All you need is Java and awt.Robot.
Emitting clicks is straightforward enough, the game logic is something you have to figure out on your own, so I will focus on getting the screen Input.
You start by getting a fullscreen capture. Then you find a distinct image that is present in every frame, and use that image as an anchor to calculate the offset of the top left corner of the game interface. The anchor image could be anything, even a two or three pixel wide border between the game and the browser background, just make sure to make it long enough. Then you simply search the screen capture to find where this image is located, this is a very simple algorithm that compares images one pixel at the time and changes the offset until the match is found. Once you have the UI offset, you find the relative offset to all the buttons on the screen, and take a little snapshot for each button you want to interact with. You use these offsets to detect active buttons or other indicators. As a bonus you can also use these offsets when clicking on buttons. You should make a collection of png (not jpg) images of all the buttons you want to detect. Then you run simple image comparison algorithms against the content of the screen capture.
Flash does vector font rendering and does not produce pixel-perfect consistency between different instances of the game. Also image scaling will not be consistent. Here are the ways to fight this:
Font recognition can be tricky. If you can separate the letters (usually with monochrome fonts), then you can simply use the Filtering method above to recognize each letter individually.
If you hit a wall, you can try a variety of more complicated filtering methods (blur + intensity threshold is a good combo).
The final tips are:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With