              :k "king" :K "king"
              :p "pawn" :P "pawn"})
 
-(def file->i
-  "Convert a letter file to an integer index (eg \"a\" -> 0)"
-  (let [m (into {}
-                (map-indexed
-                 (fn [i c] [c i])
-                 (seq "abcdefgh")))]
-    (fn [f] (get m (char f)))))
+(let [f-to-i (into {}
+              (map-indexed
+               (fn [i c] [c i])
+               (seq "abcdefgh")))
+      i-to-f (map-invert f-to-i)]
+  (do
+    (defn file->i [f] (get f-to-i (char f)))
+    (defn i->file [i] (get i-to-f i))))
 
 (defn parse-int
   [i]

(ns chess.core
  (:require [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]
            [clojure.string :refer [upper-case]]))

(def initial-board
  [[:r :n :b :q :k :b :n :r]
   [:p :p :p :p :p :p :p :p]
   [:. :. :. :. :. :. :. :.]
   [:. :. :. :. :. :. :. :.]
   [:. :. :. :. :. :. :. :.]
   [:. :. :. :. :. :. :. :.]
   [:P :P :P :P :P :P :P :P]
   [:R :N :B :Q :K :B :N :R]])

(def empty-sq :.)

(def pieces {:r "rook" :R "rook"
             :n "knight" :N "knight"

  (let [[f r] (vec p)]
    [(- 8 (parse-int r)) (file->i f)]))

(defn in
  "Get the contents of a square on the board. Nil if empty"
  [board sq]
  (get-in board (to-board-ks sq)))

(defn put
  "Puts a piece at a square in the board"
