Participate in the Concurrency Challenge
From Beautifulcode
Speed Scrabble is a game for two or more players that takes only a few minutes to play. The rules are simple:
- Spread the tiles face down on the table. Each player chooses 15 tiles at random, and puts them in front of herself; the rest are set aside.
- Someone says "Go!" Every player turns over 7 of her tiles and
starts trying to make words with them. Words must crisscross in the
standard Scrabble way, like this:
a three e able
The players' "boards" are independent---each player only uses her own
characters. - As soon as any player has made a board using all 7 of her characters, she shouts, "Go!" Every player turns over another character, so that all players now have 8 characters to use. Players may rearrange their pre-existing words when and as they please---they do not have to stick to their earlier choices.
- When any player has used all 8 of her characters, she shouts, "Go!", and everyone turns over their ninth tile. This repeats until everyone has turned over all 15 tiles. The winner is whoever makes a legal 15-character board first.
The challenge is to design the architecture of a "referee" program
for a computer Speed Scrabble tournament. Contestants will submit
classes that extend an abstract base class called
IPlayScrabble that the contest organizers will provide.
These classes will be loaded by a SpeedScrabble program,
which will create an instance of each one and pass it the dictionary
of words that can be used in the game, and its first seven tiles.
Each player will run in its own thread, in parallel with its competitors. As soon as it has made a board with the tiles it has, it will request another tile from the "referee". The first player to complete a 15-tile board wins.
This is trickier than it first seems because players have to be able handle "interrupts", i.e., notice when the referee is trying to give them another tile that they didn't ask for because some other player has taken the lead. (It's often the case that a set of $N$ tiles has no solution, but an $N+1$-tile extension does, so not taking tiles as soon as they're offered is a good way to come in last.) At the same time, when the central referee is handing out tiles, it must never wait for a player to accept one before moving on to the next player, because if it takes player P two seconds to say, "Yes, thank you, carry on," that's two seconds that player P+1 has lost.
So: how will the central referee hand out characters? What methods will you give players, and which ones will they be trusted to implement themselves? Most importantly, how will you convince sceptics that your synchronization and communication scheme can't deadlock, and won't ever starve one player because of something another player has done?
To participate:
- Sign up for an account.
- Click edit, and then add the title of your in the "Solutions" section. Enclose the title in double brackets to create a new link.
- Save this page, click your new entry link, and enter the text of your solution.
Add Your Solutions Here
Attempted Java solution from newbie
