BizHawk icon indicating copy to clipboard operation
BizHawk copied to clipboard

Python support?

Open twoATOMS opened this issue 6 years ago • 12 comments

tl;dr for future humans: There is no change to Python scripting support, it's still not planned. You have the choice of Lua scripting or compiling C# to CIL which you then add into EmuHawk dynamically. That said, the community have created ways to use Python scripting with a C# shim.

On the subject of ML specifically, don't bother with Lua, either use ML.NET, or exfiltrate the data to something like TensorFlow (Python). There are a few ML hackers in the ApiHawk Discord server if you're interested in the latest and greatest.

Original inquiry follows.


Hello guys, I have a question about the emulator. I am trying to learn Machine Learning and want to apply it to video games, however I only know Python2.7 as a programming language and I was wondering if BizHawk will ever have Python scripting support in the near future?

Thanks.

twoATOMS avatar Jul 15 '18 18:07 twoATOMS

Clearly not in the "near future". Dunno about "ever" - maybe?

vadosnaprimer avatar Jul 15 '18 18:07 vadosnaprimer

@twoATOMS You might want to check out Nintaco (http://nintaco.com/api.html). It provides programmatic control using C, C#, Java, Lua and Python.

spiiin avatar Jul 15 '18 19:07 spiiin

maybe first you may try Man Learning? maybe learn lua or something to begin with learning the machines lol

g0me3 avatar Jul 15 '18 19:07 g0me3

see also previous rejection of Python #707

YoshiRulz avatar Feb 04 '19 08:02 YoshiRulz

Right, recently we had a talk, and if someone makes a PR, we'll most likely accept it.

To actually throw something on the table, here's the approach that looks very promising: http://tasvideos.org/Feos/CallingCSharpMethodsFromPython.html You expose the methods from C#, have a C# Python interpreter, and then Python scripts just call those methods dynamically. Bonus points if it can be done using the newly updated APIHawk.

vadosnaprimer avatar Feb 04 '19 09:02 vadosnaprimer

It's not very hard to implement lua server, and connect to it from ANY language via sockets. Example for fceux emulator: https://github.com/spiiin/fceux_luaserver

spiiin avatar Feb 04 '19 09:02 spiiin

Yeah, this dynamic approach should also allow any language with C# bindings to use those functions.

vadosnaprimer avatar Feb 04 '19 10:02 vadosnaprimer

Clarification, the PythonNET module is a module for the python interpreter which allows for calling dynamic-exposed objects in C#.

Which means that in theory, you should be able to use any interpreter you want, as long as the interpreter can load aforementioned module.

Warepire avatar Feb 04 '19 17:02 Warepire

+1 on Python websocket support for Machine Learning. Then with Dockerfile will be great! I will make an article for building this. Can anyone here guide me through this?

elcolie avatar Feb 04 '20 17:02 elcolie

Several people have suggested and ML project using BizHawk, so I'm writing this out to save repeating myself: The easiest way to get memory access and playback controls is with an external tool. You could use Lua to bridge to another process, but it'll be slower. External tools need to be in C# (or, maybe, F# or VB). The library you'll use will probably be ML.NET what with Microsoft throwing money at it. For completeness, you could use C# instead of Lua to bridge to another process. ~~I imagine that even calling into C from C# would be slower than a pure C# solution.~~ edit: Less sure about this, especially if you're running under Mono.

I'm personally willing to help anyone with the implementation of an external tool (I don't know much about ML, sorry). So, @elcolie, if you know that it's going to be annoying and still want to try, I'm on IRC and Matrix.

YoshiRulz avatar Feb 04 '20 18:02 YoshiRulz

Thank you @YoshiRulz I will learn the material and when I am ready I will contact you 🙏

elcolie avatar Feb 05 '20 03:02 elcolie

Time to be annoying and necro a thread: https://github.com/magnusjjj/FakeControllerDesu

Rudimentary python support, at least for the restart function ;). I am looking for testers, to make sure that it's reasonably stable for other people to, well, I guess toy with.

magnusjjj avatar Jul 22 '21 19:07 magnusjjj