Programming Showdown Battle Bot - A socket battle bot for Showdown

Disclaimer : English is not my native language, there might be some mistakes. Please forgive me.

Hello everyone.
I come here to present a project developed during a free school project a while ago. Having left this school this year, I am now free to present it to you in due form, as well as continue to develop it after a year off.

There are a lot of chatbots circulating on showdown, but surprisingly very few bots of fighting, while the system seemed to me quite suitable for this kind of project. It is from this observation that I go for this project with the aim of achieving correct results, and why not a totally autonomous and competitive bot. I developed it in python 3.5 with the modules requests, websockets and asyncio.

You can find the project on github here: https://github.com/Synedh/showdown-battle-bot

So, how does that works :

The bot works in three parts : I/O process, game engine an AI.

I/O process is about sending and receiving datas from Showdown's servers.
Showdown use websockets to send datas, therefor I use them too. Then all I had to do is to follow the Pokemon Showdown Protocol. Tricky part is about connection, the protocol is not very precise about it. To be simple, once connected to the websockets' server, you receive a message formated this way : |challstr|<CHALLSTR>. Then you send a post request to https://play.pokemonshowdown.com/action.php with the <CHALLSTR> but web-formated (beware of special characters) and the ids of the bot. In the answer, you have to extract the assertion part. Finally, you have to send a websrequest this format : /trn <USERNAME>,0,<ASSERTION> where <USERNAME> is the one you gave previously and <ASSERTION> the one you extract just before.

Game engine is about simulate battles, teams and pokemons.
For each battle, an object is created and filled with information sent by Showdown's servers. For the unknowns information (enemy's team), moves are filled thanks to a file take from source code where moves and pokemons are listed.

Bot's brain, the AI.
At the moment I write theses lines, the AI is static. It means if you put the bot in the same situation X times, it will act the same way X times. On each turn, a player (here, the bot) has the choice between switch and use a move. To choose the move, the bot "just" calculate the efficiency of each move using pokemon's calculating formula. To choose a pokemon to switch, the bot will parse every of its pokemons and calculate its efficiency based on speed and moves power (same calculus as the above one). All the difficulty of building the bot is to choose between use a move and switch. What I mean here is : I (the bot) know that this pokemon is dangerous, but is it enough dangerous to switch, or attack is more interresting ? Today, this choice is manual. There is a value beyond wich the bot switch. In the long term, I would like to modify this behavior to allow the bot to evolve, based on its previous experiences, but that's hard and I miss some knowledge.

Here end this little presentation. Of course feel free to read the code, test the bot and make feedback, as well as fork the project or create pull requests if it interest you. In the next months, I would like to learn to use Tenserflow to improve AI, but it will takes me some times to be able to use it properly.

Thanks for your time !
 
There's some research I wanted to do with a bot like this one, but I'm unsure how to use it as the documentation is (for good reason) sparse and I'm unfamiliar with some of the structures used. If you ever come online again, I'd love for you to give me the opportunity to ask you some questions about your code.
 

Users Who Are Viewing This Thread (Users: 1, Guests: 0)

Top