   {:v  x
    :h  y
    :d1 (- x y)
-   :d2 (- (dec grid-width) x y)}
-  )
+   :d2 (- (dec grid-width) x y)})
+(def line-index-from-point (memoize line-index-from-point))
 
 (defn gen-lines
   [points grid-w grid-h]

(defn negamax
  ""
  [is-first-player state got-time? grid-width grid-height ret-chan]
  (loop
      [deepness 1]

    (if (and @got-time? (< deepness 10))
      (let [point (negamax-inner state
                               Double/NEGATIVE_INFINITY
                               Double/POSITIVE_INFINITY
                               got-time?
                               is-first-player
                               deepness         ; Steps
                               grid-width grid-height)]
        (when (not (empty? (point :best-move)))
          (async/>!! ret-chan point))
        (recur (inc deepness))))))

(defn -getNextMove
  "Gets the next best move"
  [charmat timeout]
  (let [ret-chan (async/chan (async/sliding-buffer 1))
        timeout-chan (async/timeout (- timeout 5))
        got-time? (atom true)
        charmat-seq (lazy-seq charmat)
        state (gen-map-from-charmat charmat-seq {true #{} false #{}} 0)

            (default-assoc h (indexes :h) x)
            (default-assoc v (indexes :v) y)
            (default-assoc d1 (indexes :d1) x)
            (default-assoc d2 (indexes :d2) x)))))))
(def gen-lines (memoize gen-lines))


(defn build-all-lines-from-state
  [state grid-w grid-h is-first-player]
  {:max (gen-lines (state is-first-player) grid-w grid-h)
   :min (gen-lines (state (not is-first-player)) grid-w grid-h)})

(defn get-value-for-point
  [{max-lines :max min-lines :min}
