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

Posted on 2003-03-03
Medium Priority
Last Modified: 2010-03-31
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.


Question by:espadana
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 15

Accepted Solution

ozymandias earned 150 total points
ID: 8063290
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


Expert Comment

ID: 9058956
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question