PLEASE HELP: This rummy game is driving me nuts

Started by
7 comments, last by pars 21 years, 1 month ago
I have had this problem for a while, and I can''t think of any feasable solution. I am programming in java BUT this problem is not language related, please read. In my project, I am suppose to create an agent that plays a simple version of rummy. To win this game, the agent is dealt seven cards initially, and in order to win, it has to create two sets of combination of cards (one of 3 cards the other of 4), each combination can either have cards of the same rank (eg. 10 Hearts, 10 Clubs, 10 Spades) or the same sequence, but the same suit (2s,3s,4s,5s OR 7c,8c,9c). Beside the main SDK, we have our own api for this game, that for example lets you check whether two cards are in the same rank (eg. (10H.sameRank(10D) returns true), or whether they have the same suit or not. I have no trouble creating a hand of cards with the same rank, but my problem is with creating a hand of cards with the same sequence. I have tried to come up with an algorithm that would allow me to create a hand of cards (of same suit) in the sequence, but without success. This thing is driving me nuts. CAN ANYONE GIVE ME ANY GUIDANCE PLEASE!! Thanks
----Khalije Hamishegiye Faars!!!!
Advertisement
do you mean you cannot get your agent to successfully "go for" and construct a sequence or you do not know how to model a sequence hand?

I know how to how to check one card to see if its in sequence with another card that I am holding (BTW I am storing the hand in an array).

mstein, I don''t fully understand the second part of your question. But I suppose the problem is that I can''t come up with a good technique, so that the agent would be able to construct a sequence.

Thanks
----Khalije Hamishegiye Faars!!!!
Just to sumarise your problem and see if we have this right:

your agent has been dealt a hand of 7 cards and you want to decide whether any of those 7 cards form a run (sequence of ascending cards)? Is this right?

If this is correct, then the easiest way is to write a quick sort alogrithm (or use qsort) which orders cards from low to high in their suit, then run through a final for loop which sees if you have any in a sequence of the required length.


[edited by - shamen on March 3, 2003 1:47:52 PM]
okay this is totally random and there is probably a better way to do it, but this idea just sprang from my head:

So you are dealt a hand of 7 cards. You could construct a system that divides the cards in your hand to all possible "winning hands (sequences/same rank).

Example

2C, 6D, 7D, 9Clubs, JHearts, KHearts, AceSpades

Now we take our hand and divide it into every possible straight/same rank sequence our agent could conceivably go for. We need some bounds though, like if we had the 10 of Diamonds in there too, we would not include it in our grouping of the 6 of Diamonds and the 7 of Diamonds. Let me show you what i mean:

----- ----- ------- ------- --------- ------- -------
2s | 6s | 7s | 9s | Jacks | Kings | Aces

----- ------
6-7D JK-Hearts

So you would search your array for these combinations. All single cards would go into their own individual bin of hands that the agent could go for. Then you would search for sequences. This way the agent knows what he needs. Example:

Suppose a 5 of Diamonds comes up. The agent could traverse his bins. The 5 is meaningless everywhere but the 6-7Diamond bin. YOu could have a function that tells you if a card would help in a certain bin.

There are lots of tiny details, but i think this would be a pretty neat way of doing it, and it would be object oriented so you could tailor it to your already existing API.

let me know if you want any more ideas or if you just want me to shut up

[edited by - mstein on March 3, 2003 1:48:18 PM]

[edited by - mstein on March 3, 2003 1:49:06 PM]
Thank you both for the replies.

mstein, when you talk about bin of hand, how do you think it would be best represented when writing the code for it? (what should be used as a bin)

I should probabely say that my agent doesn't need to know whether it has the winning hand or not. The dealer (which is part of the api) will automatically determine the winner

[edited by - pars on March 3, 2003 3:43:45 PM]
----Khalije Hamishegiye Faars!!!!
i was thinking (and bare with me, havent coded in awhile) something like:

// very incompleteclass Bin{int curCount = 0;string cards[7]; // most any hand could have is seven cards// in real rummy you can win by having a 7 card straight too//maybe you do not have to support that// could also do Card cards[7] if you have a Card class (i dont know what you already have)public Bin() {}public addCard(String s) { cards[curCount++] = s;}public removeCard(String s) {//find card s and boot it and reorder array}// function would see if adding the given card to this hand would helppublic willCardHelp(String s) {}// if we needed to get rid of a card, our discard, a binrank function would be neededpublic binRank() {}//other functions}[\CODE]so each of my bins would be an instance of class Bin.  so once the agent is first dealt the cards you find all of the meaningful bins that could be created. In my previous example we have the 6 and 7 of Diamonds.  THey would be their own bin.  Through interaction with that bin, the agent knows that he wants a 5 of Diamonds or an 8 of Diamonds.  This logic would be setup in checkCard.  So when the 5 of Diamonds comes along, we call willCardHelp("5D") on all bins.  the bin that has the "2" in it is not going to want the 5 of diamonds, but the bin that has the 6 and 7 of Diamonds is.  Do you kind of understand what i am saying.  The more i look at this, its probably overkill, and you could easily write some brute force method that goes in and sees what the agent has and what he should go for, but to me this is more elegant and easier to see what is going on.If you really want me to elaborate more, i can try, but i have to get back to work at the moment.     


[edited by - mstein on March 3, 2003 4:03:40 PM]
Thanks a lot, I''ll get back to you again if I need help
----Khalije Hamishegiye Faars!!!!
let me know if you actually do it this way as opposed to a more brute force approach, i am curious to see how it works out, and yeah would love to help.

This topic is closed to new replies.

Advertisement