   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
 

        else
          console.log(@words)

        for letter in path
          $(".row#{letter.y}.col#{letter.x}").addClass("solved#{solvedNumber}")
        solvedNumber = (solvedNumber+1)%3

      else
        console.log("\"#{foundWord}\" is not a correct word")

      @selected.removeClass('selected')
      @selected = null
    else
      @selected = $cell
      $cell.addClass('selected')


  _fillGrid: (wordlist, attempts) ->

        @_tryPutWord(word) if word not in @words

    # Fill in all unfilled slots with random letters
    cell.randomFill() for cell in row for row in @cells


  _tryPutWord: (word) ->
    # Choose a random start and end point
    [startX, startY] = randomStartingPoint(@width, @height)
    [dirX, dirY] = randomDirection()
    [endX, endY] = [startX+dirX*(word.length-1), startY+dirY*(word.length-1)]

    cells = @path([startX, startY], [endX, endY])

    # Return if word will not fit in grid
    return false unless cells?

    # Return if any cell is already filled
    for cell, i in cells
      return false unless cell.willFitLetter(word[i])

    # Set the new word
    for cell, i in cells
      cell.setLetter(word[i])
    @words.push(word)
    return true


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

