Tuesday, May 02, 2006

Scrabble with blank tiles

The Scrabble Solver engine has been modified to handle wild cards.

When one or more wild cards have been detected in the search letters, the basic selection criteria to find potential words has been changed from:

select *
from WORDLIST
where conv('<Map>', 2, 10) & letter_map = letter_map

to:

select *
from WORDLIST
where bit_count(conv('<Map>', 2, 10) & letter_map)
         >= bit_count(letter_map) - <number of wild cards>

This then needs to be filtered to ensure that the number of wild cards and of each letter in the target word does not exceed the number in the search letter string.

The SQL is generated automatically by the PHP code and the resulting where clause condition is quite large as it has to deal with each letter of the alphabet separately as well as ensuring that the overall sum of the difference between the total number of occurrences of each letter of the alphabet in the candidate word against the number available does not exceed the number of wild cards/blank tiles available.

The initial count slows up a bit from when there are no wildcards but is still acceptably fast. Once the count has been made and the first set of words displayed, moving between set using the next and previous links is pretty fast.

The search process is pretty robust - even entering a search letter string consisting entirely of wild cards doesn't throw it.

A combinatorial explosion has definitely been averted.

0 Comments:

Post a Comment

<< Home