Esempio n. 1
0
    def countAllZhuShu(self, codes, wtype):
        wtype = int(wtype)
        #任选
        if wtype in [249,250,251,252,253,254,255]:
            nneeds = wtype - 247
            nchose = len(codes.split(','))
            if nneeds > nchose:
                return 0
            return Math.C(nchose,nneeds)

        #直选
        # if wtype == 244:
        #     return len(codes.split(','))
        if wtype in [244,245,246]:
            chose = codes.split('|')
            chose[0] = chose[0].split(',') if chose[0]!='-' else ['-1']
            chose[1] = chose[1].split(',') if chose[1]!='-' else ['-1']
            chose[2] = chose[2].split(',') if chose[2]!='-' else ['-1']
            zhushu = 0
            for a in chose[0]:
                for b in chose[1]:
                    for c in chose[2]:
                        if a==b and a!='-1':continue
                        if b==c and b!='-1':continue
                        if c==a and c!='-1':continue
                        zhushu+= 1
            return zhushu

        #组选
        if wtype in [247,248]:
            nneeds = wtype - 245
            nchose = len(codes.split(','))
            if nneeds > nchose:
                return 0
            return Math.C(nchose,nneeds)
Esempio n. 2
0
def procDantuo(openCode, info):
    # 胆拖玩法
    beishu = info['f_beishu']
    zhushu = 0
    bonus = newBonus()
    cdata = ''
    global _DT_RE_
    for i in info['f_fileorcode'].split('$'):
        m = _DT_RE_.match(i)
        if not m:
            continue
        dan1 = m.group(1).split(',')
        tuo1 = m.group(2).split(',')
        dan2 = m.group(3).split(',')
        tuo2 = m.group(4).split(',')
        if dan1[0] == '':
            del dan1[0]
        if dan2[0] == '':
            del dan2[0]
        for i in Math.combination(tuo1, 5 - len(dan1)):
            reds = dan1 + i
            reds.sort()
            for j in Math.combination(tuo2, 2 - len(dan2)):
                blues = dan2 + j
                blues.sort()
                bs = calBonus(openCode, {'reds': reds, 'blues': blues})
                zhushu += beishu
                if bs[0]:
                    bonus[bs[0]] += beishu
                    bonus['zmax'] = 1

    money = zhushu * 2
    if info['f_wtype'] == 143:
        money = zhushu * 3
    ret = {
        'zhushu': zhushu,
        'money': money,
        'wtype': info['f_wtype'],
        'tid': info['f_tid'],
        'srccode': info['f_fileorcode'],
        'onenum': bonus['onenum'],
        'twonum': bonus['twonum'],
        'threenum': bonus['threenum'],
        'fournum': bonus['fournum'],
        'fivenum': bonus['fivenum'],
        'sixnum': bonus['sixnum'],
        'zmax': bonus['zmax']
    }

    return ret
Esempio n. 3
0
    def PlayNum_CM(self, tmp_info, cc_dict, wtype, beishu, ggtype):
        playnum = int(tmp_info['PlayNum'])
        cc_list = cc_dict.keys()
        ret_list = list()
        tmp_code = list()
        finally_list = list()

        ret_m = Math.combination(cc_list, playnum)

        for info in ret_m:
            ret_code = list()
            tmp_list = list()
            for i in info:
                tmp_list.append(cc_dict[i])

            self.orgaize_code(tmp_list, ret_code, tmp_code)

            ret_list += copy.deepcopy(ret_code)

        finally_list = ret_list
        """
        if 58 == int(ggtype):
            for info in ret_list:
                for i in info:
                    head = i.split('[')[0]
                    for j in (i.split('[')[-1].split(']')[0]).split(','):
                        finally_list.append([head + '[' + j + ']'])

        else:
            finally_list = ret_list
        """

        return finally_list
Esempio n. 4
0
    def splitRedBall(self, rArr):
        ret = list()
        r1 = rArr[0:16]
        r2 = rArr[16:]

        max = 5
        if len(r2) < 6:
            max = len(r2)

        for i in range(1, max + 1):
            tmp = list()
            # 不能同时调用两以上yield 蛋疼<<<<<碎了不
            for b in Math.combination(r2, i):
                tmp.append(b)

            for a in Math.combination(r1, 6 - i):
                for b in tmp:
                    yield a + b
    def get_velocity_accel_relative_to_car_and_their_scalar(engine):
        velocity_vector = engine.get_velocity()
        velocity_to_car_x, velocity_to_car_y = cMath.convert_point_into_relative_coordinate(
            target_xy=[velocity_vector.x, velocity_vector.y],
            original_xy=[0, 0],
            original_yaw_radius=math.radians(engine.vehicle_yaw))

        velocity = engine.get_velocity_scalar()

        accel_vector = engine.get_accel()
        accel_to_car_x, accel_to_car_y = cMath.convert_point_into_relative_coordinate(
            target_xy=[accel_vector.x, accel_vector.y],
            original_xy=[0, 0],
            original_yaw_radius=math.radians(engine.vehicle_yaw))

        accel = engine.get_velocity_scalar()

        return velocity, velocity_to_car_x, velocity_to_car_y, accel, accel_to_car_x, accel_to_car_y
