Created
December 20, 2010 17:54
-
-
Save naush/748712 to your computer and use it in GitHub Desktop.
gtp implementation example
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
| (ns gtp.example.console | |
| (:refer-clojure :exclude [name]) | |
| (:require [gtp.core :as gtp] :reload) | |
| (:gen-class)) | |
| (defn board [] | |
| (let [size (atom 19)] | |
| {:set-size #(reset! size %1) | |
| :get-size @size})) | |
| (def current-board (board)) | |
| (defn move-generator [color] | |
| (let [max (current-board :get-size)] | |
| (str (char (rand-nth (range 65 (+ 64 max)))) (rand-nth (range 1 max))))) | |
| (gtp/make-name-command #(str "maru")) | |
| (gtp/make-version-command #(str "0.1")) | |
| (gtp/make-komi-command #(str %1)) | |
| (gtp/make-quit-command #(str "quit")) | |
| (gtp/make-boardsize-command #((current-board :set-size) %1)) | |
| (gtp/make-clear-board-command #(str "")) | |
| (gtp/make-play-command #(str "play " (first %1) " " (second %1))) | |
| (gtp/make-genmove-command #(move-generator %1)) | |
| (defn -main [& args] | |
| (loop [output (read-line)] | |
| (println (gtp/parse output)) | |
| (if (= output "quit") | |
| (System/exit 0) | |
| (recur (read-line))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment