Squad Vb

This program has been disqualified.


Authormomo
Submission date2012-04-12 09:36:49.594099
Rating6591
Matches played241
Win rate64.73

Source code:

import random

def highest(v):
    return random.choice([i for i in range(len(v)) if max(v) == v[i]])

def lowest(v):
    return random.choice([i for i in range(len(v)) if min(v) == v[i]])

def best(c):
    return highest([c[1]-c[2], c[2]-c[0], c[0]-c[1]])

def mean(c):
    return sum(c)/length(c)

# alpha in [0,1]: greediness 
def attack(yo, tu, alpha):
    r = res[yo][tu]
    p1 = yo
    if r == -1:
        p1 = (yo + 1) % 3
    elif r == 0 and random.random() < alpha:
        p1 = (yo + 2) % 3
    return p1

def attackpa(pa, alpha):
    yo = pa[0]
    tu = pa[1]
    r = res[yo][tu]
    p1 = yo
    if r == -1:
        p1 = (yo + 1) % 3
    elif r == 0 and random.random() < alpha:
        p1 = (yo + 2) % 3
    return p1
                   
if(1):
    if (input == ""):
        N = 1
        AR1 = .92
        states = ["R","S","P"]
        st = [0,1,2]
        dna = [0,1,2,3,4,5,6,7,8,9]
        dnadic = {(0,0): 0,(1,0): 1,(2,0): 2,
                  (0,1): 3,(1,1): 4,(2,1): 5,
                  (0,2): 6,(1,2): 7,(2,2): 8}
        pairs = [(0,0),(1,0),(2,0), (0,1),(1,1),(2,1), (0,2),(1,2),(2,2)]
        sdic = {"R":0, "S":1, "P":2}
        
        
        forwardbias = 2
        res = [[0, 1, -1], [-1, 0, 1], [1, -1, 0]]
        MEM1 = MEM2 = MEM3 = []
        
        h = 5 #10
        MEM5 = [0,1,2,4] #000114
    
     
       
        M5 = len(MEM5)
        
        M = M5 + 1
        models = ([1, 0, 0]*M)
      
        
        state = [0] * (M*3)
      
        yo = random.choice(st)
        tu = random.choice(st)

        pa = (yo, tu)
        hi = [pa]
        hiyt = states[yo]+states[tu]
        hit = states[yo]+" "
        hiy = " " + states[tu]
        choices = []
        prognosis = [random.choice(st) for i in range(M*3)]


    else:
          tu = sdic[input]
          pa = (yo,tu)
          hi += [pa]

          hiyt += states[yo]+states[tu]
          hit += states[yo]+" "
          hiy += " " + states[tu]
          state = [ AR1 * state[i] + res[prognosis[i]][tu] * models[i] for i in range(M*3)]
        
 

    prognosis = [random.choice(st) for l in range(M*3)]
    i = -3
    prob= [0,0,0, 0,0,0, 0,0,0]
    
    
    # Squad

                
        
    for k in MEM5:
                prob0 = [0,0,0, 0,0,0, 0,0,0]
                if k == 0:
                    for j in range(h):
                        r = max([random.choice(range(N)) for l in range(forwardbias)])
                        prob0[dnadic[hi[r]]]+= 1
                  
                    i += 3; prognosis[i] = attackpa(pairs[highest(prob0)],0.85);
                    

        
            
                if 0 < k and k < N:
                    for j in range(h):
                        r = max([random.choice(range(N-k)) for l in range(forwardbias)])
                        z = ((yo + hi[r+k][0] - hi[r][0])%3,((tu + hi[r+k][1] - hi[r][1]) % 3))
                        prob0[dnadic[z]]+= 1
                    i += 3; prognosis[i] = attackpa(pairs[highest(prob0)],0.85);    
                        
                      
    
  
  

    best = highest(state)   
    yo = prognosis[best] #0  5 

    
    output = states[yo]  
        
    N = N + 1