 randomChar = ->
   # "Common" letters are more likely to occur than "uncommon" ones
   choose('AABBCCDDEEFFGGHHIIJKLLMMNNOOPPQRSSTTUUVWXYZ')
+
+wordFromPath = (path) ->
+  word = ''
+  if path?
+    for cell in path
+      word += cell.letter
+  word
 
 
 class Cell


    @$grid = $('<div/>')
    @$grid.addClass('ws-grid')
    for y in [0..@height-1]
      $row = $('<div/>')
      $row.appendTo(@$grid)
      for x in [0..@width-1]
        $cell = $('<div/>')
        $cell.addClass('ws-cell')
        $cell.text(@cells[y][x].letter)
        @cells[y][x].$cell = $cell
        $cell.appendTo($row)
        $cell.click($.proxy(@_cellClicked, this, @cells[y][x]))
    @$grid.appendTo($container)

    console.log(@words)


  _cellClicked: (clicked) ->
    if @selected?
      path = @path([@selected.x, @selected.y], [clicked.x, clicked.y])
      foundWord = ''
      if path?
        for cell in path
          foundWord += cell.letter

      if foundWord in @words
        console.log("\"#{foundWord}\" has been found")

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

      for cell in @selectedPath
        cell.$cell.removeClass('selected')
      @selected = null
    else
      @selected = clicked
      clicked.$cell.addClass('selected')


  _cellMouseenter: (currentCell) ->
    if @selected?
      @selectedPath = @path([@selected.x, @selected.y], [currentCell.x, currentCell.y])
      if @selectedPath?
        for cell in @selectedPath
          cell.$cell.addClass('selected')


  _cellMouseleave: (currentCell) ->
    if @selectedPath?
      for cell in @selectedPath
        continue if cell is @selected
        cell.$cell.removeClass('selected')


  _fillGrid: (wordlist, attempts) ->
