# Path: creamas/grid.py
# class GridAgent(CreativeAgent):
#     """An agent living in a 2D-grid with four neighbors in cardinal directions.
# 
#     The agent assumes that its environment is derived from
#     :class:`~creamas.grid.GridEnvironment`, and places itself into the grid
#     when it is initialized.
#     """
# 
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         self._xy = self.env.add_to_grid(agent=self)
#         self.name = "{}-{}({})".format(self._xy[0], self._xy[1], self.addr)
#         self._neighbors = {'N': None, 'E': None, 'S': None, 'W': None}
# 
#     @property
#     def xy(self):
#         """Agent's place (coordinate) in the grid, (x, y)-tuple.
#         """
#         return self._xy
# 
#     @property
#     def neighbors(self):
#         """Map of neighboring agent addresses in cardinal directions:
#         N, E, S, W.
#         """
#         return self._neighbors
# 
#     async def send(self, card, msg):
#         """Send message *msg* to the neighboring agent in the *card*
#         cardinal direction.
# 
#         :param str card: 'N', 'E', 'S', or 'W'.
#         :param msg: Message to the agent.
#         :returns: Response from the agent
# 
#         The method calls the neighboring agent's :meth:`rcv` with the message
#         and returns any value returned by that agent.
# 
#         This method will fail silently if there is no neighbor agent in the
#         given cardinal direction.
#         """
#         addr = self.neighbors[card]
#         if addr is None:
#             return None
#         try:
#             r_agent = await self.env.connect(addr, timeout=10)
#             return await r_agent.rcv(msg)
#         except:
#             self._log(logging.WARNING, "Could not connect to agent in {}:\n{}"
#                       .format(addr, traceback.format_exc()))
#         return None
# 
#     @expose
#     async def rcv(self, msg):
#         """Receive and handle message coming from another agent.
# 
#         This method is called from :meth:`send`.
# 
#         The base implementation does nothing, override in a subclass.
#         """
#         pass
# 
#     @expose
#     async def act(self, *args, **kwargs):
#         """See :py:class:`~creamas.core.agent.CreativeAgent.act`.
#         """
#         pass


import logging
import random
import aiomas
from creamas.grid import GridAgent
"""
.. py:module:: grid_agent
    :platform: Unix

A test implementation of a grid agent.
"""




# Path: creamas/grid.py
# class GridAgent(CreativeAgent):
#     """An agent living in a 2D-grid with four neighbors in cardinal directions.
# 
#     The agent assumes that its environment is derived from
#     :class:`~creamas.grid.GridEnvironment`, and places itself into the grid
#     when it is initialized.
#     """
# 
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         self._xy = self.env.add_to_grid(agent=self)
#         self.name = "{}-{}({})".format(self._xy[0], self._xy[1], self.addr)
#         self._neighbors = {'N': None, 'E': None, 'S': None, 'W': None}
# 
#     @property
#     def xy(self):
#         """Agent's place (coordinate) in the grid, (x, y)-tuple.
#         """
#         return self._xy
# 
#     @property
#     def neighbors(self):
#         """Map of neighboring agent addresses in cardinal directions:
#         N, E, S, W.
#         """
#         return self._neighbors
# 
#     async def send(self, card, msg):
#         """Send message *msg* to the neighboring agent in the *card*
#         cardinal direction.
# 
#         :param str card: 'N', 'E', 'S', or 'W'.
#         :param msg: Message to the agent.
#         :returns: Response from the agent
# 
#         The method calls the neighboring agent's :meth:`rcv` with the message
#         and returns any value returned by that agent.
# 
#         This method will fail silently if there is no neighbor agent in the
#         given cardinal direction.
#         """
#         addr = self.neighbors[card]
#         if addr is None:
#             return None
#         try:
#             r_agent = await self.env.connect(addr, timeout=10)
#             return await r_agent.rcv(msg)
#         except:
#             self._log(logging.WARNING, "Could not connect to agent in {}:\n{}"
#                       .format(addr, traceback.format_exc()))
#         return None
# 
#     @expose
#     async def rcv(self, msg):
#         """Receive and handle message coming from another agent.
# 
#         This method is called from :meth:`send`.
# 
#         The base implementation does nothing, override in a subclass.
#         """
#         pass
# 
#     @expose
#     async def act(self, *args, **kwargs):
#         """See :py:class:`~creamas.core.agent.CreativeAgent.act`.
#         """
#         pass


# Path: examples/grid/grid_agent.py
import logging
import random
import aiomas
from creamas.grid import GridAgent

"""
.. py:module:: grid_agent
    :platform: Unix

A test implementation of a grid agent.
"""




class ExampleGridAgent(GridAgent):