This is a fairly problematic idea for a variety of reasons. Those reasons have been discussed in detail elsewhere (some relevant comments can be found here), so instead of reviewing the usual issues yet again, I'd instead like to pose an interesting question for discussion:Suppose you've played partway through a battle and want to redo a turn. Is it possible to construct a battle that plays exactly the same up to that point, but which then goes differently on the next turn?

Obviously this problem isn't fully specified, but my point is that it's not clear whether the answer is "yes"; it may be "yes" sometimes and "no" other times. The in-game random number generator ("RNG") has a period of only 2**32. In order for it to be possible to "replay" the battle such that it is the same up to that point, but different on the next turn, you would have to locate in the output of the RNG a sequence of numbers that gives the same result as the original battle up until the critical turn, and then a different result on the next turn.

So, how feasible is this really? For some average length battle, does there *really* exist another battle that is exactly the same up until the critical turn that you want to replay and is then different on the next turn?

Let's suppose you're 50 turns into a battle, and then on the 51st turn there's some undesirable "hax" and you and your opponent decide you'd like to replay it -- i.e. you'd like to construct a new battle that plays the same for the first 50 turns, but then differently on the 51st turn. We'll make a conservative assumption that each turn generated 6 random numbers -- so we have a sequence of 300 random numbers that we need to locate in another position in the output of the RNG such that the next number is different from the original battle. What is the chance that such an alternative reality battle actually exists in the output of the RNG?

Now, you might say that the sequence of numbers doesn't need to be *exactly* the same, so long as it gives the same observable results -- and that's correct. To model that, we'll say that rather than the sequence needing to match exactly, only the lowest byte need to match from each pair of corresponding entries in the two sequences being compared.

Here's a program I wrote to solve this problem by brute force:

rng.js (brute force solution) (open)
rng.js (brute force solution) (close)

Code:

var rng = {
seed: 0,
advance: function() {
this.seed = (this.seed * 0x41C64E6D + 0x6073) >>> 0;
return this.seed >>> 16;
}
};
function randomSeed() {
return Math.floor(Math.random() * 0xFFFFFFFF);
}
function isObservableMatch(v1, v2) {
// only the lowest byte needs to match...
return ((v1 % 8) === (v2 % 8));
}
function isReplayable(rng, seed, length) {
rng.seed = seed;
var sequence = [];
for (var i = 0; i < length; ++i) {
sequence.push(rng.advance());
}
var last = rng.advance(); // the turn that we want to replay
for (var i = 0; i < 10000000; ++i) {
var nextseed = randomSeed();
if (nextseed === seed) continue; // don't try the original seed
rng.seed = nextseed;
var matches = true;
for (var j = 0; j < length; ++j) {
if (!isObservableMatch(sequence[j], rng.advance())) {
matches = false;
break;
}
}
if (matches) {
// the battle matches so far, but we still need to make sure the
// last turn is different from the old battle!
var advance = rng.advance();
if (!isObservableMatch(last, advance)) {
console.log('last = ' + last + ', advance = ' + advance);
return true;
}
}
}
return false;
}
(function(rng) {
var total = 1000;
var replayable = 0;
for (var i = 0; i < total; ++i) {
if (isReplayable(rng, randomSeed(), 300)) {
++replayable;
}
console.log(replayable + '/' + (i + 1) + ' (' + Math.round(replayable / (i + 1) * 1000) / 10 + '%) were replayable');
}
})(rng);

For each "battle", instead of searching the entire RNG space, I searched a random subset thereof consisting of 10,000,000 sequences of 300 values each, each starting from a random initial seed. This should be representative of the actual value.

I tested 100 random battles and the output was:0/100 (0%) were replayable

Redoing the experiment with a sequence length of only 20 (instead of 300) gives a nonzero "replayability" ratio, but it's very small: out of 100 battles tested, only 5 were replayable. These correspond to battles of no more than 5 turns each.

In other words, under my extremely generous assumptions, there's little to no chance that there actually exists an alternative reality battle in which the first set of turns played the same as the original battle, and then things go differently on the next turn. With less conservative assumptions, the chance is even lower.

So, one fatal flaw with your idea is that most of the time, once a battle has been underway for some time, it's actually impossible to "replay" the most recent turn and get a different result, because there does not exist a battle that is the same up to that point and then different afterward.