예제 #1
0
파일: rebalance.py 프로젝트: DmitryBol/reel
def binary_search(game, gametype, start_point: Point, params, sorted_symbols, i, j, right, left=1):
    if gametype.name == 'base':
        main_frequency = start_point.base.frequency
        second_frequency = start_point.free.frequency
    elif gametype.name == 'free':
        main_frequency = start_point.free.frequency
        second_frequency = start_point.base.frequency
    else:
        raise Exception('No such gametype for binary_search')

    left_frequency = chess(main_frequency, sorted_symbols[i], sorted_symbols[j], game, k=left)
    right_frequency = chess(main_frequency, sorted_symbols[i], sorted_symbols[j], game, k=right)

    left_point = Point(main_frequency=left_frequency, second_frequency=second_frequency, game=game,
                       main_type=gametype.name)
    right_point = Point(main_frequency=right_frequency, second_frequency=second_frequency, game=game,
                        main_type=gametype.name)

    left_point.fill_point(game, params, base=True, sd_flag=False)
    left_point.fill_point(game, params, base=False, sd_flag=True)

    right_point.fill_point(game, params, base=True, sd_flag=False)
    right_point.fill_point(game, params, base=False, sd_flag=True)

    left_val = calc_val(params, left_point)
    right_val = calc_val(params, right_point)
    middle = (right + left) // 2

    while right - left > 2:
        middle_frequency = chess(main_frequency, sorted_symbols[i], sorted_symbols[j], game, k=middle)
        middle_point = Point(main_frequency=middle_frequency, second_frequency=second_frequency, game=game,
                             main_type=gametype.name)

        middle_point.fill_point(game, params, base=True, sd_flag=False)
        middle_point.fill_point(game, params, base=False, sd_flag=True)

        middle_val = calc_val(params, middle_point)

        if middle_val * left_val < 0:
            right = middle
            right_val = middle_val

        elif middle_val * right_val < 0:
            left = middle
            left_val = middle_val
        else:
            return middle

        middle = (left + right) // 2

    return middle
예제 #2
0
파일: Optimize.py 프로젝트: DmitryBol/reel
def descent_free(params, start_point: Point, game, balance=True):
    base_rtp, rtp, sdnew, hitrate, err_base_rtp, err_rtp, err_sdnew, err_hitrate = get_parameters_from_dict(
        params)

    print('started free descent')

    # print('start point base reels: ', start_point.base.reels)

    if rtp == -1:
        return [start_point, game]

    roots = initial_free_distributions(game,
                                       start_point.base.frequency,
                                       start_point.free.frequency,
                                       params,
                                       base_reels=start_point.base.reels)
    finded_min = Point(second_frequency=roots[0].base.frequency,
                       main_frequency=roots[0].free.frequency,
                       game=game,
                       main_type='free',
                       base_reels=start_point.base.reels)
    finded_min.base.reels = start_point.base.reels

    value_list = []
    for root in roots:
        print(root.free.frequency, ' value is ', root.value,
              'base_rtp, rtp, sdnew, hitrate :', root.base_rtp, root.rtp,
              root.sdnew, root.hitrate)
        value_list = value_list + [root.value]

    index_list = list(range(len(value_list)))
    double_bubble(value_list, index_list)
    print('assuming base rtp, rtp, sd ', base_rtp, rtp, sdnew)
    print('assuming errors for base rtp, rtp,  sd ', err_base_rtp, err_rtp,
          err_sdnew)

    index_list.remove(0)
    index_list = [0] + index_list

    for index in index_list:
        print('TRYING POINT', roots[index].free.frequency, ' value is ',
              roots[index].value, 'base_rtp, rtp, sdnew, hitrate :',
              roots[index].base_rtp, roots[index].rtp, roots[index].sdnew,
              roots[index].hitrate)
        root = roots[index]

        currentScale = 0
        while currentScale < scaleLimit:
            number_of_groups = len(game.free.wildlist) + len(game.free.ewildlist) + \
                               len(game.free.scatterlist) + 1
            max_number_of_groups = len(game.base.symbol)
            while number_of_groups <= max_number_of_groups:
                temp_group = Group(game,
                                   'free',
                                   root,
                                   number_of_groups,
                                   params,
                                   rebalance=balance,
                                   sd_flag=False,
                                   base_reels=start_point.base.reels)
                print('groups ', temp_group.split.groups)

                temp_group.print_group('free')

                finded_min = temp_group.find_best_point()
                if finded_min != -1:
                    if finded_min.value < 1:
                        print('ending with ', finded_min.value)
                        print('base ', finded_min.base_rtp)
                        print('rtp ', finded_min.rtp)
                        print('sdnew ', finded_min.sdnew)
                        print('hitrate ', finded_min.hitrate)
                        root = copy.deepcopy(finded_min)
                        print(root.free.frequency)
                        finded_min.fill_point_metric(params,
                                                     base=False,
                                                     sd_flag=False)
                        finded_min.base.reels = copy.deepcopy(
                            start_point.base.reels)
                        return [finded_min, game]
                    else:
                        print('path ', finded_min.value)
                        root = copy.deepcopy(finded_min)
                else:
                    if 0.5 * max_number_of_groups < number_of_groups < max_number_of_groups:
                        number_of_groups = max_number_of_groups
                    else:
                        number_of_groups += 1
            root.scaling()
            currentScale += 1
            print('SCALING ', currentScale)

    print('Free done')

    finded_min.fill_point(game,
                          params,
                          base=False,
                          sd_flag=True,
                          base_shuffle=False,
                          free_shuffle=False)
    finded_min.base.reels = copy.deepcopy(start_point.base.reels)

    return [finded_min, game]
예제 #3
0
파일: Optimize.py 프로젝트: DmitryBol/reel
def descent_base(params, game, balance=True, start_point=None):
    base_rtp, rtp, sdnew, hitrate, err_base_rtp, err_rtp, err_sdnew, err_hitrate = get_parameters_from_dict(
        params)

    start_game = copy.deepcopy(game)

    out = sm.get_scatter_frequency(game, hitrate, err_hitrate)
    print('Generated scatter frequency')
    if out == -1 and hitrate != -1:
        raise Exception(
            'Game rules not contain freespins, but you try to fit HitRate. Please, set it -1'
        )
    elif out == -1:
        out = sm.OutResult(game.base.scatterlist)
        out.add_symbols(game.base.symbol)

    blocked_scatters = []
    for scatter_id in game.base.scatterlist:
        if max(game.base.symbol[scatter_id].scatter) > 0:
            blocked_scatters.append(scatter_id)

    print('started base descent')
    game.base.create_simple_num_comb(game.window, game.line)
    game.free.create_simple_num_comb(game.window, game.line)
    print('created_num_comb')

    roots = []
    if start_point is None:
        roots = initial_base_distributions(game, out, params)
    else:
        roots.append(start_point)
    finded_min = Point(main_frequency=roots[0].base.frequency,
                       second_frequency=roots[0].free.frequency,
                       game=game,
                       main_type='base')
    print('INITIAL POINTS, THEIR DISTRIBUTIONS, VALUES AND PARAMETERS:')

    value_list = []
    for root in roots:
        # root.fillVal(base_rtp, rtp, sdnew, err_base_rtp, err_rtp, err_sdnew)
        print(root.base.frequency, ' value is ', root.value,
              'base_rtp, rtp, sdnew, hitrate :', root.base_rtp, root.rtp,
              root.sdnew, root.hitrate)
        value_list = value_list + [root.value]
    index_list = list(range(len(value_list)))
    double_bubble(value_list, index_list)
    print('assuming base rtp, rtp, sd ', base_rtp, rtp, sdnew)
    print('assuming errors for base rtp, rtp,  sd ', err_base_rtp, err_rtp,
          err_sdnew)

    # print(value_list)
    index_list.remove(0)
    index_list = [0] + index_list

    for index in index_list:
        print('TRYING POINT', roots[index].base.frequency, ' value is ',
              roots[index].value, 'base_rtp, rtp, sdnew, hitrate :',
              roots[index].base_rtp, roots[index].rtp, roots[index].sdnew,
              roots[index].hitrate)
        root = roots[index]

        currentScale = 0
        while currentScale < scaleLimit:
            number_of_groups = len(game.base.wildlist) + len(game.base.ewildlist) + \
                               len(game.base.scatterlist) - len(blocked_scatters) + 1
            max_number_of_groups = len(
                game.base.symbol) - len(blocked_scatters)
            while number_of_groups <= max_number_of_groups:
                temp_group = Group(game,
                                   'base',
                                   root,
                                   number_of_groups,
                                   params,
                                   rebalance=balance,
                                   sd_flag=False)
                print('groups ', temp_group.split.groups)

                temp_group.print_group()

                finded_min = temp_group.find_best_point()
                if finded_min != -1:
                    if finded_min.value < 1:
                        print('ending with ', finded_min.value)
                        print('base ', finded_min.base_rtp)
                        print('rtp ', finded_min.rtp)
                        print('sdnew ', finded_min.sdnew)
                        print('hitrate ', finded_min.hitrate)
                        root = copy.deepcopy(finded_min)
                        print(root.base.frequency)
                        game.base.reels = copy.deepcopy(finded_min.base.reels)
                        game.free.reels = copy.deepcopy(finded_min.free.reels)
                        finded_min.fill_point_metric(params)
                        return [finded_min, game]
                    else:
                        print('path ', finded_min.value)
                        root = copy.deepcopy(finded_min)
                else:
                    if 0.5 * max_number_of_groups < number_of_groups < max_number_of_groups:
                        number_of_groups = max_number_of_groups
                    else:
                        number_of_groups += 1

            root.scaling()
            currentScale += 1
            print('SCALING ', currentScale)

    print('Base done')

    if finded_min == -1:
        return [start_point, start_game]

    finded_min.fill_point(game,
                          params,
                          base=False,
                          sd_flag=True,
                          base_shuffle=False,
                          free_shuffle=False)

    return [finded_min, game]
