Other Where to find more information on running the battle simulator from within a non-node.js language?

Hi, I am interested in writing a C# application that wraps some functionality of the battle simulator. On the simulator's readme page it states this:

The stream can be accessed from other programming languages using standard IO:

echo '>start {"formatid":"gen7randombattle"}
>player p1 {"name":"Alice"}
>player p2 {"name":"Bob"}
' | ./pokemon-showdown simulate-battle


But I'm not quite sure exactly how to go about connecting my C# application to the talk to the simulator in this way. Is there any more detailed information on how to do this? Thanks in advance.
 
Thanks- I'm not sure where the PS section is. I looked through the different forum categories but I'm not seeing anything like that. Do you happen to have a link?
 

pre

pkmn.cc
The stream can be accessed from other programming languages using standard IO:
Console.In.ReadLine and Console.Out.WriteLine. The one trick is that to both read and write from the pipe you'll need to give it a name on most systems.

Code:
mkfifo pipe
c_sharp_program < pipe | ./pokemon-showdown simulate-battle > pipe
 
Console.In.ReadLine and Console.Out.WriteLine. The one trick is that to both read and write from the pipe you'll need to give it a name on most systems.

Code:
mkfifo pipe
c_sharp_program < pipe | ./pokemon-showdown simulate-battle > pipe
Thanks! But I'm actually hoping to do this on windows, not linux. Any thoughts on how I might do that?
 
This is helpful, but I'm struggling to see how I can actually launch both my C# application and pokemon showdown and have them talk to eachother through this, like you did with your linux script. Would I need to do that in something like a batch script on windows? I've been googling potential methods without much luck. It doesn't seem possible to create a named pipe in batch. I know how to create a named pipe from the C# side, but then I don't know how to connect the pokemon showdown / node.js side. Any advice would be greatly appreciated.
 

Zarel

Not a Yuyuko fan
is a Site Content Manageris a Battle Simulator Administratoris a Programmeris a Pokemon Researcheris an Administrator
Creator of PS
I think it's a bad idea to launch them both and then connect them by the commandline. It's much easier to have the C# program launch PS as a subprocess.

Here's an article I found on Google for how to do that:

https://www.technical-recipes.com/2016/how-to-run-processes-and-obtain-the-output-in-c/

FileName would be the path to pokemon-showdown, and Arguments would be "simulate-battle".

(edit: on second thought, on Windows, FileName might have to be the path to Node.js, and then Arguments would have to be the path to pokemon-showdown followed by " simulate-battle")

Then you can send messages to PS with process.StandardInput.WriteLine() and read its output with process.StandardOutput.ReadLine().
 
I think it's a bad idea to launch them both and then connect them by the commandline. It's much easier to have the C# program launch PS as a subprocess.

Here's an article I found on Google for how to do that:

https://www.technical-recipes.com/2016/how-to-run-processes-and-obtain-the-output-in-c/

FileName would be the path to pokemon-showdown, and Arguments would be "simulate-battle".

(edit: on second thought, on Windows, FileName might have to be the path to Node.js, and then Arguments would have to be the path to pokemon-showdown followed by " simulate-battle")

Then you can send messages to PS with process.StandardInput.WriteLine() and read its output with process.StandardOutput.ReadLine().
Thanks so much! This totally worked. And your edit was correct, that's exactly how it works. Much appreciated!
 
Thanks so much! This totally worked. And your edit was correct, that's exactly how it works. Much appreciated!
Did you develop your app further? I have the simulator running on a separate thread right now but cannot for the life of me figure out reading the output, since it's going to stdout it seems like I can only read from there once. I'd like to be able to leave the simulator open and send commands and get responses whenever I please but doesn't seem to be working, the simulator thread will hang when I try to ReadLine().

The response to here is what I currently have: https://stackoverflow.com/questions...out-from-process-in-c-accessing-multiple-time

Have also been trying just to run this in js but can't seem to get constant reading / writing to the process to work, something like this will not give me any output (this also may be a misunderstanding of js which I don't really use :P ):

JavaScript:
const prompt = require('prompt-sync')();
const Sim = require('pokemon-showdown');
stream = new Sim.BattleStream();

(async () => {
    for await (const output of stream) {
        console.log(output);
    }
})();

stream.write(`>start {"formatid":"gen5randombattle"}`);
stream.write(`>player p1 {"name":"OGSuperSand"}`);
stream.write(`>player p2 {"name":"SpyIsPie"}`);


while (true) {
    var msg = prompt();
    stream.write(msg);
}
 
Did you develop your app further? I have the simulator running on a separate thread right now but cannot for the life of me figure out reading the output, since it's going to stdout it seems like I can only read from there once. I'd like to be able to leave the simulator open and send commands and get responses whenever I please but doesn't seem to be working, the simulator thread will hang when I try to ReadLine().

The response to here is what I currently have: https://stackoverflow.com/questions...out-from-process-in-c-accessing-multiple-time

Have also been trying just to run this in js but can't seem to get constant reading / writing to the process to work, something like this will not give me any output (this also may be a misunderstanding of js which I don't really use :P ):

JavaScript:
const prompt = require('prompt-sync')();
const Sim = require('pokemon-showdown');
stream = new Sim.BattleStream();

(async () => {
    for await (const output of stream) {
        console.log(output);
    }
})();

stream.write(`>start {"formatid":"gen5randombattle"}`);
stream.write(`>player p1 {"name":"OGSuperSand"}`);
stream.write(`>player p2 {"name":"SpyIsPie"}`);


while (true) {
    var msg = prompt();
    stream.write(msg);
}
Actually, seems to be working with:

JavaScript:
const readline = require('readline');
const Sim = require('pokemon-showdown');
stream = new Sim.BattleStream();

(async () => {
    for await (const output of stream) {
        console.log(output);
    }
})();

stream.write(`>start {"formatid":"gen5randombattle"}`);
stream.write(`>player p1 {"name":"OGSuperSand"}`);
stream.write(`>player p2 {"name":"SpyIsPie"}`);

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

rl.setPrompt("");
rl.prompt();
rl.on("line", function(message) {
    stream.write(message);
    rl.prompt();
}).on("close", function() {
    console.log("\nSee ya!\n");
    process.exit(0);
});
Just a bit unfortunate as cannot find a similar way to do this with C# due to stdin / stdout shenanigans.
 

Users Who Are Viewing This Thread (Users: 1, Guests: 0)

Top