Created
April 18, 2012 23:35
-
-
Save reiddraper/2417386 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (require '[crosscram.core :as crosscram] :reload) | |
| (require '[clojure.core.match :as match]) | |
| (require '[clojure.set :as set]) | |
| (require 'clojure.pprint) | |
| (defn move [game] | |
| (let [rows (:rows game) | |
| columns (:columns game)] | |
| (loop [moves (match/match (:next-player game) | |
| :horizontal (crosscram/generate-horizontal rows columns) | |
| :vertical (crosscram/generate-vertical rows columns))] | |
| (if (apply crosscram/location-empty? (:board game) (first moves)) | |
| (first moves) | |
| (recur (rest moves)))))) | |
| (defn random-moves [game] | |
| (let [rows (:rows game) | |
| columns (:columns game)] | |
| (loop [moves (match/match (:next-player game) | |
| :horizontal (crosscram/generate-horizontal rows columns) | |
| :vertical (crosscram/generate-vertical rows columns))] | |
| (let [m (set/difference (set moves) (set (map :move (:history game)))) | |
| random-move (rand-nth (vec m))] | |
| (if (apply crosscram/location-empty? (:board game) random-move) | |
| random-move | |
| (recur (remove #{random-move} m))))))) | |
| (def g (crosscram/new-game 9 9 :horizontal)) | |
| (time (clojure.pprint/pprint (apply merge-with + | |
| (map (fn [k] {k 1}) | |
| (map :winner (for [x (range 100)] (crosscram/play-symmetric g random-moves move 10))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment