Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return"Chameleon",function(t,t2)
- local set,names={},{}
- local function rep()
- local r,len=math.random(3)-1,0
- for i=#t-1,1,-1 do
- local v=t[i+1]
- for j=0,i do
- if t[i-j]==t[#t-j]and t2[i-j]==t2[#t2-j]then
- if j>=len then
- r,len=(v+1)%3,j+1
- end
- else
- break
- end
- end
- end
- return r
- end
- names[rep]="rep"
- local function rep2()
- local r,len=math.random(3)-1,0
- for i=#t-1,1,-1 do
- local v=t[i+1]
- for j=0,i do
- if t[i-j]==t[#t-j]then
- if j>=len then
- r,len=(v+1)%3,j+1
- end
- else
- break
- end
- end
- end
- return r
- end
- names[rep2]="rep2"
- local function repbias()
- local a,b,c=0,0,0
- for i=#t-1,1,-1 do
- local v=t[i+1]
- for j=0,i do
- if t[i-j]==t[#t-j]then
- local n=3^j/(#t-i)
- if v==0 then a=a+n elseif v==1 then b=b+n else c=c+n end
- else
- break
- end
- end
- end
- if a>b and a>c then return 1
- elseif b>a and b>c then return 2
- elseif c>a and c>b then return 0
- elseif a>b and a==c then return 0
- elseif b>c and b==a then return 1
- elseif c>a and c==b then return 2
- else return math.random(3)-1 end
- end
- names[repbias]="repbias"
- local function hist()return #t==0 and math.random(3)-1 or(t[math.random(#t)]+1)%3 end
- names[hist]="hist"
- local function hist3()return #t==0 and math.random(3)-1 or(t[math.random(math.max(1,#t-3),#t)]+1)%3 end
- names[hist3]="hist3"
- local randbias do
- local r,p,s=0,0,0
- local function f(x)
- if x==0 then r=r+1 elseif x==1 then p=p+1 else s=s+1 end
- end
- for i=1,#t do f(t[i])end
- randbias=function()
- if #t~=0 then f(t[#t])else return math.random(3)-1 end
- local x=math.random(r+p+s)
- if x<=r then return 1 end
- if x<=r+p then return 2 end
- return 0
- end
- end
- names[randbias]="randbias"
- local even do
- local r,p,s=0,0,0
- even=function()
- if math.random(2)==1 then
- if p>r and r < s then r=r+1 return 0 end
- if p < r and p < s then p=p+1 return 1 end
- if s < r and p>s then s=s+1 return 2 end
- if r < s and p < s then if math.random(2)==1 then r=r+1 return 0 else p=p+1 return 1 end end
- if p>r and p>s then if math.random(2)==1 then r=r+1 return 0 else s=s+1 return 2 end end
- if p < r and s < r then if math.random(2)==1 then p=p+1 return 1 else s=s+1 return 2 end end
- end
- local n=math.random(3)-1
- if n==0 then r=r+1 elseif n==1 then p=p+1 else s=s+1 end
- return n
- end
- end
- names[even]="even"
- local f={}for a,_ in pairs(names)do f[#f+1],set[a]=a,0 end
- for i=1,#f do local x=function()t,t2=t2,t local r=f[i]()t,t2=t2,t return r end set[x]=0 names[x]="anti"..names[f[i]]f[#f+1]=x end
- for i=1,#f do local x=function()return(f[i]()+1)%3 end local y=function()return(f[i]()+2)%3 end set[x]=0 set[y]=0 names[x]=names[f[i]].."+1" names[y]=names[f[i]].."+2"end
- local function rand()return math.random(3)-1 end set[rand]=0 names[rand]="rand"
- local last={}
- return function()
- local r=t[#t]
- local name="rand"
- if r then
- local mv,m=-math.huge,rand
- for f,v in pairs(set)do
- local a,b=last[f],r
- if a==(b+1)%3 then
- v=v+1 set[f]=v
- elseif a~=b then
- v=v-1 set[f]=v
- end
- if v>mv then m,mv=f,v end
- end
- ret=m()name=names[m]
- else
- ret=rand()
- end
- for f,v in pairs(set)do last[f]=f()end
- return ret
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement