You could do it something like that, but it introduces more problems than it solves:
fork() doesn't work on Windows. Even if it did, you would still need to set up some IPC to make things work right (that is, keep state, avoid excessive process loads and task switching, and I/O buffering, response time, and message configuration).
The simplest, and most common way to do it is to use DLLs. That's what they were designed for.
Windows provides protected memory accesses, so one DLL cannot easily gain access to another's process. Further, doing so would require source-code knowledge of the target DLL. Finally, a game will not function well if subprocesses don't behave (and try to disrupt their bretheren).
Another option, if you intend to have a "end-user programmable" AI, is to provide a basic language interpreter (embed Tcl or Python or somesuch), and execute each AI's code in a sandbox environment.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
Do you mean that I can send a value from a function written in one language to the main function written in another language using sockets? I'm new to the concept of sockets.
That's how the internet works -- its all done with sockets. Two programs running on the same or different computers can communicate with each other via sockets. And as explained by ssjarish it doesn't matter what computer language the programs are written in as long as that language supports sockets.
Ancient Dragon
Retired & Loving It
30,041 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
I didn't understand this, Duoas. Please would you elaborate a bit? Terms like basic language interpreter and sandbox environment are completely new to me.
For example, you could embed a Tcl interpreter in your program (TCL or Tool Command Language is a script language). Or, you could link a Python interpreter into your application.
In either case, you can extend the interpreted language itself to provide functionality specific to your application. Once done, the end-users could write their AI scripts in the embedded language (e.g. Tcl or Python), and your program will execute the end-user's code as needed.
The end-user's code would be a simple text file (just like all code files).
However, executing code you didn't write is a security concern, so you will need to implement the interpreter such that the end-user's code cannot do anything it shouldn't (like access files, or create sockets, etc.) Such an interpreter is said to exist in a sandbox --basically a controlled environment. Sand stays in; foreign material stays out.
Fortunately, this is very easy to do in Tcl and Python (and Scheme :-).
Socket programming is a pain in C/C++. If you were to embed Tcl or Python, you could use the embedded language's facilities to open and manage the socket. Both Tcl and Python make handling sockets trivial.
Whether you choose to do this or not you've got a lot of homework ahead of you. Good luck!
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229