Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy Stream #10886

Open
lucassunalt opened this issue Feb 12, 2025 · 0 comments
Open

Copy Stream #10886

lucassunalt opened this issue Feb 12, 2025 · 0 comments

Comments

@lucassunalt
Copy link

lucassunalt commented Feb 12, 2025

Is it possible to copy a stream such that the new stream can be interacted with as if it were an initial state? Code:

stream.write(>start {"formatid":"gen9randombattle"});
stream.write(>player p1 {"name":"Player 1"});
stream.write(>player p2 {"name":"Player 2"});

function randomGame(stream, depth){
const streams = PS.getPlayerStreams(stream);

omniscient = streams.omniscient;
spectator = streams.spectator;
p1 = streams.p1;
p2 = streams.p2;
p3 = streams.p3;
p4 = streams.p4;

const logging = (depth == 0);
const p1bot = new RandomBattlePlayer(p1, logging);
const p2bot = new RandomBattlePlayer(p2, logging);

void p1bot.start();
void p2bot.start();

void (async () => {
    for await (const chunk of omniscient) {
        var lastmessage = chunk.split('|');
        if (lastmessage.slice(-2, -1) == 'win' && logging){
            console.log(lastmessage.slice(-2, -1) + ' ' + lastmessage.slice(-1));
            return lastmessage.slice(-1);
        }
    }
})();

}

// Somehow copy stream 2 so that the battle states are the same, but different RNG seed.

winner = randomGame(stream, 0);
winner2 = randomGame(stream2, 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant