From a0eb1a0aa53ea20a16e6cdf74a6f0ac01c688290 Mon Sep 17 00:00:00 2001 From: Dan Lidral-Porter Date: Fri, 29 Mar 2013 06:51:23 -0700 Subject: [PATCH] add move advantage bot --- src/crosscram/samples/move_advantage.clj | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/crosscram/samples/move_advantage.clj diff --git a/src/crosscram/samples/move_advantage.clj b/src/crosscram/samples/move_advantage.clj new file mode 100644 index 0000000..3584c6d --- /dev/null +++ b/src/crosscram/samples/move_advantage.clj @@ -0,0 +1,26 @@ +(ns crosscram.samples.move-advantage + "Maximizes the difference between the number of moves we'll have left and the + number of moves our opponent will have left." + (:require [crosscram.game :as cc])) + +(defn evaluate + [{:keys [board player-id] :as game}] + (let [our-moves (count (cc/available-moves board)) + their-moves (-> board + (cc/rotate-board 1) + cc/available-moves + count)] + (- our-moves their-moves))) + +(defn make-move + [game] + (let [board (:board game) + possible-states (map (partial cc/move game) + (cc/available-moves board))] + (->> (for [gs possible-states] + ((juxt (comp last :history) evaluate) gs)) + (reduce (fn [[_ best-val :as best] [_ val :as candidate]] + (if (> val best-val) + candidate + best))) + first)))