   choose('AABBCCDDEEFFGGHHIIJKLLMMNNOOPPQRSSTTUUVWXYZ')
 
 
+class Cell
+  constructor: (@x, @y) ->
+
+  willFitLetter: (letter) ->
+    not @letter? or @letter is letter
+
+  setLetter: (@letter) ->
+
+  randomFill: ->
+    @letter = randomChar() unless @letter?
+
+
 module.exports = class LetterGrid
   constructor: ($container, @width=8, @height=8, wordlist=defaultWordlist) ->
     # Create empty grid then fill with words
-    @grid = (null for x in [1..@width] for y in [1..@height])
-    @_fillGrid(wordlist, 20)
+    @cells = (new Cell(x, y) for x in [0..@width-1] for y in [0..@height-1])
+    @_fillGrid(wordlist, 15)
 
     @selected = null
 

        @_tryPutWord(word) if word not in @words

    # Fill in all unfilled slots with random letters
    for x in [0..@width-1]
      for y in [0..@height-1]
        if @grid[y][x] is null
          @grid[y][x] = randomChar()


  _tryPutWord: (word) ->
    [startX, startY] = randomStartingPoint(@width, @height)
    [diffX, diffY] = randomDirection()

    # Check that the word will fit at the chosen position
    x = startX
    y = startY
    for i in [0..word.length-1]
      # Word has gone off the grid
      if x<0 or x>=@grid[0].length or y<0 or y>=@grid.length
        return false

      # Letter slot is already occupied and doesn't fit with the current word
      if @grid[y][x]? and @grid[y][x] isnt word[i]
        return false

      # Move to next letter position
      x += diffX
      y += diffY

    # Place the word into the grid
    x = startX
    y = startY
    for i in [0..word.length-1]
      @grid[y][x] = word[i]
      x += diffX
      y += diffY

    @words.push(word)
    return true


  reconstructWord: (start, end) ->
    [x, y] = start
    [endX, endY] = end


    stepX = if diffX==0 then 0 else diffX/Math.abs(diffX)
    stepY = if diffY==0 then 0 else diffY/Math.abs(diffY)

    cellList = []

    while x>=0 and y>=0 and x<@width and y<@height
      cellList.push(@cells[y][x])
      if x is endX and y is endY
        return cellList
      x += stepX
      y += stepY

