Thread: Ideas for multiple child processes in a poker project

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    23

    Ideas for multiple child processes in a poker project

    Hi, I'm trying to solve a problem with my project, in the assignment I just have 2 requirements:
    -client server
    -communicating processes
    and as project I've done a client-server poker app in C, I'm having troubles in the last part, in my idea, the check of the point will be done by child and communicating processing in this way:


    thinking that for example the straight flush:
    -if receives from his child flush true and from his child straight false returns to the father flush
    or the full house:
    if the pair child indicates a 2 pair kills the tris child and notifies the 2 pair to the the father
    Ideas for multiple child processes in a poker project-diagram-jpg
    now the problems:
    I already have done this part in a simple iterative way, but I'd like to give to the task a bit of complexity, my questions are:
    -what is the best way to do this?(I'm just looking for some hint or pseudocode)
    -is there a better way however based to communicating processes to do that task?


    Thanks in advance and sorry for my English.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    I would not bother with the "intermediate" processes of full house and straight flush. If the person only has a pair, then how will you relay that info to the parent process? It has to go through the full house process. I would simply have the pair, tris, four of a kind (you forgot this one), flush and straight processes* as direct children of the parent ("father"). Use fork to spawn each child. You could use the return value of the main function, or the value passed to the exit function, from those child processes, as a flag for whether or not that condition is met: 0 no such hand, 1 that hand exists. The pair process could return a count of the pairs: 0, 1 or 2. If you are using Linux, then you could use wait() or waitpid() (check "man waitpid" for lots of info), combined with the WIFEXITED and WEXITSTATUS macros to determine the return value from the child processes**.

    Then, I would leave it to the parent ("father") process to combine the exit statuses of the all children to see what the best hand is.

    Hope that helps, and is sufficiently clear. If you have more questions, ask.

    * I might actually also have one for the high card, so it can be used to rank hands if there are no pairs, tris, etc. It would return the rank of the card (2-10, 11 jack, ..., 14 ace). Also, it could be used to determine a royal flush (straight flush, ace high), and who wins when both players

    ** There are many other methods of IPC, like shared memory, pipes, sockets, message queues, semaphores and signals, but for this case, I would consider process exit status the easiest.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    I already have done this part in a simple iterative way, but I'd like to give to the task a bit of complexity
    Engineering is about finding the simplest possible solution to a problem. You have a simple and working solution, why try to make it harder?

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    23
    Quote Originally Posted by cyberfish View Post
    Engineering is about finding the simplest possible solution to a problem. You have a simple and working solution, why try to make it harder?
    Because the project must have communicating processes (it's an Operating System project) and I think this is a good case where use them.

    Btw thanks @anduril462 for your ideas. I've edited the communicate schema in this way: http://f.cl.ly/items/3H2T0y3a0E3d0b0t3m1V/schema.jpg (in the straight flush process I forget to write that the straight flush wait the high card process to exit with 4 if there is a royal flush) and the parent just check the exit status of 4 children, high card, poker, straight flush and full to determinate the hand value.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Child processes
    By jsx-27 in forum C Programming
    Replies: 3
    Last Post: 08-24-2012, 02:27 AM
  2. How do I stop child processes from becoming defunct?
    By Zarniwoop in forum C Programming
    Replies: 7
    Last Post: 12-19-2009, 06:36 PM
  3. forks and child processes
    By kpax in forum C Programming
    Replies: 1
    Last Post: 05-28-2008, 04:47 AM
  4. sockets and child processes
    By Elkvis in forum Linux Programming
    Replies: 2
    Last Post: 03-06-2008, 04:03 PM
  5. Child processes in Linux
    By Music_Man in forum Linux Programming
    Replies: 0
    Last Post: 03-20-2003, 09:04 AM