Esempio n. 6
0
 def handTicket(self):
     #计算票奖金
     matchList = self.parseCodeRate(self._ticket['f_ticketid'],self._ticket['f_fileorcode'],self._ticket['f_ratelist'])
     ggTypeInfo = JcConfig.getGGType(self._ticket['f_ggtype'])
     for items in Math.combination(matchList,int(ggTypeInfo['PlayNum'])):    #几串几
         gg_arr = ggTypeInfo['SelCodeNum'].split(',')  #选择场次数
         for sel in gg_arr:   #几关
             for matchComb in Math.combination(items,int(sel)): #组合投注场次
                 comb_ret = self.handMatchComb(matchComb,self.tkt_cancels)
                 logger.debug(comb_ret)
                 if comb_ret['valid'] == False: #无效立即终止,提高效率
                     self.tkt_valid = False
                     return { 'tid':self._ticket['f_ticketid'],'orderid':self._ticket['f_orderid'],'valid':self.tkt_valid,
                              'getmoney':0,'pregetmoney':0,'returnmoney':0,'returnnum':0 }
                 if comb_ret['isreturn'] == True: #返款
                     self.tkt_returnprize += comb_ret['pre_prize']
                     self.tkt_returnnum += comb_ret['zhushu']
                 else:
                     self.tkt_preprize += comb_ret['pre_prize'] #税前奖金
                     self.tkt_prize  += comb_ret['prize'] #税后奖金
                 self.tkt_zhushu += comb_ret['zhushu'] 
     
     getmoney = 0
     pregetmoney = 0
     returnmoney = 0
     returnnum = 0
     if self.tkt_valid == True:
         beishu = Decimal(self._ticket['f_beishu'])
         pregetmoney = JcConfig.sixRound(self.tkt_preprize*beishu)
         getmoney = JcConfig.sixRound(self.tkt_prize*beishu)
         returnmoney = Decimal(self.tkt_returnprize)*beishu
         returnnum = self.tkt_returnnum*self._ticket['f_beishu']
         """
         #多关单式,无取消场次,中奖的,以出票返回的maxmoney为准
         if len(matchList)>1 and self.tkt_zhushu == 1 and len(self.tkt_cancels) == 0 and self.tkt_prize>0 and self._ticket['maxmoney']>0: 
             pregetmoney = JcConfig.sixRound(Decimal(self._ticket['maxmoney']))
             getmoney = pregetmoney
             if (pregetmoney/beishu) > 10000: #单倍大于10000要扣税
                 getmoney = JcConfig.sixRound(Decimal(pregetmoney*Decimal('0.8')))
         """
                
     return { 'tid':self._ticket['f_ticketid'],'orderid':self._ticket['f_orderid'],'valid':self.tkt_valid,
              'getmoney':getmoney,'pregetmoney':pregetmoney,'returnmoney':returnmoney,'returnnum':returnnum }
Esempio n. 7
0
def procBasic(openCode, info):
    # 普通玩法
    beishu = info['f_beishu']
    zhushu = 0
    bonus = newBonus()

    for code in info['f_fileorcode'].split('$'):
        reds, blues = code.split('|')
        reds = reds.strip().split(',')
        blues = blues.strip().split(',')
        if len(reds) > 5 or len(blues) > 2:
            for r in Math.combination(reds, 5):
                for b in Math.combination(blues, 2):
                    bs = calBonus(openCode, {'reds': r, 'blues': b})
                    zhushu += beishu
                    if bs[0]:
                        bonus[bs[0]] += beishu
                        bonus['zmax'] = 1
        else:
            bs = calBonus(openCode, {'reds': reds, 'blues': blues})
            zhushu += beishu
            if bs[0]:
                bonus[bs[0]] += beishu
                bonus['zmax'] = 1
    money = zhushu * 2
    if info['f_wtype'] == 98 or info['f_wtype'] == 388:
        money = zhushu * 3
    ret = {
        'zhushu': zhushu,
        'money': money,
        'wtype': info['f_wtype'],
        'tid': info['f_tid'],
        'srccode': info['f_fileorcode'],
        'onenum': bonus['onenum'],
        'twonum': bonus['twonum'],
        'threenum': bonus['threenum'],
        'fournum': bonus['fournum'],
        'fivenum': bonus['fivenum'],
        'sixnum': bonus['sixnum'],
        'zmax': bonus['zmax']
    }
    return ret
