def get_s(name): sight = fc.get_car_sight(name) ti = fc.get_ti(name) mid = ti['mid'] while len(mid) < 5: mid.append(mid[len(mid) - 1]) mid = np.array([mid[i * (len(mid) - 1) // 5] for i in range(5)]) mid = mid - np.array([len(fc.get_car_sight(name)[0]) / 2, 0]) s = np.reshape(mid, 10) # right = ti['right'] # left = ti['left'] # if len(left) == 0: # left.append([0,0]) # if len(right) == 0: # right.append([wight-1,hight-1]) # while len(right)<5: # right.append(right[len(right)-1]) # while len(left)<5: # left.append(left[len(left)-1]) # right = np.array([right[i*(len(right)-1)//5] for i in range(5)]) # left = np.array([left[i*(len(left)-1)//5] for i in range(5)]) # s = np.concatenate([np.reshape(right,10), np.reshape(left,10)], 0) return s
def get_r(name): r, ti = 0, fc.get_ti(name) mid = ti['mid'] sight = fc.get_car_sight(name) if sight[mid[0][1]][mid[0][0]] < 0.5: r = -1000 else: r = -np.square(mid[0][0] - len(fc.get_car_sight(name)[0]) / 2) #r -= np.square((100-fc.get_velocity(name))/50) return r
def get_r(name): sight = fc.get_car_sight(name) wight = len(sight[0]) hight = len(sight) r, ti = 0, fc.get_ti(name) mid = ti['mid'] if sight[mid[0][1]][mid[0][0]] < 0.5: r = -35 else: r = -np.abs(mid[0][0] - wight / 2) return r
def get_s(name): sight = fc.get_car_sight(name) wight = len(sight[0]) hight = len(sight) ti = fc.get_ti(name) mid = ti['mid'] while len(mid) < 5: mid.append(mid[len(mid) - 1]) mid = np.array([mid[i * (len(mid) - 1) // 6] for i in range(5)]) mid = mid - np.array([wight / 2, 0]) mid = np.array([0, hight]) - mid s = np.reshape(mid, 10) s = np.concatenate([s, np.array([fc.get_velocity(name)])], 0) return s
mid = ti['mid'] if sight[mid[0][1]][mid[0][0]] < 0.5: r = -35 else: r = -np.abs(mid[0][0] - wight / 2) return r FRAME_SPACING = 20 fc.game_init('FCMAP0.PNG') fc.add_car('0', (90, 255)) fc.set_car('0', (90, 255), np.pi / 2, 0) #fc.show_car_sight('0') wight = len(fc.get_car_sight('0')[0]) fc.set_time_speed(0) ddpg = MDDPG.DDPG(11, 2, 2, np.array([np.pi / 3, 256])) var = np.array([np.pi / 3, 100]) times = 1 fc.start() while times: start_time = fc.get_time() normal_working = 0 s, a, r, s_ = [], [], [], [] if times % 10 == 1: var += np.array([np.pi / 3, 100]) / 5
value_model = tfl.regression(value, placeholder=y, optimizer='adam', loss=value_loss, trainable_vars=value_vars, batch_size=64, name='target_value', op_name='value_model') model = tfl.DNN(tf.concat([ctrl, value], 1)) fc.game_init("FCMAP0.PNG") fc.add_car("0", (430, 240)) fc.set_car("0", (430, 240), np.pi / 2, 0) fc.show_car_sight("0") wight = len(fc.get_car_sight("0")[0]) train_sight = [] train_degree = [] train_velocity = [] train_y = [] degree = 0 velocity = 100 times = 1 fc.set_time_speed(1) fc.start() reset_time = fc.get_time() while times:
placeholder=None, optimizer='adam', loss=ctrl_loss, trainable_vars=ctrl_vars, batch_size=512, name='target_ctrl', op_name='ctrl_reg') #model_value_example=tfl.DNN(value_example) model_ctrl = tfl.DNN(tf.concat([ctrl, value], 1)) fc.game_init("FCMAP0.PNG") fc.add_car("0", (430, 240)) fc.set_car("0", (435, 240), np.pi / 2, 0) fc.show_car_sight("0") wight = len(fc.get_car_sight("0")[0]) hight = len(fc.get_car_sight("0")) train_left = [] train_right = [] train_state = [] train_example_ctrl = [] train_y = [] degree = 0 velocity = 100 times = 0 fc.set_time_speed(1) fc.start() reset_time = fc.get_time()