Skip to content

Instantly share code, notes, and snippets.

@naush
Created December 20, 2010 17:54
Show Gist options
  • Save naush/748712 to your computer and use it in GitHub Desktop.
Save naush/748712 to your computer and use it in GitHub Desktop.
gtp implementation example
(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