Tetris Randomizer?

Started by Shuey, November 17, 2011, 12:25:10 PM

Previous topic - Next topic

Shuey

I'm doing some studies on Perfect Clears and would like to find out if there is a randomizer that I can "tap into" or use to analyze pieces/piece sequences.  Obviously I'm going to want to use one that randomizes the pieces "properly" (what is it called... "bag 7"?).  My plan is to analyze at least 1 million pieces (or possibly 1 million 10 piece sequences (bag 7 + 3)).

Any help is appreciated - Thanks in advance!

Sisu

#1
inb4 Zircean

Pineapple

Well, since I'm not Zircean, and he seems to not be around right now, let's have some fun here, shall we?

Zircean and I have several randomizers implemented (including some that have never been included in an actual game, but have interesting theoretical properties, and a few that are just plain evil) in code form that output to a text file, with one character per piece, and blank lines between each sequence. It's a fairly trivial adjustment to have them output a large number of sequences of a specific length.

It's worth noting at this point, though, that if you're going to stick to just the Random Generator (the randomizer that guideline games use), then there are only 1058400 sequences of 10 pieces that can appear at the start of a game (and since you'll probably want to be thinking about hold as well, then that only becomes 4233600). We could probably also write something that enumerates all of these, as well.

Also... if you come up with anything sort of analysis method that would be useful, we would be interested in hearing it.
It is only when you open your mind, that you will be able to see how beautiful the world is...

Shuey

Thanks for the reply Pineapple!  I don't know code or how to program, but a friend of mine is getting interested in this and wants to help me.  Here is what he said that led to the randomizer thread (keep in mind that his knowledge and background is very limited compared to ours when it comes to Tetris):

I can help you determine the algorithm. Here is a basic plan:
1) Collect 1,000,009 consecutive pieces output from a tetris randomizer. This would allow us to analyze 10-bag sequences.
2) Store every sequence in a tree data structure. This is a classic CS problem and interesting to work on.
3) Write some scripts to analyze the leaf nodes of the tree.
4) Add a UI on top of the scripts.
Basically this would allow you to:
1) View every valid sequence of 10 pieces
2) View the probability of any sequence appearing
3) Bonus: View the probability of any sub-sequence occurring (e.g. OOSL or IIJ)
The only hard part would be finding a randomizer with either open source code, or some black-box interface. We might be able to decompile a flash game to achieve this.


Thanks again to anyone/everyone who is willing to help with this!

XaeL

#4
if you want the bag 7 randmoizer its like 5 lines long.........

do u want output in 10's or 7's?




#include <iostream>
#include <cstdlib>
using namespace std;
char printChar (int i) {
  if (i == 0) {
    return 'I';
  } else if (i == 1) {
    return 'O';
  } else if (i == 2) {
    return 'J';
  } else if (i == 3) {
    return 'L';
  } else if (i == 4) {
    return 'S';
  } else if (i == 5) {
    return 'T';  
  } else if (i == 6) {
    return 'Z';
  }
}

void genBag () {

  bool appeared[7] = {false, false, false, false, false, false, false};

  for (int i = 0; i < 7; ++i) {
    int secret = rand() % 7;
    while (appeared[secret] == true) {
      secret--;    
      if (secret < 0) secret = 6;
    }
    appeared[secret] = true;
    cout << printChar(secret);
    
  }
  cout << endl;

}


int main() {
  srand ( time(NULL) );
  
  for (int i = 0; i < 1000000; i++)
    genBag();
    
  
  
  return 0;


}


sample output....

[spoiler]
LZTIOSJ
JOSZITL
SJOTLIZ
LOJIZTS
ZSJOITL
JSLOZIT
IZLJOTS
TSJOZIL
ZTSLOJI
JTSLOIZ
ZSITJOL
JSTIOZL
TLSJIOZ
OLTJISZ
JIOZTSL
TJSILOZ
TLSJOIZ
SOTLJIZ
LIJOZST
OTIZSLJ
JZLTOIS
TZSOLJI
ZTJISLO
LJOSTIZ
LZTSJIO
SJLOZIT
LJSIZOT
LJOIZTS
IJSLOZT
SOLIJZT
OZIJTLS
ZOSJITL
LJTOSIZ
LJTZSOI
ZITSLJO
LISJZTO
ISLJZOT
JOLSIZT
ZITSLJO
SILZTJO
LZJOIST
JTIOSZL
[/spoiler]



QuoteLike many setups here, it is useful if your opponent doesn't move and you get 4 Ts in a row.

Shuey

Awesome, thanks XaeL!

I'd like the output in 10's.  I thought about trying to modify the code myself, but I'd probably jack it up, lol.

XaeL

#6
Quote from: Shuey
Awesome, thanks XaeL!

I'd like the output in 10's.  I thought about trying to modify the code myself, but I'd probably jack it up, lol.
ok now i have to modify the code.....


you have a c++ compiler right?

#include <iostream>
#include <cstdlib>
using namespace std;
char printChar (int i) {
  if (i == 0) {
    return 'I';
  } else if (i == 1) {
    return 'O';
  } else if (i == 2) {
    return 'J';
  } else if (i == 3) {
    return 'L';
  } else if (i == 4) {
    return 'S';
  } else if (i == 5) {
    return 'T';  
  } else if (i == 6) {
    return 'Z';
  }
}

void genBag () {
  static int newline = 0;
  bool appeared[7] = {false, false, false, false, false, false, false};

  for (int i = 0; i < 7; ++i) {
    int secret = rand() % 7;
    while (appeared[secret] == true) {
      secret--;    
      if (secret < 0) secret = 6;
    }
    appeared[secret] = true;
    cout << printChar(secret);
    newline++;
    if (newline%10==0) cout << endl;
    
  }
  

}


int main() {
  srand ( time(NULL) );
  
  for (int i = 0; i < 1000000; i++)
    genBag();
    
  
  
  return 0;


}


NB: the code style i am using is very hacky but its a quick, somewhat fast implementation.



QuoteLike many setups here, it is useful if your opponent doesn't move and you get 4 Ts in a row.

Shuey

LOL, first you act snide and say "it's like 5 lines" and you whip it out like nothing.  I then answer your question and now you act like it's going to take you a year to make it output in 10's, LOL?

I personally don't have a compiler, but I'm not the coder... the guy who's going to be helping me (when he eventually replies back) is the guy who codes.

XaeL

#8
wha tare u talking about.. i whipped up the printing out in 10s in 30 seconds.... i chagned 2 lines..

if u dont have a compiler u can use either this:

http://codepad.org/CC3zLvDW - this only outputs for x seconds so it times out.

or you can ask me to output and send u a text file.. 1 million bags is like 8 mb and takes 4-5 seocnds to generate.



QuoteLike many setups here, it is useful if your opponent doesn't move and you get 4 Ts in a row.

Shuey

Awesome, yeah man, I still haven't heard back from the other dude yet, so if you're able to send me 1 million bags, that will save me another step in the process.  Thanks a lot for your help, I really appreciate it!

Wait.... are you sure your randomizer is setup properly?  When I collected data from TF Marathon, I had more than one instance where there were two pieces spawned one after another (ex: two T's in a row)... your spoiler output doesn't seem to ever do this...

coolmaninsano

[!--quoteo--][div class=\\\'quotetop\\\']QUOTE[/div][div class=\\\'quotemain\\\'][!--quotec--]15 | JZLSTOIIJO[/quote]


vipjun

you can also doubleclick sequencer.bat in your nullpo folder

set sequence length to 1000000000000000009 choose 7bag randomizer and get the file.


farter

Quote from: vipjun
1000000000000000009