代码之家  ›  专栏  ›  技术社区  ›  lpt

寻找游戏策略

  •  0
  • lpt  · 技术社区  · 5 年前

    我想匹配如果一个元组返回提供的值,结果应该是坦白或不坦白。我们称之为回报吧。但是在下面的测试代码中,它返回(0,0)作为招供,而不是在原始列表中返回招供。

    Dont confess: (-1, -1) 
    Confess : (-10, 0)
    Confess : (0, -10)
    Dont Confess: (-10, -10)
    
    
    dntCon=(-1, -1) 
    conf=(-10, 0)
    confess=(0, -10)
    DntConff=(-5, -5)
    
    import random 
    from random import shuffle
    from random import sample
    
    
    x = [-1, -10, 0, -5]
    y = [-1, 0, -10, -5]
    
    #print(sample(list, len(list)))
    
    for m in range(0, 3): 
        x=random.sample(x, len(x))
        y=random.sample(y, len(y))
        #print(x, y)
    
        for i in x:
            #print(i)
            for j in y:
                #print(i, j)
                if(i ==-1 & j==-1 ):
                    print(i, j, "ncoo")
                    #print( i, j,'')
                elif (i==-10 & j==0): 
                    print(i, j, 'Confess')
                elif (i==0 & j==-10):
                    print(i, j, 'Confess')
                elif (i==-10 & j==-10):
                    print(i, j, 'ncoo')
                else:
                    "not met"
    

    结果

    (0, 0, 'Confess')
        (-10, -10, 'ncoo')
        (-10, -1, 'ncoo')
        (-1, -1, 'ncoo')
        (0, 0, 'Confess')
        (-10, -10, 'ncoo')
        (-10, -1, 'ncoo')
        (-1, -1, 'ncoo')
        (-10, -1, 'ncoo')
        (-10, -10, 'ncoo')
        (-1, -1, 'ncoo')
        (0, 0, 'Confess')
    

    为什么这个循环会返回( 0, 0

    0 回复  |  直到 5 年前
        1
  •  1
  •   Kamal Aujla    5 年前

    Difference between 'and' (boolean) vs. '&' (bitwise) in python. Why difference in behavior with lists vs numpy arrays? 请尝试以下代码:

    Dont_confess: (-1, -1)
    Confess : (-10, 0)
    Confess : (0, -10)
    DontConfess: (-10, -10)
    
    
    dntCon=(-1, -1) 
    conf=(-10, 0)
    confess=(0, -10)
    DntConff=(-5, -5)
    
    import random 
    from random import shuffle
    from random import sample
    
    
    x = [-1, -10, 0, -5]
    y = [-1, 0, -10, -5]
    
    #print(sample(list, len(list)))
    
    for m in range(0, 3): 
        x=random.sample(x, len(x))
        y=random.sample(y, len(y))
        #print(x, y)
    
        for i in x:
            #print(i)
            for j in y:
                #print(i, j)
                if(i ==-1 and j==-1 ):
                    print(i, j, "ncoo")
                    #print( i, j,'')
                elif (i==-10 and j==0):
                    print(i, j, 'Confess')
                elif (i==0 and j==-10):
                    print(i, j, 'Confess')
                elif (i==-10 and j==-10):
                    print(i, j, 'ncoo')
                else:
                    "not met"