Created
September 8, 2015 09:19
-
-
Save dsociative/d5dd3bb6467555522e43 to your computer and use it in GitHub Desktop.
This file contains 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 travian.troops | |
(:gen-class) | |
(:require [clj-http.client :as client])) | |
(use | |
'travian.parse | |
'[travian.request :as request] | |
) | |
(defn moving? | |
[{name :name}] | |
(re-matches #"Collection:Troops:moving:[0-9]+" name)) | |
(defn moves | |
[data] | |
(let [troops (flatten (map travian.parse/extract (filter moving? data)))] | |
troops)) | |
(defn raid | |
[session src dest units] | |
(request/send-troops session 4 src dest units)) | |
(defn go-to-or-from | |
[village-id] | |
(fn | |
[move] | |
(let [{:keys [movement]} move] | |
(or | |
(= village-id (:villageIdTarget movement)) | |
(= village-id (:villageIdStart movement)) | |
)))) | |
(defn farm | |
[session moves src dest units] | |
(let [active (filter (go-to-or-from dest) moves)] | |
(if | |
(empty? active) | |
(raid session src dest units) | |
))) | |
(defn units | |
[n] | |
(let [units {:1 2 :2 0 :3 0 :4 0 :5 0 :6 0 :7 0 :8 0 :9 0 :10 0 :11 0}] | |
(conj units n))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment