Beispiel #1
0
func getValidCoords(w *word.Word, row, col int) [][]int {
	validCoords := make([][]int, 0)

	for loopRow := row - 1; loopRow < row+2; loopRow++ {
		for loopCol := col - 1; loopCol < col+2; loopCol++ {
			if loopRow >= 0 && loopRow < b.Size() && loopCol >= 0 && loopCol < b.Size() {
				if !w.ContainsCoords(loopRow, loopCol) {
					validCoords = append(validCoords, []int{loopRow, loopCol})
				}
			}
		}
	}

	return validCoords
}
Beispiel #2
0
func findWords(w *word.Word, row, col int) {
	if isValidWord(w.Word()) {
		foundWords[w.Word()] = true
	}

	validCoordsForWord := getValidCoords(w, row, col)
	for _, coords := range validCoordsForWord {
		if d.ContainsPrefix(w.Word() + b.Letter(coords[0], coords[1])) {
			newWord := word.NewFromWord(w)
			newWord.AddLetter(b.Letter(coords[0], coords[1]), coords[0], coords[1])
			findWords(newWord, coords[0], coords[1])
		}
	}
}