Is there a Js program that compiles python code and turns it into a js file?

In the world of chess, there is an open-sourced python code called stockfish, and I have heard that it could be compiled into js. I would like to do this from scratch. A javascript compiler is what I need. Is that possible and how do I do it

Hey Michael! :slight_smile: How are you doing?

I am not sure I understand what you’re looking for exactly, but I’m curious.

A javascript compiler is what I need

JS in not a compiled language :confused:

But maybe you want to migrate a codebase (?), in this case migrating means porting some code written in the language A to the language B. This can be done by yourself from scratch by learning both languages and then simply writing logics that do the same thing in the two different language syntaxes.

Example:
This program in language-A loops through a given array and prints all of the array elements. I can do the same in the language-B but the syntax for the loop is different, now I can use both, passing an array to either the first or the second, it may depend from which is faster for example. :wink:

Does this answer your question? :slight_smile:

Your example shows the start and goal for my project. say I want to say

console.log('Hello, World!');

but it is first written in python like this:

print('Hello, World!')

In this case is simple, but stockfish has thousands of lines of code that are in python. My goal is to not translate line-by-line to javascript and let the javascript do that.

also I’m doing good

py2js does Python to javascript translation:

But when looking at the stockfish sourcecode, it is all written in C++:

1 Like

Oh shoot yes sorry meant c++

Anyone correct me if i am mistaken, but i don’t think a “human readable” source code translation from C++ to javascript is possible.

Emscripten seems to be usable to convert C++ to asm.js:

But looking into the resulting file, you may wonder if this is even javascript.

What is your goal with this translation? Maybe there is an easier way than translating.

also I’m doing good

Great! :slight_smile:

My goal is to not translate line-by-line to javascript and let the javascript do that.

Try to search the web for: “transpile language-A to language-B”, maybe someone created something similar, some git repo project or something. But would you trust that?

I’m trying to encode a chess bot into a chess game that is on a website. pretty difficult idea of mine, but It should be easy once I get stockfish.cpp into stockfish.js

You may want to have a look at this project:

Seems like you can run this in your backend using nodejs, or within the clients browser.

1 Like

omg literally just found stockfish.js on the web

:face_with_symbols_over_mouth:

well, we can still have this up so that if anybody else needs to know how to compile lang_a to lang_b, they can find it here

haha xD

I’m trying to encode a chess bot into a chess game that is on a website

Just throwing around some ideas: store the c++ script on your server, call it with a request to make the necessary permutations for the current state of the chessboard (read it from database), select the best move, update the database with the current move, update the chessboard on the website with the current move.

Does this make any sense?

If you play chess we can play together a game! :stuck_out_tongue:

If you play chess we can play together a game! :stuck_out_tongue:

No thanks but I do play chess. Also thank you for your solution: it is the winner.
I’ll try this soon, I still gotta wrap my head around all of this stockfish, cpp, js, apis, etc. that I need to use

1 Like

In case you can share your code/progress, consider posting your repository in the Personal Projects Section of the Forum.

I for sure would like to see how the progress goes.

I will make sure to do so: for now though I will take a break.

Haha thank you but I feel it’s unfair to @riumequa

Let us know how it goes anyhow :slight_smile: