Permalink
Browse files

Merge branch 'master' of github.com:baznex/crosscram

Conflicts:
	project.clj
  • Loading branch information...
2 parents c2c024d + 9f10b5b commit 21662d39dfaa608117ebd5ef5465c9404c52a53f @timmc timmc committed May 31, 2012
Showing with 18 additions and 21 deletions.
  1. +1 −2 project.clj
  2. +5 −6 src/crosscram/board.clj
  3. +10 −11 src/crosscram/core.clj
  4. +2 −2 src/crosscram/samples/reserves_move.clj
View
@@ -1,8 +1,7 @@
(defproject crosscram "0.0.1-SNAPSHOT"
:description "crosscram game"
:url "https://github.com/baznex/crosscram"
- :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 v1.0"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:main ^:skip-aot crosscram.main)
View
@@ -1,5 +1,4 @@
-(ns crosscram.board
- (:require [clojure.core.match :as match]))
+(ns crosscram.board)
;;;
;;; Validation Functions
@@ -49,14 +48,14 @@
(nil? (two-d-get board pos-b))))
(defn- generate-horizontal-for-row [columns row]
- (take (- columns 1)
+ (take (dec columns)
(for [x (range columns)]
- [[row x] [row (+ 1 x)]])))
+ [[row x] [row (inc x)]])))
(defn- generate-vertical-for-column [rows column]
- (take (- rows 1)
+ (take (dec rows)
(for [x (range rows)]
- [[x column] [(+ 1 x) column]])))
+ [[x column] [(inc x) column]])))
(defn- generate-horizontal [rows columns]
(mapcat (partial generate-horizontal-for-row columns)
View
@@ -1,14 +1,12 @@
(ns crosscram.core
- (:require [crosscram.board :as board]
- [clojure.core.match :as match]))
-
+ (:require [crosscram.board :as board]))
(defn opposite [player]
- {:pre [(keyword? player)]
+ {:pre [(#{:horizontal :vertical} player)]
:post [(keyword? %)]}
- (match/match player
- :horizontal :vertical
- :vertical :horizontal))
+ (cond
+ (= :horizontal player) :vertical
+ :else :horizontal))
(defn over? [game]
(not (board/can-play-horizontal? (:board game))))
@@ -64,10 +62,11 @@
(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}))
+ (let [pair [game1 game2]]
+ (cond
+ (= pair [:horizontal :vertical]) {:bot-a 1 :bot-b 0 :draws 0}
+ (= pair [:vertical :horizontal]) {:bot-a 0 :bot-b 1 :draws 0}
+ :else {:bot-a 0 :bot-b 0 :draws 1})))
(defn play-symmetric [game bot-a bot-b games-to-play]
(loop [scoreboard {}]
@@ -10,15 +10,15 @@
(defn above-saves?
[game [[r1 c1] [r2 c2]]]
- (let [above-row (- r1 1)
+ (let [above-row (dec r1)
above-above-row (- r1 2)]
(and (valid-empty-pair? game [[above-row c1] [above-row c2]])
(not (valid-empty-pair?
game [[above-above-row c1] [above-above-row c2]])))))
(defn below-saves?
[game [[r1 c1] [r2 c2]]]
- (let [below-row (+ r1 1)
+ (let [below-row (inc r1)
below-below-row (+ r1 2)]
(and (valid-empty-pair? game [[below-row c1] [below-row c2]])
(not (valid-empty-pair?

0 comments on commit 21662d3

Please sign in to comment.