|
-
Feb 18th, 2003, 12:34 PM
#1
Thread Starter
New Member
newbie C question
i have a difficult question:
i want to build a program like chess
i would like to program a main program once. it should be able to prepare the game field and check if a move is correct or not and then call step by step two different functions written by anyone, which calculate the next move
my question: how can i organize my main program so that it is possible to add at any time any new ai function to calculate a good move without changing my main function. it would be fantastic if it would be possible that the program recognizes itself how many different ai functions are awailable and then let the user choose which to use
my english is not that good, so again in german
ich möchte ein programm bauen, dass ein schachspiel (für den anfang erstmal was einfacheres) darstellt. dabei soll das programm selbst nur das spielfeld zur verfügung stellen und nicht die berechnung für die einzelnen züge zur verfügung stellen. die einzelnen züge sollen später von anderen programmteilen berechnet werden. ich plane dabei mit ein paar leuten, das jeder seine eigene funktion bastelt und dann alle funktionen im hauptprogramm eingebunden werden so dass man die einzelnen computer gegeneinander antereten lassen kann
wie kann ich es programmieren das mein hauptprogramm merkt welche funktionen zur verfügung stehen und sie dann einbindet?
-
Feb 18th, 2003, 02:22 PM
#2
Frenzied Member
There are a couple of options here. The first, you can use dlls to dynamically load your next move finding function. With the correct setup, the find move function would be in a dll, and the user can select which dll's function to use. Ill refer you to the MSDN for more information.
The second option is scripting, writing your find next move function in some sort of scripting language. There are several canned ones on the net (Lua, Python, Javascript, etc), or you could write your own. Google would be your best bet, this time.
Z.
-
Feb 18th, 2003, 05:09 PM
#3
Thread Starter
New Member
hm i thought about dlls but i use linux
and also i don't want to use scripts.
is there no way to include compiled c programs?
-
Feb 18th, 2003, 05:20 PM
#4
Shared libraries then.
The problem is that once C code is compiled there's very little information about it left. Actually no information at all. That's what makes finding functions so hard.
If you don't mind recompiling then you could make an array of function pointers. Each array entry consists of a name and a function pointer. If you want to add a function you write that function, add it to the array along with a name and recompile.
P.S: if you want anything translated PM me - ich bin Österreicher. Allerdings fühl ich mich bei technischen Dingen auf Englisch sogar wohler
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 18th, 2003, 05:51 PM
#5
Frenzied Member
Yep, shared libraries. Never got any attempts to work under lunix, but I didnt try very hard, and it was a while back =).
Z.
-
Feb 18th, 2003, 05:54 PM
#6
Thread Starter
New Member
hm its ok understanding english is not the problem but writing
if i have to recompile it is not a solution i would prefer
what about something like my main prog calls another program that calculates the move, by sending information about the field by io (getchar and putchar) and recieving the information vice versa
like answer = system("my_prog")
would that be possible ???
-
Feb 18th, 2003, 08:58 PM
#7
Frenzied Member
What you want is a standard feature of unix: RPC or remote procedure call.
Example:
You have one program which does nothing more than move pieces around. Every move is communicated to another independent image file running as a daemon. You can constantly change the daemon process as long as the comminucation protocol stays the same, ie., you don't need to change the part that does the screen i/o.
Assume you have an image file that does the ai called daemoncode .
When you start the player part, call "exec(daemoncode);", get a process handle (pid). You can then do i/o back & forth between the two processes using stdin & stdout for both processes.
-
Feb 19th, 2003, 01:32 PM
#8
Thread Starter
New Member
sounds good but difficult, i'll try that thx
do you know about any tutorial explaining something like that?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|