Fun project, trying to find the best implementation for creating a scrabble playing bot!
In its current state I think Unscrabbler will tell you the highest scoring go possible - whether this is strategically the best move is another challenge!
- Open up
play.ipynb
. - Coords are in form
(row, col)
. - Blanks in your hand are represented by
?
, blanks on the board are denoted bylowercase
all other letters should beUPPERCASE
, and an empty square is filled with an empty string i.e.''
.
- Planning stuff on paper is good.
- Pandas is great, but
iloc
is really slow compared to slicing a numpy array. If you have homogeneous data withRangeIndex
s the trade off might not be worth it. - Tree data structures are rad! You can write something faster than
'word' in all_words
. - Using
functools.lru_cache
on a generator is not smart. - Annoying indexing problems can often be circumvented by using iteration and slicing instead.
My first angle of attack on this project was to generate regex's for each row programmatically. Generating the regex's was slow and running them against the dictionary was too.
I decided to try the tree structure seen in word_search.py
, not expecting it to be better than regex
... it was.
I then came up with a super smart algorithm that split lines up into chunks that you could play in, then ran this through my tree. This worked pretty well.
However this wouldn't spot 'secondary words' e.g. the word ON
when playing NEW
:
BAMBOO
NEW
Where ON
is a word that's also formed when you play NEW
.
At this stage I realised that for a go to be valid, it just needs at least 1 'secondary word' and that word needs to be in the dictionary.