We have chosen the following implementation. It works. Nothing more, but nothing less...
4 gives our implementation of the taboo algorithm
described in Subsection 3.2. All the cells of
the grid are examined in succession, from the top-left corner to the
bottom-right one. When the focus is on cell
,
the matrix element
contains all the letters
that were not proven wrong during the last pass. If this set contains
only one value, nothing remains to do with that cell. Otherwise, the
neighbor cells are checked and all the yet affected letters are deleted
from the possible values of cell
. When taboo
is called from the pick algorithm, the set of possible values
can become empty. In such a case, a taboo error is returned.
If this set becomes a singleton, a taboo move can be done and a message is issued using the procedure given in parameter. In interactive mode print is a good choice. When nothing is given, the message is discarded.
After a taboo move, the matrix
does not reflect all the available
knowledge since the letter affected to
can
no longer be attributed to any neighbor of this cell. We have chosen
to face this problem in a lazy way : a flag is set down before dealing
with the top-left corner and set up at each taboo move. If this flag
is set when leaving the bottom-right corner, all the process is done
again. This ensures the correctness of the algorithm ... if not the
smallest execution time.
5 gives our implementation of the totem algorithm described in Subsection 3.2. The algorithm begins by a call to algorithm taboo in order to shorten the possibilities relative to each cell. Thereafter, the groups are considered each after the other and, for each letter, the possibility of a totem move is examined.
When such a move occurs, the matrix
should be updated, and it
could happen that new taboo/totem moves become available. But, here
again, we have chosen a lazy way to face this problem. After a totem
move, a flag is set up to keep track of the fact, but this flag is
taken into account only when all the
groups have been checked.
If the flag is up, a new cycle (taboo and then checking all the groups for a totem move) is undertaken.,
To facilitate the discussion, we have separated our implementation
of the pick algorithm in two parts. The 6
describe how the pivot is chosen, i.e. how is obtained the empty cell
where the attempts will be made. The chosen policy is as follow :
determine the least value (say
) of the number of remaining
possibilities over the non yet known cells. And then chose a random
a cell having either
or
possibilities left.
At first sight, chosing the minimal value seems better, but it appears
that allowing also
introduces more variability and is more
efficient.
When the pivot is chosen,