其他分享
首页 > 其他分享> > 【验证狼人杀三行定律】

【验证狼人杀三行定律】

作者:互联网

验证狼人杀三行定律

主体框架

if __name__ == '__main__':
    # lang_san_jiao = [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
    lang_san_jiao = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]  # 提前划分的三角
    all = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

    n = 0  # 三角中第三个位置为狼的次数
    n2 = 0  # 随机选择的位置为狼的次数
    for _ in range(100000):
        lang = random.sample(all, 4)  # 随机选择四个狼

        # 排除掉1111的情况保证有两狼在同一个三角中
        while not1111(lang):
            lang = random.sample(all, 4)

        find = find_lang_in_the_same_sanjiao(lang)  # 找到在同一个三角的两个狼

        # 若三角中剩下的为狼则 n+1
        place = other_place2(find)
        if place in lang:
            n += 1

        # 去掉两狼
        all_copy = all[:]
        all_copy.remove(find[0])
        all_copy.remove(find[1])
        place2 = random.sample(all_copy, 1)[0]  # 从剩下的10张牌中随机选择一张
        if place2 in lang:
            n2 += 1

    print(n)
    print(n2)

用到的函数

# 判断四只狼中是否有两狼在用一个三角
def find_lang_in_the_same_sanjiao(lang):
    lang_san_jiao = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
    for san_jiao in lang_san_jiao:
        if lang[0] in san_jiao and lang[1] in san_jiao:
            return [lang[0], lang[1]]
        elif lang[0] in san_jiao and lang[2] in san_jiao:
            return [lang[0], lang[2]]
        elif lang[0] in san_jiao and lang[3] in san_jiao:
            return [lang[0], lang[3]]
        elif lang[1] in san_jiao and lang[2] in san_jiao:
            return [lang[1], lang[2]]
        elif lang[1] in san_jiao and lang[3] in san_jiao:
            return [lang[1], lang[3]]
        elif lang[2] in san_jiao and lang[3] in san_jiao:
            return [lang[2], lang[3]]


# 已知三角中的两狼确定三角中最后一个位置
def other_place2(find):
    lang_san_jiao = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
    p = []
    for f in find:
        for san_jiao in lang_san_jiao:
            if f in san_jiao:
                san_jiao.remove(find[0])
                san_jiao.remove(find[1])
                return san_jiao[0]

结果

请添加图片描述
请添加图片描述
在这里插入图片描述
可以看到两种结果分别稳定在 8.7%和20%

标签:lang,10,return,san,jiao,验证,狼人,三行,find
来源: https://blog.csdn.net/cqn2219076254/article/details/123421715