Esempio n. 8
0
    def handFushi(self, rArr, bArr, beishu):
        zhushu = 0

        # 红球注数
        r_zhushu = self.ArrInfo[len(rArr)][6]

        # 篮球注数
        b_zhushu = self.ArrInfo[len(bArr)][1]
        zhushu = r_zhushu * b_zhushu

        # 单票最大倍数
        max_beishu = self.TICK_RE['beishu']

        # 可拆分最大倍数
        lmt_beishu = max_beishu

        # 拆分结果
        ret = list()

        # 此处以钱为标杆
        if zhushu * self.singleMoney * max_beishu > self.limitMoney:
            lmt_beishu = self.limitMoney / (zhushu * self.singleMoney)

            # 需要拆蓝球
            if lmt_beishu == 0:
                tmpArr = Math.combination(bArr, 1)

                for info in tmpArr:
                    info_zhushu = self.ArrInfo[len(rArr)][6] * 1
                    lmt_beishu = self.limitMoney / (info_zhushu *
                                                    self.singleMoney)
                    tmp_ret = self.splitBeishu(
                        ','.join(rArr) + '|' + ','.join(bArr), lmt_beishu,
                        beishu, info_zhushu)
                    # ret.append(tmp_ret)
                    ret += tmp_ret

            # 不需要拆篮球
            else:
                tmp_ret = self.splitBeishu(
                    ','.join(rArr) + '|' + ','.join(bArr), lmt_beishu, beishu,
                    zhushu)
                # ret.append(tmp_ret)
                ret += tmp_ret

        else:
            tmp_ret = self.splitBeishu(','.join(rArr) + '|' + ','.join(bArr),
                                       lmt_beishu, beishu, zhushu)
            ret += tmp_ret

        return ret
Esempio n. 9
0
 def countAllZhuShu(self, codes, wtype):
     wtype = int(wtype)
     zhushu = 0
     # 排三排五七星彩直选
     if wtype in [415, 394, 391]:
         position = codes.split('|')
         zhushu = len(position[0])
         for i in range(1, len(position)):
             zhushu *= len(position[i])
     # 排三组选三
     if wtype in [420]:
         nneeds = 2
         nchose = len(codes.split(','))
         if nneeds > nchose:
             return 0
         zhushu = Math.C(nchose, nneeds) * 2
     # 排三组选六
     if wtype in [425]:
         nneeds = 3
         nchose = len(codes.split(','))
         if nneeds > nchose:
             return 0
         zhushu = Math.C(nchose, nneeds)
     return zhushu
Esempio n. 10
0
    def draw_3deg_lane(self,
                       params,
                       original_point,
                       life_time=0.2,
                       color=None):
        '''
        :param params: 车道线拟合参数,低次项-高次项
        :param length: 车道线总长
        :param original_point: 车的世界坐标(用于转曲线的世界坐标)
        :return:
        算法:
        这个曲线一定是以车的方向为x的,所以只需要将x等于一系列的值代入,得到y值,然后加上车的坐标
        转到世界坐标进行绘制!
        '''
        if color is None:
            color = self.carla_imported.Color(0, 0, 255)
        assert len(params) == 4, "Only 4 params in 3 deg polyfit!"
        x = np.linspace(0, 10, 100)
        y = np.power(x, 3) * params[3] + np.power(
            x, 2) * params[2] + x * params[1] + params[0]
        line_points = []
        for i in range(x.shape[0]):
            world_pos = myMath.convert_point_info_world_coordinate(
                target_xy=[y[i], x[i]],
                original_xy=[original_point[0], original_point[1]],
                original_yaw_radius=math.radians(self.vehicle_yaw))
            line_points.append(
                self.carla_imported.Location(x=world_pos[0],
                                             y=world_pos[1],
                                             z=0.25))

        last_point = line_points[0]
        # print("Point")
        # print(x[0],y[0])
        # print(self.vehicle.get_transform().location)
        # print(last_point)

        for i in range(1, len(line_points)):
            next_point = line_points[i]
            self.debug.draw_line(last_point,
                                 next_point,
                                 thickness=0.3,
                                 color=color,
                                 life_time=life_time,
                                 persistent_lines=False)
            last_point = next_point
