__author__ = 'Dennis'

from log import Log
from visualize import *


class Sensor(object):
    def __init__(self):
        """
        Attributes
        ----------
        observations
            Reference to the observations list of the Entity with this Sensor.
        signals : {name: [value]}
        """
        self.observations = None
        self.signals = {}
        self.default_signals = {}

        self.init()

    def init(self):
        """
        Used to specify the signals and signal values that this Sensor can
        sense.
        """
        raise NotImplementedError()

    def set_observations(self, observations):
        """
        Args:
            observations: a dictionary that the Sensor can use to put interpreted
                observations in.
        """
        self.observations = observations

    def detects_modality(self, modality):
        return False


class Signal(object):
    def __init__(self, modality, sig_type, value, values):
        """
        Attributes
        ----------
        modality : string
            Describes the modality that this signal is in.
        type : string
            An abstract description of what this signal represents.
        value : value
            The value associated with the type
        values : []
            All possible values this signal can have.
        """
        self.modality = modality
        self.sig_type = sig_type
        self.value = value
        self.values = values


class World(object):
    """
    Handles and arranges Entities and handles interactions between any
    observable event and its observer(s).

    Describing a World consists of describing the Entities in it and the
    relations between those Entities.

    Part is based on the RegionalSenseManager from "Artificial Intelligence for
    Games" while ignoring some parts as the representation used in this simulation
    is a kind of 'distanceless' representation.
    In other words, only the essentials.

    Differences with RegionalSenseManager:
     * no distances.
     * no notification queue, since all notifications are handled immediately.
     * signals are added in the beginning phase of a frame and sent at the end
       phase, which means all signals can be sent when all entities have been
       processed.

    Attributes
    ----------
    entities : {name: Entity}
        all entities in the world identified by name
    triggers : [(string, string, string, string)]
        The connections between entities that link actions and triggers.