?
Solved

Contract Bridge In Java

Posted on 2005-03-04
3
Medium Priority
?
380 Views
Last Modified: 2012-05-05
Hi

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) {
                        
                        
            default:
            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.  

 
0
Comment
Question by:Ikram_Bohra
[X]
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
  • 2
3 Comments
 
LVL 84

Assisted Solution

by:ozo
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?
0
 
LVL 3

Accepted Solution

by:
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).

 
0
 
LVL 3

Expert Comment

by:mike_mian
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) {
           System.out.println(de);
        }
     
     
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

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 …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

743 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