954,136 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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
 

I had a problem which is something similar to what you are having, on how to interface the AI routine with my Code. But in my case the AI reasoning part part was done LISP. So for example if an Agent wanted to move from a point A to Point B there could be different path, which basically depends upon environment.

The LISP routine would normally find the path for me, the output of that function (Which is nothing out the path) will be sent to my C code using sockets.

You could use sockets to communicate between routines if your wanted. Which makes it more simple, some thing similar to RPC or RPCgen which you are requesting for a routine to be called on the server and the output of that function would directed to the client to the client.

Some alternative for you

ssharish

ssharish2005
Posting Whiz in Training
253 posts since Dec 2006
Reputation Points: 73
Solved Threads: 20
 

@Duoas

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).

I agree.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.

I didn't understand this, Duoas. Please would you elaborate a bit? Terms likebasic language interpreter and sandbox environment are completely new to me.

@ssharish2005
The LISP routine would normally find the path for me, the output of that function (Which is nothing out the path) will be sent to my C code using sockets.

Do you mean that I can send a value from a function written in one language to the main function written in another language usingsockets? I'm new to the concept of sockets.

You could use sockets to communicate between routines if your wanted. Which makes it more simple, some thing similar to RPC or RPCgen which you are requesting for a routine to be called on the server and the output of that function would directed to the client to the client.

I don't know what isRPC and RPCgen . Are these related to sockets? From what you've given it seems it is related to networking.

Jishnu
Posting Pro
518 posts since Oct 2006
Reputation Points: 193
Solved Threads: 25
 
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.


YES thats right, you call the routine which is written in a different language. But the calling procedure is language independent. It will vary from language to language. But, in LISP you have a inbuilt library which allows to do some socket manipulation.I don't know what is RPC and RPCgen . Are these related to sockets? From what you've given it seems it is related to networking.
YES, it is something related to networking. But its is more often used in the UNIX world. I dunno about this on Windows though. I will have to research. RPC stand for Remote Procedure Call. So the name itself specific what it is suppose to do. You register all your routines on the server and the server will be waiting for the connection from the client and when once connected the client will request for a routine to be executed and the server will execute it and sends back the results to client across the network. Goggle "RPC Programming". This comes under a topic of Distributed Computing

ssharish

ssharish2005
Posting Whiz in Training
253 posts since Dec 2006
Reputation Points: 73
Solved Threads: 20
 
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
Team Colleague
30,041 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 
And as explained by ssjarish it doesn't matter what computer language the programs are written in as long as that language supports sockets.

Do C and C++ support sockets? Are any special libraries required?

Jishnu
Posting Pro
518 posts since Oct 2006
Reputation Points: 193
Solved Threads: 25
 
Do C and C++ support sockets? Are any special libraries required?

YES, C\C++ support Socket/Network programming. Follow a link bellow for a good tutorial on socket and RPC programming. Socket Programming
RPC Programming
RPCgen Programming

ssharish

ssharish2005
Posting Whiz in Training
253 posts since Dec 2006
Reputation Points: 73
Solved Threads: 20
 
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
 
Whether you choose to do this or not you've got a lot of homework ahead of you.

Yes, of course. These concepts are very much new to me and it will take quite a bit of time to have a decent grip over them. Thank you very much :)

Jishnu
Posting Pro
518 posts since Oct 2006
Reputation Points: 193
Solved Threads: 25
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You