2

Cart #30419 | 2016-10-09 | Code ▽ | License: CC4-BY-NC-SA
2

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.

P#30420 2016-10-09 11:17 ( Edited 2016-10-10 14:17)

Reminds a bit of my sketch on Khan Academy here.

P#30426 2016-10-09 12:12 ( Edited 2016-10-09 16:12)

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.

P#30430 2016-10-09 12:40 ( Edited 2016-10-09 16:40)
 ``` --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 ```
P#30438 2016-10-09 13:07 ( Edited 2016-10-09 17:15)

Anastasia, I am looking at your link. Are you just wanting to plot colored dots where no colored dot matches the one next to it either above, below, left, or right ?

P#30440 2016-10-09 13:26 ( Edited 2016-10-09 17:26)

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.

P#30441 2016-10-09 13:29 ( Edited 2016-10-10 13:58)

This is not that difficult a task I think. Lemme take a crack at it. :)

Cart #30505 | 2016-10-10 | Code ▽ | No License

17-lines of code or 87 tokens.
I can add diagonal checking too if you like ...

P#30464 2016-10-09 17:00 ( Edited 2016-10-10 03:16)

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?

P#30527 2016-10-10 10:02 ( Edited 2016-10-10 14:04)

Hmm ... I think that's missing something ... Yes, you need scr[i-17]!=c as well.

Here is the update, now checks for all diagonals and will not choose matching colors if they do.

Cart #30528 | 2016-10-10 | Code ▽ | No License

P#30529 2016-10-10 10:17 ( Edited 2016-10-10 14:18)