Skip to content

Commit

Permalink
#11: Remove core.match
Browse files Browse the repository at this point in the history
  • Loading branch information
timmc committed May 31, 2012
1 parent 8401826 commit be5d1f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
3 changes: 1 addition & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(defproject crosscram "0.0.1-SNAPSHOT"
:description "crosscram game"
:dependencies [[org.clojure/clojure "1.3.0"]
[org.clojure/core.match "0.2.0-alpha9"]]
:dependencies [[org.clojure/clojure "1.3.0"]]
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:main ^:skip-aot crosscram.main)
3 changes: 1 addition & 2 deletions src/crosscram/board.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(ns crosscram.board
(:require [clojure.core.match :as match]))
(ns crosscram.board)

;;;
;;; Validation Functions
Expand Down
25 changes: 12 additions & 13 deletions src/crosscram/core.clj
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
(ns crosscram.core
(:require [crosscram.board :as board]
[clojure.core.match :as match]))
(:require [crosscram.board :as board]))

(def orientations #{:horizontal :vertical})

(defn opposite [player]
{:pre [(keyword? player)]
:post [(keyword? %)]}
(match/match player
:horizontal :vertical
:vertical :horizontal))
{:pre [(keyword? player), (contains? orientations player)]
:post [(contains? orientations %)]}
(first (disj orientations player)))

(defn over? [game]
(not (board/can-play-horizontal? (:board game))))
Expand Down Expand Up @@ -57,15 +55,16 @@
bot-funs (cycle [bot-a bot-b])]
(if (over? g)
g
(let [new-game (apply play-piece g ((first bot-funs) g))]
(let [move ((first bot-funs) g)
_ (println (first bot-funs) move)
new-game (apply play-piece g move)]
(recur new-game (rest bot-funs))))))

(defn score [game1 game2]
{:pre [(keyword? game1), (keyword? game2)]}
(match/match [game1 game2]
[:horizontal :vertical] {:bot-a 1 :bot-b 0 :draws 0}
[:vertical :horizontal] {:bot-a 0 :bot-b 1 :draws 0}
[_ _] {:bot-a 0 :bot-b 0 :draws 1}))
{:pre [(contains? orientations game1), (contains? orientations game2)]}
(let [outcomes {[:horizontal :vertical] {:bot-a 1 :bot-b 0 :draws 0}
[:vertical :horizontal] {:bot-a 0 :bot-b 1 :draws 0}}]
(get outcomes [game1 game2] {:bot-a 0 :bot-b 0 :draws 1})))

(defn play-symmetric [game bot-a bot-b games-to-play]
(loop [scoreboard {}]
Expand Down

0 comments on commit be5d1f5

Please sign in to comment.