Final year Computer Science student Clíodhna Connolly describes her experiences in a Software Engineering Project module…

Battle of the Scrabble Bots

One nice thing about Computer Science is that mixed in with all the theory is a heavy emphasis on the practical. It means that while you’re completing your degree, you’re consistently working on projects and assignments that show you how the theory relates to real life. Every year, excluding final, CS students complete a “Software Engineering Project” module. The assignments are typically more interesting than normal programming assignments, but nothing beat my excitement of when we were assigned Scrabble.

The ultimate aim of our module was that we’d build a scrabble-bot. We had around 10-weeks to build ourselves up to that point and at the culmination of the module we’d have a battle of the bots to compete for first place! As it turns out there was a lot of people who had never played Scrabble, so a lecture or two was dedicated to how to play the game and taught us new words like “Quizzify”, which inspired a few team names.

Week to Week
If the technical aspect appeals to you; we were programming entirely in Java and our user interface (the visual bit you see) was just the console (the black thing people fake-type in in movies). Every two weeks we were given a new assignment description, our end goal was to complete an entire Scrabble game but the lecturer laid it out so that we built it up gradually, in small manageable steps.

THE BEAUTIFUL USER INTERFACE

The Beautiful User Interface

For instance, the first assignment involved setting up the playing board, the player profile and the pool of tiles. We were free to split these tasks among our groups as we saw fit but most people split it so that each person took one area. The tasks started off easy enough just setting about the basics of what we’d need, as in for Player we need somewhere to store their name, their score and their frame (the thing that holds their tiles).

After the assignment was due the lecturer would release his solution to that week’s tasks. This is what I found to be the most useful part of the class. Being able to compare your code to an actual experienced coder was great to see. You could tell if what you were doing was right or wrong and where you could improve. The other thing about this is that, if the week before had gone terribly for you and none of what you submitted worked, you could take the previous solutions code and work off that for the following week so you were never at a disadvantage if you’d had a particularly bad submission.

Building our Bots

For the last assignment, we were tasked with building our bot. We were to base our bot off of code that the lecturer provided, so that when we’d compete with others the bots would play nicely. The rules were that we had a three-second limit per turn but our bot would have access to a dictionary. The time-limit was what really made things interesting. Without it you could have a bot sit there for hours before it’d make a turn, going through every possible permutation the board and dictionary would allow. Because of this we had to start making decisions about what we thought would be the most time-efficient and highest-scoring methods.

We started simple, our plan was to identify a position on the board where we could place one tile to make a two letter word with what was already on the board. Even this simple plan had a lot of checks we had to do:
• Check all the surrounding tiles were also empty or else you’d end up making an unintentional word
• Check the dictionary for two letter words using the tile already placed and what we had in our frame
• Check which orientation of placing the tile was best, before or after placed tile
• Check was there position we could place a better 2 letter word

THE SOFTWARE YOU USE TO WRITE YOUR CODE IN

The software you use to write your code in

Chaos, chaos everywhere

After a while we got our simple plan working. We even got up to four letter words being able to be placed before and after a placed tile. Behind the scenes, I had been working on what I referred to as BetterBot. Bot was our submission, he was clean, he was simple, he worked. BetterBot was an abomination. However, BetterBot could play well, it could extend words and it never ever passed. It always found a word to play and it was typically good. The problem with BetterBot, apart from being hideous code, was that it entirely ignored the time limit; sometimes it would take 2 seconds sometimes 10. Because of this inconsistency we thought we could never use it and it’s why I kept it on the back-burner as more of just my entertainment as opposed to anything we could submit.

 I THINK MY FILENAMES SAY SOMETHING ABOUT MY STATE OF MIND AT THE TIME!

I think my filenames say something about my state of mind at the time!

The bots were due to be submitted at the end of a 2-hour practical on a Friday. Really, entering that class we all knew that we wouldn’t get much done because the deadline was so close. We imagined that we’d just be cleaning up our submissions but then it was announced that they were doing away with the time-limit. This is when the chaos hit. I wish someone had filmed us because it was probably the liveliest practical we’d ever had.

People were testing their bots against others in the class. Bots were crashing out left and right. Some like our group were taking their secret bots out of the background and trying to get them to work well enough that they could be submitted. Our BetterBot became BestBot and we desperately tried to clear all our errors in the hopes we could submit him. The competition mark counted towards our grade and the competitiveness in the class was palpable.

The Aftermath

The following Friday we received an email with the competition results. As Dr Chris Bleakley, the lecturer, explains the competition was played in 3 rounds.
“In the first round, each Bot played all of the other Bots. Each pair of Bots played each other twice (home and away, if you like). In the second round, I played the top 4 Bots against each other. Each pair played 20 times. In the third round, I played the top 2 Bots from the previous round against each other 60 times. Games were recorded as incomplete for both Bots if one of the Bots crashed or hung or if the game lasted more than 10 minutes. The purpose of the second and third rounds was to remove any confusion due to incomplete games and to average out the random element over more games.”

4 - OUR BOT PLAYING THE OVERALL WINNERS

Our bot playing the overall winners

The first round took a whopping 30 hours so it’s no surprise he took a week to come back to us with results. My team placed 6th which we were more than happy with. We ended up winning 20 games and 8040 points and as we put it, we came second fastest out of the top six by a mile.

This module was probably one of the most useful modules I did in Computer Science. I still talk about it in job interviews because so many skills were tested in it and we learnt so much. Having a somewhat useful application built at the end of the day was also an added plus. I still haven’t beaten my Scrabble bot but that’s probably more to do with my attention span being incompatible with Scrabble than anything else!