예제 #1
0
    def get_environment(self):
        if self.__mood_flag:
            if self.__get_environment_count == self.__max_get_environment_count:
                raise Exception(
                    "The robot thinks you don't trust it. The robot self-destructed"
                )
            self.__get_environment_count += 1
        observe_range = self.__get_mood_level()

        ret_var = Variable(_BOOL_TYPE_ID_, False,
                           [observe_range * 2 + 1, observe_range * 2 + 1, 2])
        for i in range(observe_range * 2 + 1):
            for j in range(observe_range * 2 + 1):
                cell_symbol = maze.get().get(self.__x + j - observe_range,
                                             self.__y + i - observe_range)
                if cell_symbol == wall_symbol:
                    ret_var.get([j, i, 0]).get().trivial_assignment(
                        Value(_BOOL_TYPE_ID_, True))
                if cell_symbol == exit_symbol:
                    ret_var.get([j, i, 1]).get().trivial_assignment(
                        Value(_BOOL_TYPE_ID_, True))
                    self.__mood += self.__additional_see_exit_mood
                    if self.__mood > (self.__max_mood + self.__extra_mood):
                        raise Exception(
                            "The robot became paranoid. The robot self-destructed"
                        )
        return reference_wrapper(ret_var)
예제 #2
0
 def execute(self):
     try:
         function = self.__functions_map.get(self.__function_name, None)
         if function is not None:
             return reference_wrapper(function[1].get())
         else:
             raise Exception('>>> function not exist')
     except Exception as exception:
         raise Exception(str(exception) + ' --> ' + str(self.lineno()))
예제 #3
0
 def execute(self):
     try:
         if self.__function_stack[-1].get(self.__variable_name,
                                          None) is not None:
             raise Exception('>>> this var already exist')
         self.__function_stack[-1][
             self.__variable_name] = reference_wrapper(
                 copy.deepcopy(self.__expression.execute().get()))
     except Exception as exception:
         raise Exception(str(exception) + ' --> ' + str(self.lineno()))
예제 #4
0
 def execute(self):
     try:
         if self.__function_stack[-1].get(self.__variable_name,
                                          None) is not None:
             raise Exception('>>> this var already exist')
         self.__function_stack[-1][
             self.__variable_name] = reference_wrapper(
                 Variable(self.__type_id, self.__init_value,
                          self.__dimensions.execute()))
     except Exception as exception:
         raise Exception(str(exception) + ' --> ' + str(self.lineno()))
예제 #5
0
 def execute(self):
     try:
         function = self.__functions_map.get(self.__function_name, None)
         if function is not None:
             result = function[0].call(self.__call_parameters)
             function[1] = reference_wrapper(result.get())
             return result
         else:
             raise Exception('>>> function not exist')
     except Exception as exception:
         raise Exception(str(exception) + ' --> ' + str(self.lineno()))
 def execute(self, program, debug=False, tests=False):
     functions_map, good = self.__parser.parse(program, debug, tests)
     if good is True:
         findexit = functions_map.get('FINDEXIT', None)
         if findexit is None:
             sys.stderr.write(f'Error: FINDEXIT function is not found')
         else:
             try:
                 findexit[1] = reference_wrapper(findexit[0].call([]).get())
                 if not tests:
                     if findexit[1].get()._Variable__objects[0].get()._Value__value == True:
                         print('exit was found')
                     else:
                         print("can't find exit")
             except Exception as exception:
                 sys.stderr.write(str(exception))
예제 #7
0
 def execute(self):
     return reference_wrapper(Variable(self.__type_id, self.__value, [1]))
예제 #8
0
                    print('@', end="")
                else:
                    print(symbol, end="")
                j += 1
            print()
            i += 1
        print(Robot.Robot.robot.get().get_dir())
        return ""

    def tkprint(self, canvas: Canvas):
        for i in range(len(self.__maze)):
            for j in range(len(self.__maze[i])):
                if self.__maze[i][j] == wall_symbol:
                    canvas.create_rectangle(i, j, 1, 1, fill='red')


maze = reference_wrapper(None)

if __name__ == '__main__':
    map_file = open('Maze.txt')
    maze.set(Map(map_file.read()))
    print(maze.get())
    # window = Tk()
    # window.title("Findexit")
    # window.geometry('1600x900')
    # canvas = Canvas(window, width=600, height=600)
    # canvas.pack()
    # maze.tkprint(canvas)
    # window.update()
    # window.mainloop()
예제 #9
0
    def give_mood_points(self, points):
        if self.__mood_flag:
            self.__mood += points
            if self.__mood > (self.__max_mood + self.__extra_mood):
                raise Exception(
                    "The robot became paranoid. The robot self-destructed")
            if self.__mood < self.__min_mood:
                raise Exception(
                    "The robot was offended. The robot self-destructed")
        return self

    @staticmethod
    def symbol():
        return '@'

    def position(self):
        return self.__x, self.__y

    def get_dir(self):
        if self.__direction == 0:
            return "left"
        if self.__direction == 1:
            return "up"
        if self.__direction == 2:
            return "right"
        if self.__direction == 3:
            return "down"


robot = reference_wrapper(None)