<commit_before>'''
Created on 28 janv. 2014

@author: <NAME>
'''
from core.agents.AgentMovable import AgentMovable
from core.agents.AgentDijkstra import AgentDijkstra


class ExplorerAgent(AgentMovable, AgentDijkstra):

    def __init__(self, x, y, sma, color = 'light blue'):
        AgentMovable.__init__(self, x, y, sma) # could be ignored
        AgentDijkstra.__init__(self, x, y, sma)

        self.color = color

    def action(self):
        # TODO
        # random move
        self.randomMoveInNeighborhood()

        # compute the Dijkstra's grid
        self.computeDijkstraGrid()
<commit_msg>Implementation of action() in ExplorerAgent<commit_after>'''
Created on 28 janv. 2014

@author: <NAME>
'''
from core.agents.AgentMovable import AgentMovable
from core.agents.AgentDijkstra import AgentDijkstra
import logging as log


class ExplorerAgent(AgentMovable, AgentDijkstra):

    def __init__(self, x, y, sma, color = 'light blue'):
        AgentMovable.__init__(self, x, y, sma) # could be ignored
        AgentDijkstra.__init__(self, x, y, sma)

        self.color = color
        self.map = [[False for _ in xrange(self.sma.env.cols)] for _ in xrange(self.sma.env.rows)]

    def action(self):
        # compute the Dijkstra's grid
        unknownCells = self.computeDijkstraGrid()
        if not unknownCells:
            log.info('I finished my exploration !')
            return

        minVal = unknownCells[0][2]
        nextX, nextY = unknownCells[0][0], unknownCells[0][1]
        for x, y, value in unknownCells:
            if value < minVal:
                nextX, nextY = x, y

        self.moveTo(nextX, nextY)
        self.map[nextX][nextY] = True # Cell visited

    '''
    Override from AgentDijkstra
    Stop compute when the cell is unknown or when this is wall
    '''
    def computeDijkstraGrid(self):
        self._initDijkstraGrid()
        self.dijkstraGrid[self.x][self.y] = 0
        listNeighbours = self._fillNeighbours(self.x, self.y, 1)

        unknownCells = []
        for position in listNeighbours:
            x, y, value = position[0], position[1], position[2]
            if not self.map[x][y]:
                unknownCells.append(position)
                continue

            positionChild = self._fillNeighbours(x, y, value)
            listNeighbours.extend(positionChild)

        return unknownCells

{'fraction_non_alphanumeric': 0.10033869602032176, 'fraction_numerical': 0.009737510584250635, 'mean_word_length': 2.569486404833837, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '957829', 'n_tokens_mistral': 772, 'n_tokens_neox': 706, 'n_words': 195}