source: scenarios/GerminationX/oak/src/oak/remote_agent.clj @ 437

Revision 437, 2.3 KB checked in by dave, 10 years ago (diff)

added germination x

Line 
1;; Copyright (C) 2010 FoAM vzw
2;; This program is free software: you can redistribute it and/or modify
3;; it under the terms of the GNU Affero General Public License as
4;; published by the Free Software Foundation, either version 3 of the
5;; License, or (at your option) any later version.
6;;
7;; This program is distributed in the hope that it will be useful,
8;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10;; GNU Affero General Public License for more details.
11;;
12;; You should have received a copy of the GNU Affero General Public License
13;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
15(ns oak.remote-agent
16  (:use oak.io)
17  (:import
18   java.net.Socket
19   java.io.File
20   java.io.IOException
21   java.util.Random
22   FAtiMA.util.parsers.SocketListener
23   FAtiMA.autobiographicalMemory.AutobiographicalMemory))
24
25(defstruct remote-agent
26  :properties
27  :name
28  :role
29  :display-name
30  :socket
31  :relations
32  :emotions
33  :said
34  :done
35  :random)
36
37(def remote-agent-properties (accessor remote-agent :properties))
38(def remote-agent-name (accessor remote-agent :name))
39(def remote-agent-role (accessor remote-agent :role))
40(def remote-agent-display-name (accessor remote-agent :display-name))
41(def remote-agent-socket (accessor remote-agent :socket))
42(def remote-agent-relations (accessor remote-agent :relations))
43(def remote-agent-emotions (accessor remote-agent :emotions))
44(def remote-agent-said (accessor remote-agent :said))
45(def remote-agent-done (accessor remote-agent :done))
46(def remote-agent-random (accessor remote-agent :random))
47
48(defn remote-agent-add-property [agent property]
49  (merge agent {:properties (cons property (remote-agent-properties agent))}))
50
51(defn make-remote-agent [socket world]
52  ;(.configureBlocking socket false)
53  ;(. (AutobiographicalMemory/GetInstance) setSelf name)
54  (let [toks (.split (read-msg socket) " ")]
55    (send-msg socket "OK")
56    (struct
57     remote-agent
58     (reduce
59      (fn [r prop]
60        (let [tv (.split prop ":")]
61          (assoc r (first tv) (second tv))))
62      {}
63      (nthnext toks 3))
64     (nth toks 0)
65     (nth toks 1)
66     (nth toks 2)
67     socket
68     "none yet"
69     "none yet"
70     '()
71     '()
72     (new java.util.Random))))
73
Note: See TracBrowser for help on using the repository browser.