Sometimes, your game makes use of a randomly generated sequence, but it would be nice to smooth out some of the short-term variance in it (e.g. long stretches of not getting a long piece in Tetris). This cart showcases some algorithms you can use to generate smoother-feeling random sequences, and lets you visualize them for tetrominoes, digits, or dice rolls.

Thanks to TetrisConcept without whom I would never have learned about these techniques, and to the developers who invented them.

See the code comments for more on the implementation of each randomizer.

This is really WAY over my head, DrPete. But checking your code I can see you are doing a vast number of ways to get random values, and to get them based on conditions, restrictions, and evictions. :)

If you're curious, you might use some line charts to graph out patterns found in your methods.

--makes a table from 0 to (to) function range(to) local array={} for i=1,to do array[i]=i-1 end return array end --returns a table with index (v) removed from table (t) function pop(t,v) local array={} local index=1 for i=1,#t-1 do if(i==v)then index+=1 end array[i]=t[index] index+=1 end return array end --settings local old=nil local size=10 --makes a table from 0 to (size) --pops out (old) from table --takes out a random element from table function randommemory() if(old==nil)then local take=flr(rnd(size)) old=take return take else local selectable=range(size) selectable=pop(selectable,old+1) local take=flr(rnd(#selectable)) old=selectable[take+1] return selectable[take+1] end end --takes one from 0 to (size) --if the value is equal to (old) then repeat function randomloop() while(true)do local take=flr(rnd(size)) if(take~=old)then old=take return take end end end --printing out for i=1,10 do print(randomloop()) end |

Left and above. Below and right doesn't really matter because it loops from top left to bottom right. It would matter if the cells were placed randomly in order. You would need to push **{x:-1,y:-1},{x:1,y:-1}** into **neighbourPositions** for diagonal checking.

That's pretty good.

It would be

(x==0 or scr[i-1]!=c) and scr[i-15]!=c and (y==0 or scr[i-16]!=c) and scr[i-17]!=c |

right? Or even shorter for diagonal checking?

[Please log in to post a comment]