Hello World/Projects/
Views: -

Automating wordfeud


Summary

After playing wordfeud for a while I realized that some of the opponents were active during unusual times of the day and never responded to chat messages, suggesting they were bots. To test this theory out I made a bot myself, impersonating the terminator.

Tools used

Python as the primary programming language
Android studio for running wordfeud on my computer
Fiddler for mapping the private wordfeud API and debugging
Frida for disabling SSL-pinning and capturing secure network traffic from wordfeud

Method

Mapping the API

After starting android studio I downloaded the wordfeud APK and signed up with a new account. I now configured frida to run on the android emulator:
$ unxz frida-server-{version}-android-{architecture}.xz # Decompress the file
$ adb root # Request root privileges as it might be required later
$ adb push frida-server /data/local/tmp/ # Send file to device
$ adb shell "chmod 755 /data/local/tmp/frida-server" # Make the file executable
$ adb shell "/data/local/tmp/frida-server &" # Start the server
I now downloaded the SSL-pinner bypassing script and injected it using the following command:
frida -U -f com.hbwares.wordfeud.free -l universal-android-ssl-check-bypass-2.js --no-pause
I could now start Fiddler and route all data traffic through it by setting it as my proxy. By using the requests module in python I could send customized requests from there.

Note that you first have to enable "Allow remote computers to connect" in Fiddlers settings and install Fiddlers custom SSL certificate in android studio by going to {computers local IP-address}:8888 and downloading it from there.

Action selection algorithm

I figured a pretty good algorithm would be to always play the move that generated the most amount of points every turn. I downloaded this python library that generates a list of words and their respective points given the board (both the multipliers and the tiles) and the players rack.

Although this worked and the bot preformed quite well, the bot could sometimes get stuck with a rack of unplayable tiles. To counter this I added support for tile swapping in some cases. I also made the bot take some possible counter moves into consideration, as it would sometimes play a <20 point word that set the opponent up for a 200+ point word.

Here is an image of how it preforms after a few days of testing:
Won:160,Lost:67,Tied:1

Other features

As I had to choose a unique username and icon I thought that the terminator would be fitting, as he, just as my program, was a robot with robot like responses. I also created some triggers for chat messages to the opponent:

Game start --> "I'm back"
Bot plays high scoring word --> "He'll live."
Opponent plays high scoring word --> "Get out."
Bot victory --> "Hasta la vista, baby"
Opponent victory --> "I'll be back"
Random chat message --> "Talk to the hand."
Emoji only chat message --> "🤖"
Question mark in chat message --> "I am not authorized to answer your question."
Opponent congratulating bot in chat --> "I love you, too, sweetheart."

Although this may seem quite basic, this method often results in surprisingly natural conversations.

Some other things I added are:

Result

I had a lot of fun during this project, and I also learned more about how private APIs can be mapped effectively. If I ever become comfortable with reinforcement learning I might come back and optimize the move selection.

As I'm planning to keep the script running in the near future, you might encounter T-800 if you keep searching for new games in wordfeud.

The code can be downloaded here:
File size: 847KB
Wordfeud_bot.zip

Back to top