I'd like to generate the adjacency matrix for a boggle board. A boggle board is one where you have alphabets in a nxn matrix like this: http://www.wordtwist.org/sample.gif
Each cell is connected to its neighbor cell; basically we move up/down/left/right/diagonally to connect to another cell.
If each cell is viewed as a vertex in a graph, then we can find the adjacency matrix of the boggle board.
I came up with the following formulas to find the adjacent cells: Assume the index of the cells start with 0 and are numbered from left to right. i = cell index, n = number of rows/columns. So in a 3x3 matrix, i=0 would be the first cell and n is 3.
up = i-n
down = i+n
left = i-1
right = i+1
diagonal 1 = i-(n+1), i+(n+1)
diagonal 2 = i-(n-1), i+(n-1)
The above formulas fail in case of corner cells. How to exclude the invalid cells for corner cases?