TGM randomizer: Difference between revisions

From TetrisWiki
Jump to navigation Jump to search
*>Tepples
→‎Pseudocode: numTries is an argument
MattMayuga (talk | contribs)
No edit summary
 
(15 intermediate revisions by 11 users not shown)
Line 1: Line 1:
Most games in [[TGM series|Arika's ''Tetris The Grand Master'' series]] randomize the order of [[tetromino]]es using an algorithm that makes successive identical tetrominoes less common. It involves keeping a history of the four most recent tetrominoes and trying to choose a random tetromino not in the history. It "rolls the dice" a given number of times and takes the first tetromino that doesn't match any in the history. TGM1 uses 4 tries; subsequent games using the TGM randomizer use 6 tries.
Most games in [[TGM series|Arika's ''Tetris The Grand Master'' series]] randomize the order of [[tetromino]]es using an algorithm that makes successive identical tetrominoes less common. The system involves keeping a history of the four most recent tetrominoes and trying to choose a random tetromino not in the history. Each time a piece is generated, the game will try a certain number of times to generate a tetromino that doesn't match any in the history; if all tries fail and generate a recent piece, the game will settle with that recent piece. The overall effect is to minimize several of the same tetromino showing up in succession, while maintaining a certain amount of unpredictability. ''[[TGM1]]'' uses 4 tries, while later games use 6 tries.


The history is not a unique list. If the randomizer fails to generate a unique tetromino, which happens about 3.5 percent of the time in a 6-try system, then two or more of one tetromino may occupy elements of the history.
The four-piece history is not necessarily a unique list. If the randomizer fails to generate a non-recent tetromino, which happens about 3.5 percent of the time in a 6-try system, then two or more of the same tetromino may occupy elements of the history.


A few additional behaviors exist in the beginning of the game.
A few additional behaviors exist in the beginning of the game:
*The game never deals an S, Z or O as the first piece.
*The game never deals an S, Z or O as the first piece, to avoid a forced overhang.
*The state of the history is initialized to a fixed state:
*The state of the history is initialized to a fixed state:
**In TGM1, the history begins filled with 4 Z pieces.
**In TGM1, the history begins filled with 4 Z pieces.
**In TGM2, the history begins with a Z,S,Z,S sequence.
**In TGM2 (and TGM2+), the history begins with a Z,Z,S,S sequence. However, as the first piece of the game overwrites the first Z rather than pushing off the last S, this is effectively a Z,S,S,Z or Z,S,Z,S sequence.


== Pseudocode ==
''[[Tetris The Grand Master Ace]]'' uses the "7-bag" [[Random Generator]] algorithm to comply with the Tetris guideline, but slightly modified so that it also never deals an S, Z or O as the first piece.
:Function tgmRandomize(''history'' as list of 4 pieces by reference, ''numTries'' as integer by value) as piece:
 
::For ''try'' = 1 to numTries:
== [[Tetris The Grand Master 3 Terror-Instinct]] ==
:::''candidatePiece'' = random element of set {I, J, L, O, S, T, Z}
Unlike ''TGM1'' and ''TA'' (''P''), ''Ti'' uses a [[bag]] of 35 pieces to draw from rather than drawing uniformly randomly from the seven pieces (while performing history checking). The bag initially contains 5 of each piece. However, unlike a true bag (which slowly empties with each drawn piece before being completely refilled), ''Ti'''s random generator puts a copy of the least recent piece back into the bag each time a piece is taken out. While the TGM randomizer naturally prevents "floods" (many of the same piece in a row), this additional behavior has the effect of preventing "droughts" (where a certain piece fails to show up for a long time). At an extreme, it is impossible for any piece to fail to appear for longer than a 35-piece sequence.
:::If ''candidatePiece'' is not in ''history'':
 
::::Exit loop
This is not a perfect description of ''Ti'''s randomizer; for full elaboration including some subtle bugs in the algorithm, see the reference link below.
::Move all tetrominoes in ''history'' back by one position
::Put ''candidatePiece'' at front of ''history''
::Return ''candidatePiece''


== References ==
== References ==
*[http://www.tetrisconcept.com/forum/viewtopic.php?p=2038#2038 colour_thief's description of the TGM randomizer]
*[https://web.archive.org/web/20151107011715/http://tetrisconcept.net/wiki/User:Zzymyn#Random-Number_Generator Disassembly of the TAP randomizer]
 
*[http://tetrisconcept.net/threads/randomizer-theory.512/page-9#post-55478 Ti randomizer explanation]
**[https://tetrisconcept.net/threads/randomizer-theory.512/page-12#post-65418 Ti randomizer commented C code] including cause of bug
 
{{Arika games}}
 
[[Category:Randomizers]]

Latest revision as of 14:05, 11 November 2020

Most games in Arika's Tetris The Grand Master series randomize the order of tetrominoes using an algorithm that makes successive identical tetrominoes less common. The system involves keeping a history of the four most recent tetrominoes and trying to choose a random tetromino not in the history. Each time a piece is generated, the game will try a certain number of times to generate a tetromino that doesn't match any in the history; if all tries fail and generate a recent piece, the game will settle with that recent piece. The overall effect is to minimize several of the same tetromino showing up in succession, while maintaining a certain amount of unpredictability. TGM1 uses 4 tries, while later games use 6 tries.

The four-piece history is not necessarily a unique list. If the randomizer fails to generate a non-recent tetromino, which happens about 3.5 percent of the time in a 6-try system, then two or more of the same tetromino may occupy elements of the history.

A few additional behaviors exist in the beginning of the game:

  • The game never deals an S, Z or O as the first piece, to avoid a forced overhang.
  • The state of the history is initialized to a fixed state:
    • In TGM1, the history begins filled with 4 Z pieces.
    • In TGM2 (and TGM2+), the history begins with a Z,Z,S,S sequence. However, as the first piece of the game overwrites the first Z rather than pushing off the last S, this is effectively a Z,S,S,Z or Z,S,Z,S sequence.

Tetris The Grand Master Ace uses the "7-bag" Random Generator algorithm to comply with the Tetris guideline, but slightly modified so that it also never deals an S, Z or O as the first piece.

Tetris The Grand Master 3 Terror-Instinct

Unlike TGM1 and TA (P), Ti uses a bag of 35 pieces to draw from rather than drawing uniformly randomly from the seven pieces (while performing history checking). The bag initially contains 5 of each piece. However, unlike a true bag (which slowly empties with each drawn piece before being completely refilled), Ti's random generator puts a copy of the least recent piece back into the bag each time a piece is taken out. While the TGM randomizer naturally prevents "floods" (many of the same piece in a row), this additional behavior has the effect of preventing "droughts" (where a certain piece fails to show up for a long time). At an extreme, it is impossible for any piece to fail to appear for longer than a 35-piece sequence.

This is not a perfect description of Ti's randomizer; for full elaboration including some subtle bugs in the algorithm, see the reference link below.

References