Results 1 to 8 of 8

Thread: newbie C question

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    14

    Question 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?
    do you like halflife ???

    check

    chAos mApping

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    14
    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?
    do you like halflife ???

    check

    chAos mApping

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  5. #5
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Yep, shared libraries. Never got any attempts to work under lunix, but I didnt try very hard, and it was a while back =).

    Z.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    14
    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 ???
    do you like halflife ???

    check

    chAos mApping

  7. #7
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    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.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    14
    sounds good but difficult, i'll try that thx
    do you know about any tutorial explaining something like that?
    do you like halflife ???

    check

    chAos mApping

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width