示例#1
0
def car_reward(F, player):
    """
    seeker's reward function
    :param F: Node with status of all players
    :param player: player number
    :return:
    """
    # print 'Player'
    # print player
    player_nr = int(player[3:])
    # print 'Player Number'
    # print player_nr
    # reward = 0
    # F = None

    position_player = F[player_nr]
    reward = position_player[1] * position_player[1]
    reward *= 4
    # if position_player[0] == west:
    #     reward = -position_player[1]
    #     if position_player[1] > int(north - blocked_north):
    #         reward -= 150

    f_not_player = None
    for f_b in range(len(F)):
        #  print f_b
        if not f_b == player_nr:
            if f_not_player is None:
                f_not_player = F[f_b]
            else:
                f_not_player = np.vstack((f_not_player, F[f_b]))
    # print position_player
    # print np.array([east, north])
    if np.array_equal(position_player, np.array([east, north])) is False:
        if check_collision(position_player, f_not_player):
            # print 'Collision'
            reward -= 150

    #  sys.stdout.write('\n')
    #  sys.stdout.write(' p: ' + str(player_nr) + ' pos : ' + str(position_player[0]) +
    #                   ' - ' + str(position_player[1]) + ' r: ' + str(reward))
    #  sys.stdout.write('\n')
    return reward
示例#2
0
def car_reward(F, player):
    """
    seeker's reward function
    :param F: Node with status of all players
    :param player: player number
    :return:
    """
    # print 'Player'
    # print player
    player_nr = int(player[3:])
    # print 'Player Number'
    # print player_nr
    # reward = 0
    # F = None

    position_player = F[player_nr]
    reward = position_player[1] * position_player[1]
    if position_player[0] == 0:
        reward -= position_player[1]
        if position_player[1] > 2:
            reward -= 150

    f_not_player = None
    for f_b in range(len(F)):
        if not f_b == player_nr:
            if f_not_player is None:
                f_not_player = F[f_b]
            else:
                f_not_player = np.vstack((f_not_player, F[f_b]))
    if check_collision(position_player, f_not_player):
        # print ' - Collision '
        reward -= 20

    # sys.stdout.write('\r')
    # sys.stdout.write(' p: ' + str(player_nr) + ' pos : ' + str(position_player[0]) +
    #                  ' - ' + str(position_player[1]) + ' r: ' + str(reward))
    return reward
示例#3
0
                state_space.append(state)

# print 'state space: \n ' + str(state_space)

# starting locations

# Ego-vehicle starts at [0, 0]
starting_poses = np.array([west, south])
pose_ind = 1
while pose_ind < nr_vehicles:
    new_pose = np.array([0, 0])
    new_pose[0] = np.random.randint(east + 1, size=1)
    new_pose[1] = np.random.randint(south + 3, size=1)
    print 'new_pose' + str(new_pose)

    if not check_collision(new_pose, starting_poses):
        starting_poses = np.vstack((starting_poses, new_pose))  # axis=0))
        pose_ind += 1
    # print 'Pose index : ' + str(pose_ind)

# starting locations
print 'starting_poses : '
print starting_poses

# observational noise CPT (left, right, stay)
# obsnoiseCPT = np.array([prob_left, prob_right, prob_remain, prob_brake])


def adjust_loc(location):
    """"
     function that adjusts for moves off the grid