9

The Classic Tetris World Championship uses original NES consoles that are modded to provide the same RNG for both players:

Players WILL have the same RNG

I am wondering how this was done. So, my question is two-fold:

  1. What random seed is used by the NES?
  2. How can this seed be manipulated?
Jaap Joris Vens
  • 1,016
  • 6
  • 18
  • You might want to ask this on Arquade.SE. – Raffzahn Dec 22 '20 at 22:28
  • 4
    Since this question pertains to a computing aspect of a particular retro console, rather than a gaming aspect, this site seemed more appropriate. – Jaap Joris Vens Dec 22 '20 at 22:36
  • 4
    @Raffzahn I think it's be on-topic on both sites. It's about a modern gaming competition, but also about contemporary use of retro hardware. The specific “how was it done in this modern instance” might make it off-topic here, I suppose; is that the main issue? – wizzwizz4 Dec 22 '20 at 22:55
  • @wizzwizz4 That and that I assume the audience over there might be way more familiar with the details of this modern setup. Chances of a valid answer are simply higher over there as the core is about the use applied in this competition - the gaming aspect. – Raffzahn Dec 22 '20 at 23:36
  • 1
    The rule is "Players WILL have the same RNG", not "Players WILL have the same RNG that is set to the starting condition". But that doesn't make sense based on what you observed. Thus, I really think this would be better answered at gaming.SE since they know more about how these tournaments are run. – RonJohn Dec 23 '20 at 06:29
  • I can't speak specifically for this system, hence a comment, but it was normal to seed the generator with a negative number to produce a known sequence of random numbers. – Chenmunka Dec 23 '20 at 10:24
  • Related: https://retrocomputing.stackexchange.com/questions/2244/how-was-early-randomness-generated – Jaap Joris Vens Dec 23 '20 at 11:07
  • 1
    According to this comment and this one on Reddit, CTWC uses a modified cartridge with significantly different piece generation code. (They modify it on the fly, Game Genie style, to avoid problems with copyright.) I'm not sure that answers your general question though. – benrg Dec 23 '20 at 23:38
  • 1
    There is a difference between systems with hardware RNG support (e.g. Atari POKEY) and those without. Identifying the nature of pseudo-randomness on the NES seems appropriate to RC. – fadden Dec 24 '20 at 15:48
  • Yeah, there is no "the NES RNG" and therefore no literal answer to this question. I assume an answer about the software RNG implemented specifically by whatever NES version of Tetris is in use would be acceptable? – Tommy Feb 10 '21 at 17:30
  • There is a deleted answer to this question that seems to answer it perfectly. – knol Feb 10 '21 at 18:05

1 Answers1

8

Community Wiki, as it's unclear to me why @JaapJorisVens deleted his answer given that it appears to contain the necessary clues:

The carts are special carts we have made that contain 1000 selectable games. It is worth mentioning that the carts are actually adapters - essentially Game Genies - which do nothing unless you have an original NES Tetris cart plugged in.

Each of the 1000 games corresponds to a unique random seed which initializes the RNG for each game. The seed is iterated once per piece to produce the sequence. ...

Part of the RNG algorithm in the cart makes use of fairly large tables ... Each year we shuffle the contents of these tables to make a new cart.

So:

  • the original Tetris is used;
  • a competition-specific cartridge acts as a passthrough to replace Tetris's random number generator; and
  • specifically, that passthrough device spots when Tetris is performing its new-piece sequence and at that point inserts the next random number.

The NES itself doesn't inherently generate random numbers, that's a per-game process, implemented however each game sees fit. For the purposes of this competition they've engineered an intermediary that substitutes its own random numbers, generating them exactly on-demand.

Per other parts of Jaap's answer:

The math involved in 'iterating' the seed is fairly detailed, involving a LFSR (as is used in the standard NES cart), a few looping counters, and some lookup tables. Just before each game, a random number between 0 and 999 is chosen and players are told which game to select on the cart. After a game is played, it is never re-played.

So both the new implementation and the original are linear feedback shift registers ('LFSR's), which are shift registers in which the bit going out is exclusive-ORd onto some other combination of bits in the current state. Through that means an n-bit register can iterate through 2n − 1 states in a fixed sequence that is sufficiently oblique that a human might interpret it as random.

That said, it sounds like the passthrough device goes further in using the LFSR to index random number tables, so it's likely that the LFSR is being used just because it's easier to throw together than a classic ripple counter.

Quite probably the original just uses the output of its software LFSR directly.

user3840170
  • 23,072
  • 4
  • 91
  • 150
Tommy
  • 36,843
  • 2
  • 124
  • 171