Пример #1
0
 def get(self):
     message = Message()
     setattr(message, 'link', request.url)
     try:
         setattr(message, 'message', "Success")
         galeryDao = GaleryDao()
         result = None
         if 'id_album' in request.args:
             id_album = int(request.args['id_album'])
             logger.info(id_album)
             result = galeryDao.GetGaleryByAlbum(id_album)
         else:
             result = galeryDao.GetAllGaleries()
         logger.info(result)
         if result is None:
             setattr(message, 'code', 404)
             setattr(message, 'developerMessage', "Data is empty")
             setattr(message, 'data', None)
         else:
             setattr(message, 'code', 200)
             setattr(message, 'developerMessage', None)
             setattr(message, 'data', result)
         logger.info(message.GetResponse())
     except Exception as e:
         logger.error(e)
         setattr(message, 'code', 500)
         setattr(message, 'message', "Fail")
         setattr(message, 'developerMessage', str(e))
         setattr(message, 'data', None)
     res = message.GetResponse()
     return jsonify(res)
Пример #2
0
 def get(self):
     message = Message()
     setattr(message, 'link', request.url)
     try:
         setattr(message, 'message', "Success")
         agendaDao = AgendaDao()
         result = None
         if 'id_agenda' in request.args:
             id_agenda = int(request.args['id_agenda'])
             logger.info(id_agenda)
             result = agendaDao.GetAgendaById(id_agenda)
         elif 'limit' in request.args:
             limit = int(request.args['limit'])
             logger.info(limit)
             result = agendaDao.GetAgendaLimit(limit)
         else:          
             result = agendaDao.GetAllAgenda()
         logger.info(result)
         if result is None:
             setattr(message,'code',404)           
             setattr(message, 'developerMessage', "Data is empty")
             setattr(message, 'data', None)
         else:            
             setattr(message,'code',200)
             setattr(message, 'developerMessage', None)
             setattr(message, 'data', result)
         logger.info(message.GetResponse())
     except Exception as e:
         logger.error(e)
         setattr(message,'code',500)
         setattr(message, 'message', "Fail")
         setattr(message, 'developerMessage', str(e))
         setattr(message, 'data', None)
     res = message.GetResponse()
     return jsonify(res)
Пример #3
0
 def __init__(self):
     self.ticker = Ticker()
     self.states = States(self.ticker)
     self.message = Message()
     self.map = Map()
     self.you = Player()
     self.enemy = Player()
Пример #4
0
 def get(self):
     message = Message()
     setattr(message, 'link', request.url)
     try:
         setattr(message, 'message', "Success")
         artikelDao = ArtikelDao()
         result = None
         if 'id_artikel' in request.args:
             id_artikel = int(request.args['id_artikel'])
             logger.info(id_artikel)
             result = artikelDao.GetArtikelById(id_artikel)
         else:
             result = artikelDao.GetAllArtikel()
         logger.info(result)
         if result is None:
             setattr(message, 'code', 404)
             setattr(message, 'developerMessage', "Data is empty")
             setattr(message, 'data', None)
         else:
             setattr(message, 'code', 200)
             setattr(message, 'developerMessage', None)
             setattr(message, 'data', result)
         logger.info(message.GetResponse())
     except Exception as e:
         logger.error(e)
         setattr(message, 'code', 500)
         setattr(message, 'message', "Fail")
         setattr(message, 'developerMessage', str(e))
         setattr(message, 'data', None)
     res = message.GetResponse()
     return jsonify(res)
Пример #5
0
 def __init__(self):
     self.ticker = Ticker()
     self.states = States(self.ticker)
     self.message = Message()
     self.map = Map()
     self.you = Player()
     self.enemy = Player()
     self.history = MoveHistory(length=50, history=[])
Пример #6
0
 def __init__(self):
     self.values = Values()
     self.ticker = Ticker()
     self.states = States(self.ticker)
     self.message = Message()
     self.map = Map()
     self.map.register_cost_and_heuristic(self.astar_move_cost,
                                          self.astar_heuristic)
     self.you = Player()
     self.enemy = Player()
Пример #7
0
class AI(object):
    def __init__(self):
        self.ticker = Ticker()
        self.states = States(self.ticker)
        self.message = Message()
        self.map = Map()
        self.you = Player()
        self.enemy = Player()

    def setup(self,info):
        self.message.parse_message(info)
        self.map = self.message.map
        self.map.load_json_map()
        self.you = self.message.you

    def reset_for_next_round(self):
        self.you = Player()
        self.enemy = Player()
        self.map.reset_map()
        self.ticker.reset()

    def update(self, info):
        self.ticker.tick()
        self.message.parse_message(info)
        self.you = self.message.you
        self.possible_moves = self.map.get_neighbours_of(self.you.pos)
        self.enemy = self.message.enemy
        self.__update_danger()
        self.map.update_content(self.message,[self.you.pos,self.enemy.pos])

    def __update_danger(self):
        if self.you.pos in self.map.super_pellets_positions:
            self.ticker.start_you_are_dangerous_ticker()
        if self.enemy.pos in self.map.super_pellets_positions:
            self.ticker.start_other_is_dangerous_ticker()

    def move(self):
        move = _get_move(self,self.map)
        self.map.prev_move.append(move)
        if move < 0:
            print("error") #TODO print all the stuff
        return move
