Ejemplo n.º 1
0
def feature_RES_tensor_map(csv_roomrecord_groupby, csv_object, LOS, *map_args):
    for (Filename), group in csv_roomrecord_groupby:
        print(Filename)
        game_state = GameState(Filename, csv_object)
        bops, bops_last_pos = game_state.bops, game_state.bops_last_pos
        stage_groupby = group.groupby(["StageID"])
        states_tensor_red = []
        states_tensor_blue = []
        bops_odd = []
        bops_even = []
        soldier_red = [bops["red_soldier1"]["Pos"]]
        soldier_blue = [bops["blue_soldier1"]["Pos"]]
        for (stageid), group in stage_groupby:
            group1 = group.sort_values(by=["TimeID", "ObjStep"],
                                       axis=0,
                                       ascending=[False, False])

            game_state.initCancelKeep()
            bops["stage"] = stageid
            bops["red_win"] = group.iloc[0]["JmResult"]

            bops_one_stage = []

            for indexs, row in group1.iterrows():
                bop_name = game_state.Get_bop_name(row.ObjID)
                if row.ObjNewPos == row.ObjPos:
                    if row.ObjInto != 0:
                        game_state.UpdateOn(row, bop_name)
                    if row.ObjOut != 0:
                        game_state.UpdateOut(row, bop_name)

                    if row.AttackID != 0:
                        game_state.Attack(row, bop_name)
                    if row.CityTake != 0:
                        game_state.Occupy(row)
                    if row.ObjHide != 0:
                        game_state.Hide(row, bop_name)
                    if row.ObjPass == 1:
                        game_state.Pass(row, bop_name)
                    if row.ObjKeepCancel != 0:
                        game_state.KeepCancel(row, bop_name)
                else:
                    game_state.Move(row, bop_name)
                    soldier_red.append(bops["red_soldier1"]["Pos"])
                    soldier_blue.append(bops["blue_soldier1"]["Pos"])
        dirs = '../data/test/'
        if not os.path.isdir(dirs):
            os.makedirs(dirs)
        plot_position(soldier_red, soldier_blue, dirs, Filename)
Ejemplo n.º 2
0
def feature_RES_tensor(csv_roomrecord_groupby, csv_object, LOS):
    for (Filename), group in csv_roomrecord_groupby:
        print(Filename)
        game_state = GameState(Filename, csv_object)
        bops, bops_last_pos = game_state.bops, game_state.bops_last_pos
        stage_groupby = group.groupby(["StageID"])
        states_tensor_red = []
        states_tensor_blue = []
        bops_odd = []
        bops_even = []
        for (stageid), group in stage_groupby:
            group1 = group.sort_values(by=["TimeID", "ObjStep"],
                                       axis=0,
                                       ascending=[False, False])

            game_state.initCancelKeep()
            bops["stage"] = stageid
            bops["red_win"] = group.iloc[0]["JmResult"]

            bops_one_stage = []
            for indexs, row in group1.iterrows():
                bop_name = game_state.Get_bop_name(row.ObjID)
                if row.ObjNewPos == row.ObjPos:
                    if row.ObjInto != 0:
                        game_state.UpdateOn(row, bop_name)
                    if row.ObjOut != 0:
                        game_state.UpdateOut(row, bop_name)

                    if row.AttackID != 0:
                        game_state.Attack(row, bop_name)
                    if row.CityTake != 0:
                        game_state.Occupy(row)
                    if row.ObjHide != 0:
                        game_state.Hide(row, bop_name)
                    if row.ObjPass == 1:
                        game_state.Pass(row, bop_name)
                    if row.ObjKeepCancel != 0:
                        game_state.KeepCancel(row, bop_name)
                else:
                    game_state.Move(row, bop_name)
                bops_one_stage.append(copy.deepcopy(bops))

            if stageid % 2 == 1:  # 奇数阶段,采集红方预测蓝方棋子信息
                bops_odd = bops_one_stage
                flag, tensor_one_stage_red, = StateFeature_two_stage(
                    bops_odd, bops_even, bops_last_pos, LOS, 1)
                if flag:
                    states_tensor_red.append(tensor_one_stage_red)
            else:  # 偶数阶段,采集蓝方预测红方棋子信息
                bops_even = bops_one_stage
                flag, tensor_one_stage_blue, = StateFeature_two_stage(
                    bops_odd, bops_even, bops_last_pos, LOS, 0)
                if flag:
                    states_tensor_blue.append(tensor_one_stage_blue)

        spatial_states_np_red = np.concatenate(states_tensor_red)
        spatial_states_np_blue = np.concatenate(states_tensor_blue)
        spatial_states_np_red = spatial_states_np_red.reshape(
            [spatial_states_np_red.shape[0], -1])
        spatial_states_np_blue = spatial_states_np_blue.reshape(
            [spatial_states_np_blue.shape[0], -1])
        print(spatial_states_np_blue.shape)
        print(spatial_states_np_red.shape, "--------")
        vs1 = 'red2blue'
        vs2 = 'blue2red'

        path = os.path.join('../data/feature_data/feature_RES_tensor/')
        if not os.path.isdir(path):
            os.makedirs(path)
        sparse.save_npz(os.path.join(path, Filename + vs1 + '@S'),
                        sparse.csc_matrix(spatial_states_np_red))

        sparse.save_npz(os.path.join(path, Filename + vs2 + '@S'),
                        sparse.csc_matrix(spatial_states_np_blue))