Esempio n. 11
0
    def splitCodeDT( self, codes ):
        dt_re  = re.compile(r'\[D:(.*)\]\[T:(.*)\]')
        tmpstr = dt_re.match(codes)
        dcode  = tmpstr.group(1).split(',')
        tcode  = tmpstr.group(2).split(',')
        ret    = ''

        ddict = dict()
        for info in range(Config.CODENUM[int(self.lotId)]['changcinum']):
            ddict[info] = dcode[info]

        tlist = list()
        for info in range(Config.CODENUM[int(self.lotId)]['changcinum']):
            tmpdict = dict()
            if '*' == tcode[info].strip():
                continue

            tmpdict[info] = tcode[info]
            tlist.append(tmpdict)

        tmplist = list()
        yunum   = Config.CODENUM[int(self.lotId)]['codenum'] - (Config.CODENUM[int(self.lotId)]['changcinum'] - dcode.count('*'))
        for info in Math.combination( tlist, yunum ):
            tmpdict = copy.deepcopy( ddict )

            for var in info:
                tmpdict.update( var )

            if self.countAllZhuShu( ','.join( tmpdict.values() ) ) > self.flagzhushu:
                tmplist += self.splitOverCode( tmpdict, info )

            else:
                tmplist.append( tmpdict )

        for info in tmplist:

            if '' == ret:
                ret = ','.join( info.values() )

            else:
                ret += '$' + ','.join( info.values() )

        return ret
Esempio n. 12
0
    def splitHlist(self, hlist, flagnum):
        tmplist = list()
        for info in hlist:
            for i in list(info['code']):
                tmpdict = dict()
                tmpdict[info['innum']] = i
                tmplist.append(tmpdict)

        td = dict()
        cmblist = list()
        for info in Math.combination(tmplist, flagnum):
            #去掉重复位置选项
            for i in info:
                td = dict(td, **i)

            if len(td) == flagnum:
                cmblist.append(td)

            td = dict()

        return cmblist
Esempio n. 13
0
    def splitCodeFS( self, codes ):
        ret = ''
        fcode = codes.split(',')
        if Config.CODENUM[int(self.lotId)]['codenum'] == (14 - fcode.count('*') ):
            ret = codes
            return ret

        ddict = dict()
        for info in range(14):
            ddict[info] = '*'

        tlist = list()
        for info in range(14):
            tmpdict = dict()

            if '*' == fcode[info].strip():
                continue

            tmpdict[info] = fcode[info]
            tlist.append(tmpdict)

        tmplist = list()
        yunum   = Config.CODENUM[int(self.lotId)]['codenum']
        for info in Math.combination( tlist, yunum ):
            tmpdict = copy.deepcopy( ddict )

            for var in info:
                tmpdict.update( var )

            tmplist.append( tmpdict )

        for info in tmplist:

            if '' == ret:
                ret = ','.join( info.values() )

            else:
                ret += '$' + ','.join( info.values() )

        return ret