예제 #4
0
파일: Groups.py 프로젝트: DmitryBol/reel
    def __init__(self,
                 game,
                 type_name,
                 root: Point,
                 number_of_groups,
                 params,
                 rebalance=True,
                 sd_flag=True,
                 base_reels=None):
        self.root = root

        base_flag = True

        if type_name == 'base':
            gametype = game.base
            main_frequency = root.get_base_frequency()
            second_frequency = root.get_free_frequency()
        elif type_name == 'free':
            gametype = game.free
            main_frequency = root.get_free_frequency()
            second_frequency = root.get_base_frequency()
            base_flag = False
        else:
            raise Exception('Not supported gametype')

        self.total = [sum(i) for i in main_frequency]
        self.split = Split(gametype, number_of_groups, main_frequency)
        self.points = []
        for i in range(number_of_groups - 1):
            for j in range(i + 1, number_of_groups):
                group1 = self.split.group_transfer(gametype,
                                                   i,
                                                   j,
                                                   balance=rebalance)
                # print('group1: ', group1)
                if group1:
                    new_point = Point(main_frequency=group1.frequency,
                                      second_frequency=second_frequency,
                                      game=game,
                                      main_type=type_name,
                                      base_reels=base_reels)
                    new_point.fill_point(game,
                                         params,
                                         base=base_flag,
                                         sd_flag=sd_flag)
                    self.points.append(new_point)
                group2 = self.split.group_transfer(gametype,
                                                   j,
                                                   i,
                                                   balance=rebalance)
                if group2:
                    new_point = Point(main_frequency=group2.frequency,
                                      second_frequency=second_frequency,
                                      game=game,
                                      main_type=type_name,
                                      base_reels=base_reels)
                    new_point.fill_point(game,
                                         params,
                                         base=base_flag,
                                         sd_flag=sd_flag)
                    self.points.append(new_point)
