Contract Bridge In Java

Posted on 2005-03-04
Medium Priority
Last Modified: 2012-05-05

I'm currently programming the card game contract bridge using java.  I need a little help in checking whether the card exists in the deal.  

I have created a RandomDeal class, where the cards are defined, a TestDeal class, where a deal is distributed and a BridgeApp class, where the methods are called and run.  

Currently this is what I have got in the standard play method:
  /**                      Request input for card
            Check whether card exists
            If not, output error message
            If it does, play card **/
            System.out.println("SOUTH PLAY A CARD:");
            card = keyboardInput.readLine();
            switch (checkCard) {
            System.out.println("\n Error: YOU DO NOT HAVE THAT CARD " +
                                    card + "\n");
            System.out.println("NORTH PLAY A CARD:");
            card = keyboardInput.readLine();

I know this is incomplete, but I cant seem to get my head round, how to check the RandomDeal class for validity.  

Question by:Ikram_Bohra
  • 2
LVL 85

Assisted Solution

ozo earned 600 total points
ID: 13472430
What is your RandomDeal class, and what difficulty are you having with the check?
Could you also show your RandomDeal class?

Accepted Solution

mike_mian earned 1400 total points
ID: 13571879
In your card class you could have state attributes that indicate the hand they are in "N|E|S|W" and if it has been played.
In you deal class have a hash of the card  keyed on the card face (eg 5H = 5 of hearts) and add a method to the deal class
that takes postion as an argument and replace the switch with a call to the deal class hash look-up, that throws an exception indicatioing the
problem (card already played, do not have card) else it changes the card state to played (hidden iin the deal class).


Expert Comment

ID: 13571907
coe would look something like this:

/**                     Request input for card
          Check whether card exists
          If not, output error message
          If it does, play card **/
          System.out.println("SOUTH PLAY A CARD:");
          card = keyboardInput.readLine();
         try {
            RandomDeal.checkCard(card, 'S');
        } catch (DealException de) {

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

621 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