Debian Codegraph @

src/mas/agent.h

raw symbols SCIP
1 /***************************************************************************
2 agent.h - description
3 -------------------
4 begin : nov 29th 2005
5 copyright : (C) 2005-2006 by Duong Khang NGUYEN
6 email : neoneurone @ gmail com
7 author : Victor STINNER
8
9 $Id: agent.h 375 2008-10-28 14:47:15Z neoneurone $
10 ***************************************************************************/
11
12 /***************************************************************************
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * any later version. *
18 * *
19 ***************************************************************************/
20
21
22 #ifndef _OPENCITY_AGENT_H_
23 #define _OPENCITY_AGENT_H_ 1
24
25 #define MAS_NDEBUG 1 // Debugging off
26
27 #include "role.h"
28 #include "main.h" ///< OpenCity specifics
29
30 #ifndef MAS_NDEBUG
31 #define MAS_DEBUG( msg ) OPENCITY_DEBUG( msg )
32 #else
33 #define MAS_DEBUG( msg )
34 #endif
35
36 #include <ostream>
37 #include <list>
38
39 // Forward declaration
40 class Kernel;
41 class Environment;
42 class Message;
43
44 typedef unsigned int AgentID_t;
45
46
47 /*=====================================================================*/
48 /** This interface shows common methods of all agents in a Multi-Agent System
49 @author Victor STINNER
50 */
51 class Agent
52 {
53 public:
54 typedef enum
55 {
56 AGENT_BORN,
57 AGENT_LIVE,
58 AGENT_DIE
59 } agent_state_t;
60
61 Agent(Kernel& kernel, Environment& env, int x, int y, MAS_ROLE role);
62 virtual ~Agent();
63
64 void receiveMessage(const Message& msg);
65 void sendMessage(MAS_ROLE role, const Message& msg);
66 void sendMessageToAgent(AgentID_t agent, const Message& msg);
67 virtual void processMessage();
68
69 virtual void born();
70 virtual void live();
71 virtual void die();
72
73 unsigned int getX() const;
74 unsigned int getY() const;
75
76 Agent* lookForAgent(MAS_DIRECTION dir, unsigned long max_distance);
77
78 AgentID_t getId() const;
79 MAS_ROLE getRole() const;
80
81 //========================================================================
82 /** Move the agent accordingly to the current direction
83 @return true if the agent has move, false otherwise
84 */
85 bool moveDirection();
86 bool move(int x, int y);
87
88 bool canMove(int x, int y) const;
89 bool canMove(MAS_DIRECTION dir, int &x, int &y) const;
90 bool canMove(MAS_DIRECTION dir) const;
91
92 //========================================================================
93 /** Move the agent randomly
94 @return true if the agent has move, false otherwise
95 */
96 bool randomMove(int turn_percent=60);
97
98 virtual void output(std::ostream& os) const;
99 friend std::ostream& operator<<(std::ostream& os, const Agent& agent);
100
101
102 /*=====================================================================*/
103 /* OPENCITY SPECIFIC */
104 /*=====================================================================*/
105 //========================================================================
106 /** Returns the OpenCity's GRAPHIC_CODE of the agent
107 */
108 const OPENCITY_GRAPHIC_CODE
109 GetGraphicCode() const;
110
111 void
112 SetGraphicCode( const OPENCITY_GRAPHIC_CODE gc );
113
114
115 protected:
116 bool doRandomMove(int turn_percent);
117 Kernel& m_kernel;
118 Environment& m_environment;
119 int m_x, m_y;
120 MAS_DIRECTION m_direction;
121 unsigned int m_move_speed;
122 MAS_ROLE m_role;
123 agent_state_t m_agent_state;
124 std::list<Message> m_messages;
125
126 /*=====================================================================*/
127 /* OPENCITY SPECIFIC */
128 /*=====================================================================*/
129 OPENCITY_GRAPHIC_CODE m_enumGC; ///< OpenCity's graphic code
130
131 private:
132 AgentID_t m_id;
133 };
134 #endif
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167