Пример #8
0
 def get(self):
     message = Message()
     setattr(message, 'link', request.url)
     try:
         setattr(message, 'message', "Success")
         beritaDao = BeritaDao()
         result = None
         if 'id_berita' in request.args:
             id_berita = int(request.args['id_berita'])
             logger.info(id_berita)
             result = beritaDao.GetBeritaById(id_berita)
             logger.info(result)
         elif 'id_kategori' in request.args:
             id_kategori = int(request.args['id_kategori'])
             logger.info(id_kategori)
             result = beritaDao.GetBeritaByKategori(id_kategori)
         elif 'limit' in request.args:
             limit = int(request.args['limit'])
             logger.info(limit)
             result = beritaDao.GetBeritaLimit(limit)
         else:
             result = beritaDao.GetAllBerita()
         if result is None:
             setattr(message, 'code', 404)
             setattr(message, 'developerMessage', "Data not found")
             setattr(message, 'data', None)
         else:
             setattr(message, 'code', 200)
             setattr(message, 'developerMessage', None)
             setattr(message, 'data', result)
         logger.info(message.GetResponse())
     except Exception as e:
         logger.error(e)
         setattr(message, 'code', 500)
         setattr(message, 'message', "Fail")
         setattr(message, 'developerMessage', str(e))
         setattr(message, 'data', None)
     res = message.GetResponse()
     return jsonify(res)
Пример #9
0
 def get(self):
     message = Message()
     setattr(message, 'link', request.url)
     try:
         setattr(message, 'message', "Success")
         pageDao = PageDao()
         result = pageDao.GetAllPages()
         if result is None:
             setattr(message, 'code', 404)
             setattr(message, 'developerMessage', "Data is empty")
             setattr(message, 'data', None)
         else:
             setattr(message, 'code', 200)
             setattr(message, 'developerMessage', None)
             setattr(message, 'data', result)
         logger.info(message.GetResponse())
     except Exception as e:
         logger.error(e)
         setattr(message, 'code', 500)
         setattr(message, 'message', "Fail")
         setattr(message, 'developerMessage', str(e))
         setattr(message, 'data', None)
     res = message.GetResponse()
     return jsonify(res)
Пример #10
0
 def get(self):
     message = Message()
     setattr(message, 'link', request.url)
     try:
         setattr(message, 'message', "Success")
         beritaDao = BeritaDao()
         result = beritaDao.GetBeritaPopular()
         if result is None:
             setattr(message, 'code', 404)
             setattr(message, 'developerMessage', "Data not found")
             setattr(message, 'data', None)
         else:
             setattr(message, 'code', 200)
             setattr(message, 'developerMessage', None)
             setattr(message, 'data', result)
         logger.info(message.GetResponse())
     except Exception as e:
         logger.error(e)
         setattr(message, 'code', 500)
         setattr(message, 'message', "Fail")
         setattr(message, 'developerMessage', str(e))
         setattr(message, 'data', None)
     res = message.GetResponse()
     return jsonify(res)
