Esempio n. 1
0
// Given a blank board, find all words we can play with our given tiles, from the center.
//
// Since the center spot is always required, we just always start our words
// from there. No word will ever be long enough to go off the edge of the
// board, since that is 8 tiles away and we only ever have 7.
//
// Also, direction is not important because the board has 4-way symmetry. So,
// we always choose 7,7,RIGHT.
func InitialWords(idx index.Index, available map[byte]int) <-chan foundword {
	allowed := index.NewUnanchoredAllowedInfo(
		[]string{".", ".", ".", ".", ".", ".", "."},
		[]bool{true, true, true, true, true, true, true},
		available)

	out := make(chan foundword)

	go func() {
		defer close(out)
		for left := 0; left < 7; left++ {
			subinfo := allowed.MakeSuffix(left)
			for seq := range idx.ConstrainedSequences(subinfo) {
				out <- foundword{
					word:      string(seq),
					start:     7,
					line:      7,
					direction: RIGHT,
				}
			}
		}
	}()

	return out
}
Esempio n. 2
0
// Given a line-oriented query (find me a word that matches this sort of line),
// produce all valid words on that line.
func LineWords(line, direction int, idx index.Index, lineQuery []string, available map[byte]int) <-chan foundword {
	allowed := idx.GetAllowedLetters(lineQuery, available)

	out := make(chan foundword)
	go func() {
		defer close(out)
		for left := range GetSubSuffixes(allowed) {
			subinfo := allowed.MakeSuffix(left)
			if !subinfo.PossiblePrefix() {
				continue
			}
			for seq := range idx.ConstrainedSequences(subinfo) {
				out <- foundword{
					word:      string(seq),
					start:     left,
					line:      line,
					direction: direction,
				}
			}
		}
	}()
	return out
}