       (swap! state assoc-in [side (first r)] 0)
       (swap! state update-in [side (first r)] #(max (- % (last r)) 0)))))
 
+(defn gain-agenda-point [state side n]
+  (gain state side :agenda-point n)
+  (when (>= (get-in @state [side :agenda-point]) (get-in @state [side :agenda-point-req]))
+    (system-msg state side "wins the game")))
+
+(defn add-prop [state side card key n]
+  (update! state side (update-in card [key] #(+ % n))))
+
+(defn set-prop [state side card & args]
+  (update! state side (apply assoc (cons card args))))
+
+(defn score [state side {:keys [card]}]
+  (when (>= (:advance-counter card) (:advancementcost card))
+    (let [moved-card (move state side card :scored)
+          c (card-init state side moved-card)]
+      (system-msg state side (str "scores " (:title c) " and gains " (:agendapoints c) " agenda points"))
+      (gain-agenda-point state side (:agendapoints c))
+      (set-prop state side c :advance-counter 0)
+      (trigger-event state side :agenda-scored c))))
+
+(defn steal [state side card]
+  (let [c (move state side card :scored)]
+    (system-msg state side (str "steals " (:titlte c) " and gains " (:agendapoints c) " agenda poitns"))
+    (gain-agenda-point state side (:agendapoints c))
+    (set-prop state side c :advance-counter 0)
+    (trigger-event state side :agenda-scored c)))
+
 (defn run [state side {:keys [server] :as args}]
   (pay state :runner :click 1)
   (let [s (case server

    (flatline state))
  (trigger-event state side :turn-ends nil)
  (swap! state assoc :end-turn true))

(defn add-prop [state side card key n]
  (update! state side (update-in card [key] #(+ % n))))

(defn set-prop [state side card & args]
  (update! state side (apply assoc (cons card args))))

(defn purge [state side]
  (doseq [card (get-in @state [:runner :rig :program])]

  (get-in @state [:corp :discard]))

(defmethod access :remote [state side server]
  (get-in @state [:corp :servers :remote (js/parseInt (last server)) :content]))

(defn successful-run [state side]
  (let [server (get-in @state [:run :server])]
    (swap! state update-in [:runner :register :sucessful-run] #(conj % (first server)))
    (trigger-event state side :successful-run (first server))
    (let [cards (access state side server 1)]
      (handle-access state side cards)
      (system-msg state side (str "accesses " (join ", "(map :title cards)))))
    (swap! state assoc :run nil)))

