From be5d1f5c80686c57e2722c6c85ef4f85d87361f5 Mon Sep 17 00:00:00 2001 From: Tim McCormack Date: Wed, 30 May 2012 23:43:11 -0400 Subject: [PATCH] #11: Remove core.match --- project.clj | 3 +-- src/crosscram/board.clj | 3 +-- src/crosscram/core.clj | 25 ++++++++++++------------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/project.clj b/project.clj index f26e125..7048e99 100644 --- a/project.clj +++ b/project.clj @@ -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) diff --git a/src/crosscram/board.clj b/src/crosscram/board.clj index ca90a64..e8f146a 100644 --- a/src/crosscram/board.clj +++ b/src/crosscram/board.clj @@ -1,5 +1,4 @@ -(ns crosscram.board - (:require [clojure.core.match :as match])) +(ns crosscram.board) ;;; ;;; Validation Functions diff --git a/src/crosscram/core.clj b/src/crosscram/core.clj index 0602891..0f45b5f 100644 --- a/src/crosscram/core.clj +++ b/src/crosscram/core.clj @@ -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)))) @@ -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 {}]