Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

PLEASE HELP ME: This rummy game is driving me nuts!!!!

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.


1 Solution
Can you not write a function called sameSuit that returns true if two cards have the same suit. Then also write a function called proximity which returns in int between 1 and 12 indicating the value distance between two cards.

For instance :

6H.proximity(7H) would return 1.
6H.proximity(4H) would return 2.

Then you write a function that checks for a same suit sequence by finding all the cards of the same suit and calculating their proximity.

First you check to see if you have any 3 cards of the same suit. If you do take one and calculate its proximity to the other two by adding their proximity values together. If it is 3 or less it must be a sequence.

You can do the same with any 4 cards of the same suit except that their proximity must be 6 or less

This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now