Permalink
Browse files

add first two naive bots

  • Loading branch information...
1 parent 989b2d6 commit c610ddfafa4679e1aacab28bff10e492ab1c966b @reiddraper committed Apr 15, 2012
Showing with 29 additions and 0 deletions.
  1. +29 −0 src/crosscram/bots.clj
@@ -0,0 +1,29 @@
+(ns crosscram.bots
+ (:require [crosscram.core :as crosscram])
+ (:require [clojure.core.match :as match])
+ (:require [clojure.set :as set])
+ (:require clojure.pprint)
+ )
+
+(defn brute-force-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))]
+
+ (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)))))))

0 comments on commit c610ddf

Please sign in to comment.