Esempio n. 14
0
    def get_vehicle_traffic_light_info(self):
        '''
        :return: 是否在等红绿灯,红绿灯状态(红还是绿),红绿灯和车的距离
        '''
        if self.vehicle.is_at_traffic_light():

            t = self.vehicle.get_traffic_light()
            if t is None:
                return False, None, None
            # 相对位置
            x, y = myMath.convert_point_into_relative_coordinate(
                target_xy=[t.get_location().x,
                           t.get_location().y],
                original_xy=[
                    self.vehicle.get_location().x,
                    self.vehicle.get_location().y
                ],
                original_yaw_radius=math.radians(self.vehicle_yaw))

            if x < 0:
                return False, None, None
            return True, self.vehicle.get_traffic_light_state(), x
        else:
            return False, None, None
    def get_direction_vector_series_and_car_to_next_waypoint_ratio(
            carla_engine,
            start_waypoint_xy_array,
            target_waypoint_xy_array,
            draw_in_UE=False):
        '''
        适用于WaypointsTarget环境的state求取


        # 以下代码作为参考
        获得车辆最近的路径点,以及接下来n个路径点(目前改为最后两个路径点,不会随着车辆位置更新!),然后返回与这两个路径点相关的参数,有:
        1.车辆到两个waypoints的中点距离
        2.waypoint方向角
        3.车辆到waypoint中点方向角
        4.车辆本身方向角

        #  另外这样获取waypoints实时更新的方法是不合适的,产生的rewards不对action连续

        # 原来的方法是车辆获取最近的waypoint然后求得下一个waypoints,现在改成一开始就确定waypoints
        因为使用获取最近waypoints的方法可能会产生变道
        原来的方法代码:
        # # 获得车辆的下两个waypoints的xy坐标
        # next_center_waypoints = self.engine.map.get_waypoint(
        #     # location
        #     self.engine.vehicle.get_location()
        # )
        # # 获得接下来5m的作为下一个路径点
        # next_next_center_waypoints = next_center_waypoints.next(5)[0]
        #
        # waypoint_list =((
        #            next_center_waypoints.transform.location.x,
        #            next_center_waypoints.transform.location.y
        #        ), (
        #            next_next_center_waypoints.transform.location.x,
        #            next_next_center_waypoints.transform.location.y
        #        ))
        #
        # # 在carla中绘制路径点
        # self.engine.draw_waypoint_list(
        #     [next_center_waypoints,next_next_center_waypoints],life_time=1)
        #
        # return waypoint_list

        # 注意点:
        因为最终计算的时候是需要两个waypoint来得到和车辆的距离
        以及 车辆到waypoints中心点的方向 和 两个waypoints方向 的夹角
        所以一定要保证waypoints中心点在车辆前方(否则就会后退)
        需要保证Waypoints的间隔足够大即可!也可以这里取点时取后面两个点而不是一个点!

        # 这里的代码是求得距离车辆最近的点,然后往下找3个点,现在更新成一开始指定的点!
        # # 求得最近的waypoints的index,然后找下一个!如果到了waypoints的末端?
        # distance = np.sqrt(
        #     np.sum(np.square(self.car_waypoints_xy_array - np.array([self.engine.vehicle.get_location().x,
        #                                                              self.engine.vehicle.get_location().y])), axis=1))
        #
        # # print(distance)
        # # 最大的index
        # index_max = distance.shape[0] - 1
        # # 找到距离最近的waypoints的index
        # index = int(np.argmin(distance))
        #
        #
        # index = index_max - 1
        #
        # # 这里点取得向前一点儿
        # next_point_index = index + 3
        # if next_point_index > index_max: next_point_index = index_max

        # if draw_in_UE:
        #     # 作出两个waypoints的线段
        #     start = self.car_waypoints_list[index]
        #     end = self.car_waypoints_list[next_point_index]
        #     self.engine.draw_line(start, end, life_time=1, color=(0, 255, 0))
        # center_point = (self.car_waypoints_xy_array[index, :].reshape(-1) +
        #                 self.car_waypoints_xy_array[next_point_index, :].reshape(-1)) / 2

        '''

        # 车辆位置
        vehicle_location = carla_engine.vehicle.get_location()
        car_point = np.array([vehicle_location.x, vehicle_location.y])

        if draw_in_UE:
            # waypoint中点
            center_point = (start_waypoint_xy_array +
                            target_waypoint_xy_array) / 2
            center_point_transform = carla_engine.make_transform(
                x=center_point[0], y=center_point[1], z=vehicle_location.z)
            carla_engine.draw_point_xyz(center_point[0],
                                        center_point[1],
                                        carla_engine.vehicle.get_location().z +
                                        0.25,
                                        color=(0, 255, 255),
                                        thickness=0.1)

            carla_engine.draw_line_location(vehicle_location,
                                            center_point_transform.location,
                                            life_time=1,
                                            color=(0, 0, 255))

        # waypoints的单位方向向量
        way_unit_direction = target_waypoint_xy_array - start_waypoint_xy_array
        way_unit_direction /= np.linalg.norm(way_unit_direction, 2)
        # 车辆到中心点的单位方向向量
        car_to_way_unit_direction = (target_waypoint_xy_array - car_point)
        car_to_way_unit_direction /= np.linalg.norm(car_to_way_unit_direction,
                                                    2)

        # 车辆本身的单位方向向量
        car_unit_direction = carla_engine.vehicle.get_transform(
        ).get_forward_vector()
        car_unit_direction = np.array(
            [car_unit_direction.x, car_unit_direction.y])

        # 车辆到target点和总路程的比值
        total_distance = np.linalg.norm(
            target_waypoint_xy_array - start_waypoint_xy_array, 2)
        now_distance = np.linalg.norm(target_waypoint_xy_array - car_point, 2)
        car_to_target_distance_ratio = now_distance / total_distance

        # 车辆的yaw角度
        car_yaw = math.radians(carla_engine.vehicle_yaw)

        # 增加:相对于车辆坐标的目标waypoint的x和y
        target_xy_array_relate_to_car = cMath.convert_point_into_relative_coordinate(
            target_waypoint_xy_array, car_point, original_yaw_radius=car_yaw)

        return way_unit_direction, car_to_way_unit_direction, car_unit_direction, car_to_target_distance_ratio, target_xy_array_relate_to_car