func (board *Board) SetWord(word *Word) { if word.orientation == S || word.orientation == N { for i := word.y; i < word.y+word.length; i++ { value := word.value if word.orientation == N { value = helpers.Reverse(word.value) } r := rune([]rune(value)[i-word.y]) board.Set(word.x, i, r) } } // if word.orientation == NE || word.orientation == SW { // for i := 0; i < word.length; i++ { // y := word.y + i // x := word.x + i // value := word.value // if word.orientation == SW { // value = helpers.Reverse(word.value) // } // r := rune([]rune(value)[i]) // board.Set(x, y, r) // } // } if word.orientation == SE || word.orientation == NW { for i := 0; i < word.length; i++ { y := word.y + i x := word.x + i value := word.value if word.orientation == NW { value = helpers.Reverse(word.value) } r := rune([]rune(value)[i]) board.Set(x, y, r) } } if word.orientation == E || word.orientation == W { for i := word.x; i < word.x+word.length; i++ { value := word.value if word.orientation == W { value = helpers.Reverse(word.value) } r := rune([]rune(value)[i-word.x]) board.Set(i, word.y, r) } } board.words = append(board.words, word.value) }
func (board *Board) FindQuery(x, y int, orientation Orientation, wordLength int) string { var query string = "" if orientation == S || orientation == N { for i := y; i < y+wordLength; i++ { char := board.Get(x, i) if *char == GridNilValue { query = query + "_" } else { s := fmt.Sprintf("%c", *char) query = query + s } if orientation == N { query = helpers.Reverse(query) } } } // if orientation == NE || orientation == SW { // for i := 0; i < length; i++ { // y := y + i // x := x + i // // char := board.Get(x, y) // if *char == GridNilValue { // query = query + "_" // } else { // s := fmt.Sprintf("%c", *char) // query = query + s // } // if orientation == N { // query = helpers.Reverse(query) // } // // if orientation == SW { // query = helpers.Reverse(query) // } // } if orientation == SE || orientation == NW { for i := 0; i < wordLength; i++ { y := y + i x := x + i char := board.Get(x, y) if *char == GridNilValue { query = query + "_" } else { s := fmt.Sprintf("%c", *char) query = query + s } if orientation == N { query = helpers.Reverse(query) } } } if orientation == E || orientation == W { for i := x; i < x+wordLength; i++ { char := board.Get(i, y) if *char == GridNilValue { query = query + "_" } else { s := fmt.Sprintf("%c", *char) query = query + s } if orientation == W { query = helpers.Reverse(query) } } } return query }