コード例 #1
0
    def get_neighbor_set_cones(self, row, col, agent, agent_field):
        number_of_standing = 0
        counter = 0
        if col == 0:
            number_of_standing += agent_field[row][col + 1].behavior
            counter += 1
        elif col == self.n_of_column - 1:
            number_of_standing += agent_field[row][col - 2].behavior
            counter += 1
        else:
            number_of_standing += agent_field[row][col - 1].behavior
            number_of_standing += agent_field[row][col + 1].behavior
            counter += 2

        if row != 0:
            i = 1
            while i < row:
                j = col - i
                while j <= col + i:
                    if j >= 0 and j < self.n_of_column:
                        number_of_standing += agent_field[row - i][j].behavior
                        counter += 1
                    j += 1
                i += 1
        agent.make_decision(counter, number_of_standing)
コード例 #2
0
 def get_neighbor_set_neumann(self, row, col, agent, agent_field):
     number_of_standing = 0
     number_of_standing += agent_field[row][(col + 1) %
                                            self.n_of_column].behavior
     number_of_standing += agent_field[row][(col - 1 + self.n_of_column) %
                                            self.n_of_column].behavior
     number_of_standing += agent_field[(row + 1) %
                                       self.n_of_row][col].behavior
     number_of_standing += agent_field[(row - 1 + self.n_of_row) %
                                       self.n_of_row][col].behavior
     agent.make_decision(4, number_of_standing)
コード例 #3
0
ファイル: profile.py プロジェクト: ftao/fnake
def test(filename):
    with open(filename, "r") as f:
        data = pickle.load(f)
        start = time.time()
        seq = None
        for i, snake in enumerate(data["info"]["snakes"]):
            if snake["name"] == data["name"]:
                seq = i
                #                snake['body'] = snake['body'][1:]
                #                snake['length'] -=1
                #                print snake['body']
                break
        #            else:
        #                snake['body'] = snake['body'][:1]
        # fake
        #        data['info']['eggs'].append((16,4))
        #        pprint.pprint(data['info']['snakes'])
        print data["info"]["snakes"][seq]["body"]
        d = make_decision(data["map"], data["info"], seq)
        print "d is ", d
        print "cost", time.time() - start
コード例 #4
0
def test(filename):
    with open(filename, 'r') as f :
        data = pickle.load(f)
        start = time.time()
        seq = None
        for i, snake in enumerate(data['info']['snakes']):
            if snake['name'] == data['name']:
                seq = i
#                snake['body'] = snake['body'][1:]
#                snake['length'] -=1
#                print snake['body']
                break
#            else:
#                snake['body'] = snake['body'][:1]
        #fake 
#        data['info']['eggs'].append((16,4))
#        pprint.pprint(data['info']['snakes'])
        print data['info']['snakes'][seq]['body']
        d = make_decision(data['map'], data['info'], seq)
        print 'd is ', d
        print 'cost', time.time() - start
コード例 #5
0
 def get_neighbor_set_standing_ovation(self, row, col, agent, agent_field):
     number_of_standing = 0
     if row != 0:
         if col == 0:
             number_of_standing += agent_field[row - 1][col].behavior
             number_of_standing += agent_field[row][col + 1].behavior
             number_of_standing += agent_field[row - 1][col + 1].behavior
             agent.make_decision(3, number_of_standing)
             return True
         elif col == self.n_of_column - 1:
             number_of_standing += agent_field[row - 1][col].behavior
             number_of_standing += agent_field[row][col - 1].behavior
             number_of_standing += agent_field[row - 1][col - 1].behavior
             agent.make_decision(3, number_of_standing)
             return True
         else:
             number_of_standing += agent_field[row - 1][col - 1].behavior
             number_of_standing += agent_field[row - 1][col].behavior
             number_of_standing += agent_field[row - 1][col + 1].behavior
             number_of_standing += agent_field[row][col - 1].behavior
             number_of_standing += agent_field[row][col + 1].behavior
             agent.make_decision(5, number_of_standing)
             return True
     else:
         if col == 0:
             number_of_standing += agent_field[row][col + 1].behavior
             agent.make_decision(1, number_of_standing)
             return True
         elif col == self.n_of_column - 1:
             number_of_standing += agent_field[row][col - 1].behavior
             agent.make_decision(1, number_of_standing)
             return True
         else:
             number_of_standing += agent_field[row][col - 1].behavior
             number_of_standing += agent_field[row][col + 1].behavior
             agent.make_decision(2, number_of_standing)
             return True
コード例 #6
0
 def get_neighbor_set_standing_ovation(self, row, col, agent, agent_field):
     number_of_standing = 0
     if row != 0:
         if col == 0:  # agentが左端の列にいるとき
             number_of_standing += agent_field[row - 1][col].behavior
             number_of_standing += agent_field[row][col + 1].behavior
             number_of_standing += agent_field[row - 1][col + 1].behavior
             agent.make_decision(3, number_of_standing)
             return True
         elif col == self.n_of_column - 1:  # agentが右端の列にいるとき
             number_of_standing += agent_field[row - 1][col].behavior
             number_of_standing += agent_field[row][col - 1].behavior
             number_of_standing += agent_field[row - 1][col - 1].behavior
             agent.make_decision(3, number_of_standing)
             return True
         else:  # 左右、前に他のagentがいるとき
             number_of_standing += agent_field[row - 1][col - 1].behavior
             number_of_standing += agent_field[row - 1][col].behavior
             number_of_standing += agent_field[row - 1][col + 1].behavior
             number_of_standing += agent_field[row][col - 1].behavior
             number_of_standing += agent_field[row][col + 1].behavior
             agent.make_decision(5, number_of_standing)
             return True
     else:
         if col == 0:  # agentが左角にいるとき(row,col)=(0,0)
             number_of_standing += agent_field[row][col + 1].behavior
             agent.make_decision(1, number_of_standing)
             return True
         elif col == self.n_of_column - 1:  # agentが右角にいるとき
             number_of_standing += agent_field[row][col - 1].behavior
             agent.make_decision(1, number_of_standing)
             return True
         else:  # agentが両端以外の最前列にいるとき
             number_of_standing += agent_field[row][col - 1].behavior
             number_of_standing += agent_field[row][col + 1].behavior
             agent.make_decision(2, number_of_standing)
             return True