been working on a bot to play the game bookworm adventures
so far the bot can take a screenshot of the game while it's running, parse the grid of tiles, and find the possible words it could spell
the grid image is parsed by thresholding each tile and comparing it to a prepared set of letter images, which works well since the letter part of each tile is almost completely black
it also detects gem tiles and plague tiles using the tile's average hue
i haven't seen it fail yet on gem tiles, but i tried to implement this for smashed tiles and it didn't work anywhere near consistently enough
smashed tiles have a hue too similar to diamond tiles
i tried to use brightness as well as hue but it didn't work because the brightness of tiles varies too much (even ignoring the black pixels)
might try to just cut the center out and compare the tile uncropped to a smashed tile image
locked tiles are an issue as well, they're near identical to normal tiles if you average everything out
locked tiles are one of the tiles i really need to be able to detect so the bot can know these tiles can't be used, i could probably go without detecting plague/smashed tiles
unless i went and tried to click every tile after a word failed to submit, and checked which ones couldn't be selected, but again not an ideal solution
there's also other tile types from the sequel bookworm adventures 2 that i haven't done yet, fire tiles might be a problem
would prefer to avoid using opencv because it's a bit overkill and my bot is written in java, but there would definitely be something in there that would solve these problems
the dictionary works by creating a tree when it loads the words, so i don't have to check over every word (probably slow) or every permutation of letters (definitely slow)
each node in the tree represents a letter (e.g. 'f') and it has child nodes representing the number of times the next letter is in the word (e.g. 0, 1, 2... 'g's)
at the bottom there is a list of unsorted (i.e. 'balloon' not 'abllnoo') words
when searching we want all subanagrams, not just all anagrams, so we take not just the nodes corresponding to the given set of letters, but also all recursively sum all sets of letters less than the given set (e.g. if the letters contain 2 't's, we want all branches with 0, 1, or 2 't's)
i realised after writing it that my dictionary implementation is probably inefficient so i might change it later, since it's unnecessary to store 26 layers when no word has all 26 letters
instead i could just make a tree where each node is a letter+frequency and the layers are the position of a letter in the word, although what i have now seems fast enough
java's Robot class made it easy to take a screenshot and will make it easy to move mouse and click when i get to that part, but one weakness is that i can't take a screenshot unless the game window is maximised and focused
apparently there are ways to achieve this but it would involve some annoying windows api stuff, i'll do this later if at all
i want to try different strategies of spelling words and see what the fastest/average times i can get in arena mode (where you fight all the bosses in order and are timed) are
one strategy i used while playing the game normally was 'saving up' a long word with a lot of gem tiles and then finally use it when i get the right tiles, maybe the bot could do better by using up the uncommon and difficult to use letters like 'k' and 'v' in short words without using the gem tiles (which give a percentage damage boost) so it can do a very long word using a power up potion
.
todo add images to this post