예제 #5
0
파일: rebalance.py 프로젝트: DmitryBol/reel
def rebalance(start_point: Point, game, gametype, params):
    print('REBALANCE')

    print('\n\n\n')
    print(params['base_rtp'], params['rtp'], params['sdnew'])
    print(start_point.base_rtp, start_point.rtp, start_point.sdnew)
    print('metric: ', start_point.metric(params, base=False, sd_flag=True))

    if start_point.metric(params, base=False, sd_flag=True) < 1:
        return [start_point, game]

    print('during fitting')
    print('base rtp: ', start_point.base_rtp)
    print('rtp: ', start_point.rtp)
    print('sdnew: ', start_point.sdnew)
    print('value: ', start_point.value)
    print(start_point.base.frequency)

    prev_val = calc_val(params, start_point)

    blocked_scatters = []
    if gametype.name == 'base':
        for scatter_id in gametype.scatterlist:
            if max(gametype.symbol[scatter_id].scatter) > 0:
                blocked_scatters.append(scatter_id)
    sortedSymbols = []
    val = []
    for i in range(len(gametype.symbol)):
        if i not in blocked_scatters and i not in gametype.wildlist and i not in gametype.ewildlist:
            sortedSymbols.append(i)
            val.append(gametype.symbol[i].payment[game.window[0]])
    double_bubble(val, sortedSymbols)
    print('sorted = ', sortedSymbols, '\n')
    SD = [start_point.sdnew, start_point.base_rtp, start_point.rtp]

    out_point = None
    out_game = None

    for i in range(len(sortedSymbols) - 1):
        for j in range(i + 1, len(sortedSymbols)):
            if gametype.name == 'base':
                list_k = [sum(start_point.base.frequency[_]) for _ in range(len(start_point.base.frequency))]
                max_k = max(list_k)
                best_k = binary_search(game, gametype, start_point, params, sortedSymbols, i, j, max_k, 1)
                if best_k == 0:
                    print('\nazaza\n')
                    continue
                new_frequency = chess(start_point.base.frequency, sortedSymbols[i], sortedSymbols[j], game, k=best_k)
            elif gametype.name == 'free':
                list_k = [sum(start_point.free.frequency[_]) for _ in range(len(start_point.free.frequency))]
                max_k = max(list_k)
                best_k = binary_search(game, gametype, start_point, params, sortedSymbols, i, j, max_k, 1)
                if best_k == 0:
                    print('\nazaza\n')
                    continue
                new_frequency = chess(start_point.free.frequency, sortedSymbols[i], sortedSymbols[j], game, k=best_k,
                                      base=False)
            else:
                raise Exception('No such gametype for rebalance')

            if new_frequency is None:
                continue
            else:
                if gametype.name == 'base':
                    result_point = Point(new_frequency, start_point.free.frequency, game)
                elif gametype.name == 'free':
                    result_point = Point(start_point.base.frequency, new_frequency, game)
                else:
                    raise Exception('No such gametype in rebalance')
                result_point.fill_point(game, params, base=True, sd_flag=False)
                result_point.fill_point(game, params, base=False, sd_flag=True)
                print('trying to change in ', sortedSymbols[i], ' and ', sortedSymbols[j], ' positions')
                print('base rtp: ', result_point.base_rtp)
                print('rtp: ', result_point.rtp)
                print('sdnew: ', result_point.sdnew)
                print('hitrate: ', result_point.hitrate)
                print('val: ', result_point.value)
                if gametype.name == 'base':
                    print('total = ', sum(result_point.base.frequency[0]), 'base ', result_point.base.frequency)
                elif gametype.name == 'free':
                    print('total = ', sum(result_point.free.frequency[0]), 'free ', result_point.free.frequency)
                print('\n')
                new_val = calc_val(params, result_point)
                print('prev_val: ', prev_val, 'new_val: ', new_val)
                if abs(new_val) < abs(prev_val):
                    prev_val = new_val
                    SD = [result_point.sdnew, result_point.base_rtp, result_point.rtp]
                    out_point = copy.deepcopy(result_point)
                    out_game = copy.deepcopy(game)
                    if out_point.metric(params, base=False, sd_flag=True) < 1:
                        return [out_point, game]

                    print('\nChanging result\n')

    print('BEST SD IS ', SD[0])
    print('with base_rtp: ', SD[1], 'rtp: ', SD[2])
    if out_game is None:
        out_game = game
    if out_point is None:
        out_point = start_point
    return [out_point, out_game]