<commit_before>from abc import ABC, abstractmethod
from collections import namedtuple

State = namedtuple("State", ["dir", "pos", "carry"])

def dot_product(v1, v2):
    """
    Compute the dot product of the vectors v1 and v2.
    """

    return sum([i*j for i, j in zip(v1, v2)])

class Verifier(ABC):
    def __init__(self, env):
        self.env = env
        self.startDirVec = env.getDirVec()

    @abstractmethod
    def step(self):
        """
        Update verifier's internal state and returns true
        iff the agent did what he was expected to.
        """

        return

    def _obj_desc_to_poss(self, obj_desc):
        """
        Get the positions of all the objects that match the description.
        """

        poss = []

        for i in range(self.env.grid.width):
            for j in range(self.env.grid.height):
                cell = self.env.grid.get(i, j)
                if cell == None:
                    continue

                # Check if object's type matches description
                if obj_desc.type == "door" and obj_desc.state == "locked":
                    type = "locked_door"
                else:
                    type = obj_desc.type

                if cell.type != type:
                    continue
                
                # Check if object's state matches description
                if obj_desc.state in ["closed", "locked"] and cell.isOpen:
                    continue
                
                # Check if object's color matches description
                if obj_desc.color != None and cell.color != obj_desc.color:
                    continue

                # Check if object's position matches description
                if obj_desc.loc in ["left", "right", "front", "behind"]:
                    # Direction from the agent to the object
                    v = (i-self.env.startPos[0], j-self.env.startPos[1])

                    # (d1, d2) is an oriented orthonormal basis
                    d1 = self.startDirVec
                    d2 = (-d1[1], d1[0])

                    # Check if object's position matches with location
                    pos_matches = {
                        "left": dot_product(v, d2) > 0,
                        "right": dot_product(v, d2) < 0,
                        "front": dot_product(v, d1) > 0,
                        "behind": dot_product(v, d1) < 0
                    }

                    if not(pos_matches[obj_desc.loc]):
                        continue

                poss.append((i, j))
        
        return poss
    
    def _get_in_front_of_pos(self):
        """
        Get the position in front of the agent.
        The agent's state is the 2-tuple (agentDir, agentPos).
        """<commit_msg>Bug with "left" and "right" corrected in the Verifier<commit_after>from abc import ABC, abstractmethod
from collections import namedtuple

State = namedtuple("State", ["dir", "pos", "carry"])

def dot_product(v1, v2):
    """
    Compute the dot product of the vectors v1 and v2.
    """

    return sum([i*j for i, j in zip(v1, v2)])

class Verifier(ABC):
    def __init__(self, env):
        self.env = env
        self.startDirVec = env.getDirVec()

    @abstractmethod
    def step(self):
        """
        Update verifier's internal state and returns true
        iff the agent did what he was expected to.
        """

        return

    def _obj_desc_to_poss(self, obj_desc):
        """
        Get the positions of all the objects that match the description.
        """

        poss = []

        for i in range(self.env.grid.width):
            for j in range(self.env.grid.height):
                cell = self.env.grid.get(i, j)
                if cell == None:
                    continue

                # Check if object's type matches description
                if obj_desc.type == "door" and obj_desc.state == "locked":
                    type = "locked_door"
                else:
                    type = obj_desc.type

                if cell.type != type:
                    continue
                
                # Check if object's state matches description
                if obj_desc.state in ["closed", "locked"] and cell.isOpen:
                    continue
                
                # Check if object's color matches description
                if obj_desc.color != None and cell.color != obj_desc.color:
                    continue

                # Check if object's position matches description
                if obj_desc.loc in ["left", "right", "front", "behind"]:
                    # Direction from the agent to the object
                    v = (i-self.env.startPos[0], j-self.env.startPos[1])

                    # (d1, d2) is an oriented orthonormal basis
                    d1 = self.startDirVec
                    d2 = (-d1[1], d1[0])

                    # Check if object's position matches with location
                    pos_matches = {
                        "left": dot_product(v, d2) < 0,
                        "right": dot_product(v, d2) > 0,
                        "front": dot_product(v, d1) > 0,
                        "behind": dot_product(v, d1) < 0
                    }

                    if not(pos_matches[obj_desc.loc]):
                        continue

                poss.append((i, j))
                
        return poss
    
    def _get_in_front_of_pos(self):
        """
        Get the position in front of the agent.
        The agent's state is the 2-tuple (agentDir, agentPos).
        """
{'fraction_non_alphanumeric': 0.0936936936936937, 'fraction_numerical': 0.009009009009009009, 'mean_word_length': 1.3392330383480826, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 7, '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': '1024264', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1423, 'n_words': 460}