Waffle3z

Match

Jun 26th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. return"Match",function(t,t2)
  2. local set,names={},{}
  3. local function cycle()return #t%3 end
  4. names[cycle]="cycle"
  5. local change do
  6. local last=math.random(3)-1
  7. change=function()
  8. last=(last+math.random(2))%3
  9. return last
  10. end
  11. end
  12. names[change]="change"
  13. local function beatlast()
  14. return #t==0 and math.random(3)-1 or(t[#t]+1)%3
  15. end
  16. names[beatlast]="beatlast"
  17. local winstay do
  18. local last=math.random(3)-1
  19. winstay=function()
  20. if #t~=0 and last~=(t[#t]+1)%3 then
  21. last=(last+math.random(2))%3
  22. end
  23. return last
  24. end
  25. end
  26. names[winstay]="winstay"
  27. local function hist()return #t==0 and math.random(3)-1 or(t[math.random(#t)]+1)%3 end
  28. names[hist]="hist"
  29. local function hist3()return #t==0 and math.random(3)-1 or(t[math.random(math.max(1,#t-3),#t)]+1)%3 end
  30. names[hist3]="hist3"
  31. local f={}for a,_ in pairs(names)do f[#f+1],set[a]=a,0 end
  32. 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
  33. 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
  34. local function rand()return math.random(3)-1 end set[rand]=0 names[rand]="rand"
  35. local last={}
  36. return function()
  37. local r=t[#t]
  38. local name="rand"
  39. if r then
  40. local mv,m=-math.huge,rand
  41. for f,v in pairs(set)do
  42. local a,b=last[f],r
  43. if a==(b+1)%3 then
  44. v=v+1 set[f]=v
  45. elseif a~=b then
  46. v=v-1 set[f]=v
  47. end
  48. if v>mv then m,mv=f,v end
  49. end
  50. ret=m()name=names[m]
  51. else
  52. ret=rand()
  53. end
  54. for f,v in pairs(set)do last[f]=f()end
  55. return ret
  56. end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment