# beliefs.py

class beliefs: #code or individual

    def __init__(self, dim,p,seq,kind=1):
        self.dim = dim
        self.p= p
        self.seq=seq
        self.vector=[]
        self.kind=kind #0=code 1=individual

    def create(self,zeros=0): #create random beliefs to start with
        random.seed()
        for i in range(self.dim):
            if zeros==0:
                self.vector.append(random.choice(self.seq))
            else:
                self.vector.append(0)

    def update(self,vec):
        if self.kind==1:
            for i in range(self.dim):
                self.update_dim1(self,i,vec[i])

    def update_dim1(self,ind,belief): #compared to a given reference
        #ind pointing at specific dimension
        if belief_i!=0:
            if random.random()<p:
                self.vector[ind]=belief #update to follow the code

    def update_code(self,orga,reality): #update as if code
        for i in range(self.dim):
            if orga.get_reality_check(reality)[i]!=0:
                k=orga.get_reality_check(reality)[i]-orga.get_code_check(self)[i]
                if k>0: #more people are aligned with reality than the code
                    probability=(1-self.p)^k
                    if random.random()>probability:#the code learns
                        self.vector[i]=reality[i]

    def veccheck(self,vec):
        indexes=[]
        for i in range(self.dim):
            if self.vector[i]==vec[i]:
                indexes.append(i)
        return indexes