Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Permutation

  1. #1
    Junior Member
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Permutation

    Hello community,

    I'm working on a project an am in need of a little help, so I hope I'll get some hints here.

    This is about a game, but I thought it fits this category best. So I do a board game with cards (which is completed) and now the ai needs to become smart. All this is done, but where I'm having trouble is finding permutations of my cards. Here's what we've got:
    - cards are numbered from 0 to 6, so I work with ints (or Strings, whatever is best)
    - we are given 9 cards --> so there could be something like 111534123
    - we want to pick 5 cards (their order is the important thing here)
    - we want to try out all permutations an find the best (this is done)
    - it should be as fast a possible (getting all 9-int-permutation is not fast because of the trying part)

    What I have so far is a method that finds all permutations of 5 (or 9) given ints _without_ repeating identical numbers (e.g. 11354 only appears once, not twice).
    So my idea was to pick 5 out of these 9 ints and then permutate them with my algorithm.

    What I need help with is:
    - How do I pick 5 of these 9 cards to then permutate them? Without repetition of course.
    - Is my idea nonsense and there is a way to combine these two steps or am I thinking in the complete wrong direction?

    Furthermore, there are combinations that are deadly and we do not want to permutate them. Say we have 12345, and the testing shows card 2 kills us, so we don't want to test 12435,... because they're all deadly. (This is not the main question, I don't think this can be done without code.)

    So, I hope I made myself clear, I apologize if not, and hope someone can give me some kind of idea. A hint would be enough, pseudo if it makes it clearer.

    Thanks a lot,
    Nahara


  2. #2
    Member Faz's Avatar
    Join Date
    Mar 2010
    Posts
    97
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Default Re: Permutation

    I'm a bit confused as to the game I mean what constitutes a good hand? I mean you say 12345 is deadly would 23456 or 01234 be stronger and how strong would say 66666 or 00000 be?

  3. #3
    Junior Member
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Permutation

    Hey Faz, thanks for your interest.
    The evaluation of the cards depends on the current position of the player, it is kinda complex and i would rather not go into detail here, but this part is done and works fine.

    By the way, the part where the second card kills us and we want to avoid further permutatons afterward is done now, it was easier than it sounded.

    I would still be glad if someone could give me a hint on picking all sets of 5 out 9 ints without repitition.

    Nahara
    Last edited by Nahara; June 29th, 2010 at 01:27 PM.

  4. #4
    Member Faz's Avatar
    Join Date
    Mar 2010
    Posts
    97
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Default Re: Permutation

    I'm bamboozled I have to say. If the order of cards is the most important have you thought about ordering them? For a video poker game I wrote I decided to create a duplicate of the hand that was ordered by strength of the card so checking for pairs/straights etc so I would only need to step through the cards from left to right once.

    However that was a 5 choose 5 situation not a 9 choose 5 but if it is mostly order I think this would be something to look at.

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Permutation

    you'll have to explain the rules of the game, otherwise the best solution we can give you is brute force (which you have right now).

    I suspect, though, you'd want to do something like Faz suggested and order your original 9 cards (if possible), and then go through a pre-defined list of hands going from "best" (as in always pick this if possible) to "worst" (as in try to avoid this if possible). The number of different hands can be quite large, but you should be able to categorize different hands into a handful of categories and compare them using a simple algorithm.

  6. #6
    Junior Member
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Permutation

    Problem solved, topic can be closed.

    Solution was completely different to my first approach, but works perfectly.
    I guess I didn't describe it right, but thanks for helping anyway. (:

  7. #7
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Permutation

    Fyi, you can mark your own threads as solved when they are solved. Simply go to Thread Tools -> Mark Thread as Solved. I've marked this one as solved for you.