Python算法随机停顿

我正尝试在Python中运行一种学习算法,该算法将确定竞技Fortnite锦标赛的最佳格式。

我现在遇到的问题是我的程序在比赛期间偶而停顿,看似随机。我尝试定位问题,但没有成功。我认为问题可能出在我算法中的球员具有给定的打法,如果太低,球员将不会与任何人打架,这可能导致比赛中没人攻击任何人,但是我没有知道解决方法

这些是play_match()方法Player类,以及我如何创建球员和比赛的方法

all_sorted_players = []

player_amt = random.randint(75000,90000)  # I make this lower when coding and higher when leaving it to run overnight

for i in range(player_amt - len(all_players)):  # Used so I can manually add players above
    skill_bias = 1  # between .8 and 1.2 (lower = lower skill tourney,higher = higher skill tourney)

    p_skill = random.randint(0,100) + random.random()  # The only true random variable

    name = ''.join((random.choice(Syntax) for x in range(random.randint(3,20))))
    min_skill = 0
    max_skill = int(p_skill*10)
    skill = random.randint(min_skill,max_skill)*skill_bias
    play_style = ((p_skill / 100) * 10 + random.random()) / 10
    drop_spot = -1
    rotation = random.randint(int(p_skill/2*10),int(p_skill*30))
    while drop_spot == -1:
        b1 = int((max_skill/10 + random.randint(1,5) - skill/10) / 5)
        b2 = 1 - play_style
        drop_spot = int(b1 * b2)
        if drop_spot > 30:
            drop_spot /= 2
            drop_spot += random.randint(1,3) - random.randint(1,3)
        elif drop_spot < 1:
            drop_spot = 1
    all_players.append(Player(skill,rotation,drop_spot,play_style,name))
    player_pool.append(Player(skill,name))
# I cut out all `print()`s and 
class Player:
    points = 0
    points_match = 0
    kills = 0
    t_kills = 0
    matches = 0
    placement_match = 0
    avg_placement = 0
    total_placement = 0
    wins = 0
    match_report = []

    def __init__(self,mech,name):
        self._skill = mech
        self._rotate = rotation
        self._drop_spot = drop_spot  # unused for Now
        self._play_style = play_style
        self._name = name
        self._match_report = self.match_report

    # I cut out all getters and setters
def play_match(players_in_match,style_bias):
    players_alive = len(players_in_match)

    pool = players_in_match

    while players_alive > 1:
        # Simulate the match
        if not len(pool) == 2:
            for pl in range(len(pool)):
                if pl >= len(pool):
                    break
                nums = []
                for all_p in range(len(pool)):
                    if not all_p == pl:
                        if pool[all_p].get_rotation()/1000 < random.random()/1.02:
                            nums.append(all_p)
                if pool[pl].get_play_style() + style_bias > random.random():
                    p2 = -1
                    if len(nums) > 0:
                        nump = random.randint(0,len(nums) - 1)
                        p2 = nums[nump]
                    if p2 != -1:
                        if (pool[pl].get_skill() + random.random() * 20 + 20) >= (
                                pool[p2].get_skill() + random.random() * 20):
                            pool[pl].add_kills(1)
                            pool[p2].set_placement_match(players_alive)
                            del (pool[p2])
                            players_alive -= 1
                        else:
                            pool[p2].add_kills(1)
                            pool[pl].set_placement_match(players_alive)
                            del (pool[pl])
                            players_alive -= 1
        elif len(pool) == 2:
            if (pool[0].get_skill() + random.random() * 20 + 20) >= (
                    pool[1].get_skill() + random.random() * 20):
                pool[0].add_kills(1)
                pool[1].set_placement_match(2)
                del (pool[1])
                players_alive -= 1
            else:
                pool[1].add_kills(1)
                pool[0].set_placement_match(2)
                del (pool[0])
                players_alive -= 1
        if players_alive == 1:
            pool[0].set_placement_match(1)
        players_alive = len(pool)

Player类和play_match()方法都放在一个文件中(method_storage.py),而代码本身在一个单独的文件中(placement.py)

此问题的一个简单解决方案是使所有玩家变量完全随机,而不是基于skill,但是,这并不是玩家技能的实际表现,因此这不是长期解决方案。这确实表明该问题与Player变量有关,并且可能与匹配的模拟方式有关。

我的整个代码都可以在github here上找到。

如果您需要其他代码段,请在注释中提问。

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...