package main import ( "fmt" ) var wordSearch = [][]string{{"M","M","M","S","X","X","M","A","S","M"}, {"M","S","A","M","X","M","S","M","S","A"}, {"A","M","X","S","X","M","A","A","M","M"}, {"M","S","A","M","A","S","M","S","M","X"}, {"X","M","A","S","A","M","X","A","M","M"}, {"X","X","A","M","M","X","X","A","M","A"}, {"S","M","S","M","S","A","S","X","S","S"}, {"S","A","X","A","M","A","S","A","A","A"}, {"M","A","M","M","M","X","M","M","M","M"}, {"M","X","M","X","A","X","M","A","S","X"}} // func letterSearch(wordSearch string) (string, bool) { // } func main() { fmt.Println(wordSearch) for y, letterRow := range wordSearch { for x, letter := range letterRow { if letter == "X" { /* +----------+----------+----------+ | y-1, x-1 | y-1, x | y-1, x+1 | +----------+----------+----------+ | y, x-1 | letter | y, x+1 | +----------+----------+----------+ | y+1, x-1 | y+1, x | y+1, x+1 | +----------+----------+----------+ */ // var letterNeighbors []string // letterNeighbors[0] = board[y-1][x-1] // letterNeighbors[1] = board[y-1][x] // letterNeighbors[2] = board[y-1][x+1] // letterNeighbors[3] = board[y][x-1] // letterNeighbors[4] = board[y][x+1] // letterNeighbors[5] = board[y+1][x-1] // letterNeighbors[6] = board[y+1][x] // letterNeighbors[7] = board[y+1][x+1] } fmt.Println(letter) } } }