Пример #11
0
class AI(object):
    def __init__(self):
        self.values = Values()
        self.ticker = Ticker()
        self.states = States(self.ticker)
        self.message = Message()
        self.map = Map()
        self.map.register_cost_and_heuristic(self.astar_move_cost,
                                             self.astar_heuristic)
        self.you = Player()
        self.enemy = Player()

    def setup(self, info):
        self.message.parse_message(info)
        self.map = self.message.map
        self.map.load_json_map()
        self.player = self.message.you

    def reset_for_next_round(self):
        self.you = Player()
        self.enemy = Player()
        self.map.reset_map()
        self.ticker.reset()

    def update(self, info):
        self.ticker.tick()
        self.message.parse_message(info)
        self.player = self.message.you
        self.possible_moves = self.map.get_neighbours_of(self.player.pos)
        self.enemy = self.message.enemy
        self.__update_danger()
        new_poses = [self.player.pos, self.enemy.pos]
        self.map.update_content(self.message, new_poses)

    def __update_danger(self):
        if self.player.pos in self.map.super_pellets_positions:
            self.ticker.start_you_are_dangerous_ticker()
        if self.enemy.pos in self.map.super_pellets_positions:
            self.ticker.start_other_is_dangerous_ticker()

    def get_move(self):  # AI LOGIC GOES HERE!
        if self.states.is_status_quo():
            print("Mmmm, shiny!")
            path = self.map.get_bf_path(self.player.pos,
                                        char_goal=self.map.icon.pellet)
            first_move_pos = path[1]
            move = self.map.get_move_from(self.player.pos, first_move_pos)
            return move
        elif self.states.you_are_dangerous():
            if self.map.get_euclidean_dist(
                    self.player.pos,
                    self.enemy.pos) <= self.values.enemy_distance_trigger:
                print("Ima getcha!")
                path = self.map.get_bf_path(self.player.pos,
                                            pos_goal=self.enemy.pos)
                first_move_pos = path[1]
                move = self.map.get_move_from(self.player.pos, first_move_pos)
                return move
            else:
                print("Pft, cba chasing that guy")
                path = self.map.get_bf_path(self.player.pos,
                                            char_goal=self.map.icon.pellet)
                first_move_pos = path[1]
                move = self.map.get_move_from(self.player.pos, first_move_pos)
            return move
        elif self.states.enemy_is_dangerous():
            if self.map.get_manhattan_dist(
                    self.player.pos,
                    self.enemy.pos) <= self.values.enemy_distance_trigger:
                print("HAPL!")
                return self.send_random_move()
            else:
                print("Ima do me")
                path = self.map.get_bf_path(self.player.pos,
                                            char_goal=self.map.icon.pellet)
                first_move_pos = path[1]
                return self.map.get_move_from(self.player.pos, first_move_pos)

        return -1  #haha, you messed up!  :P

    def send_random_move(self):
        return self.map.get_move_from(
            self.player.pos, np.random.choice(list(self.possible_moves)))

    def astar_heuristic(self, start, goal):
        return self.map.get_euclidean_dist(start, goal)

    def astar_move_cost(self, pos1, pos2):
        return 10.0
Пример #12
0
class AI(object):
    def __init__(self):
        self.ticker = Ticker()
        self.states = States(self.ticker)
        self.message = Message()
        self.map = Map()
        self.you = Player()
        self.enemy = Player()
        self.history = MoveHistory(length=50, history=[])

    def setup(self, info):
        self.message.parse_message(info)
        self.map = self.message.map
        self.map.load_json_map()
        self.you = self.message.you

    def reset_for_next_round(self):
        self.you = Player()
        self.enemy = Player()
        self.map.reset_map()
        self.ticker.reset()

    def update(self, info):
        self.ticker.tick()
        self.message.parse_message(info)
        self.you = self.message.you
        self.possible_moves = self.map.get_neighbours_of(self.you.pos)
        self.enemy = self.message.enemy
        self.__update_danger()
        self.map.update_content(self.message, [self.you.pos, self.enemy.pos])

    def __update_danger(self):
        if self.you.pos in self.map.super_pellets_positions:
            self.ticker.start_you_are_dangerous_ticker()
        if self.enemy.pos in self.map.super_pellets_positions:
            self.ticker.start_other_is_dangerous_ticker()

    def move(self):
        move = self.__get_the_move(self.map)
        return move

    def __get_the_move(self, map):
        avail_pellet_moves = []
        avail_new_moves = []
        avail_old_moves = []

        for possible_move in self.possible_moves:

            # Just do this move if it's a super pellet
            if possible_move in map.super_pellets_positions:
                return map.get_move_between(self.you.pos, possible_move)

            # Record possible pellet move
            elif possible_move in map.pellet_positions:
                avail_pellet_moves.append(possible_move)

            # Track old moves
            if self.history.contains(possible_move):
                avail_old_moves.append(possible_move)
            else:
                avail_new_moves.append(possible_move)

        if len(avail_pellet_moves) > 0: move = r.choice(avail_pellet_moves)
        else:
            move = r.choice(avail_new_moves) if len(
                avail_new_moves) > 0 else r.choice(avail_old_moves)

        # Chase super pellets
        for supahpelletz in map.super_pellets_positions:
            moves_to_supapellet = map.get_breadth_first_path(
                self.you.pos, supahpelletz)
            if (len(moves_to_supapellet) < 10):
                move = moves_to_supapellet[0]
                print("Chasing a super pellet!")
                break

        # Chase enemy if dangerous
        if (self.you.is_dangerous and not self.enemy.is_dangerous):
            move = map.get_breadth_first_path(self.you.pos, self.enemy.pos)[0]
            print("I'm dangerous!")

        self.history.add(move)

        return map.get_move_between(self.you.pos, move)