Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Please clarify me the concept

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two class --------
  1.cardDeck has a list of cards and
  2.Player extends cardDeck
In cardDeck,I create a deck of 52 cards and shuffle,
And I create player array for 2 players


Doubt----------??
Declaring the list of cards as static in cardDeck class will make both the players have the same list of cards.?
 
Saloon Keeper
Posts: 6049
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can see if you are on the right track with the IS-A and HAS-A rules.

Does this sound correct to you?
A Player IS-A CardDeck

No, a Player is not a CardDeck.

But...
A Player HAS-A Hand

And possibly
A Hand IS-A CardDeck

You might want a more generic class like "CardSet" which could be used for both a deck and a hand.
CardSet deck = new CardSet( 52 ); // or something
 
Divyadharshini Karthikeyan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Carey Brown
Thank you now I got it.
 
Marshal
Posts: 6974
471
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have any requirements what needs to be done? It is quite difficult to suggest something when isn't clear what needs to be done.
 
Marshal
Posts: 65108
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Divyadharshini Karthikeyan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each player will have 2 cards in hand.
On board there will be 5 cards.
Pick the best hand with five cards (best 5 cards from 7 cards)
I need ideas for evaluating hands.



 
Campbell Ritchie
Marshal
Posts: 65108
247
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think these two topics are so similar that they sould be discussed as one. I have joined the two discussions.

I am pleased to see you indenting your code, but some of yur lines (e.g. line 71) are too long and should be broken into two lines.
Don't use \n, and don't terminate what you are returning from toString() with a line end sequence (line 83). Write return rank + " of " + suit; Leave it to the method's user to decide whether to use println() or print() or similar.

I can see two serious problems. You have fields which are not marked private.
You have duplicated data structures, particularly the enums, which appear twice each. Such enums should be written as top‑level types, not nested types.

There are lots of minor problems, which will lose you marks, but I shall keep quiet about them for now.
Don't use Strings to pass information. You can pass the enum elements directly. Looks at lines 44 and 76.
 
Saloon Keeper
Posts: 3415
149
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This merging is not very handy. I wanted to reply to the topic of comparing twp pokerhands, only to end up in this topic with a diffrent title. Confusing.

But here's the reply to that comparing, the way I solved it for a Project Euler exercise:

First of all: the situation is slightly better than you imagine. Since you have two cards in your hand, you have to pick only 3 out of 5 cards, reducing the possibilities from 21 to a mere 10.

Then comparing two hands. What I did to evaluate a hand was to first make a map of your hand. The keys will be the values of the cards (2, 3, 4, ...., K, A), the values of the map will be the corresponding cards.

The valuation is then a two step process.

If the size of the map is 2, then you have either a 4-1 split or a 3-2 aplit. Checking one of the frequencies is rhen sufficient to determine which of the two you have. If the size is 3, then you have two pairs, with a size of 4 you have one pair and a size of 5 will give you the chance of a royal flush.

If that is not sufficient to determine a winner, then make sure that the first key in your map contains the highest value. You can then compare the first key of one hand to the first key of the second. Et cetera. It may boil down to effectively determine the hands card by card.

If you make sure your map is ordered handily, so highest key first, and the values in order of highest colour first, then the comparison is not too hard.
 
Rancher
Posts: 471
6
IntelliJ IDE Spring Fedora
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made a project that was a game server for it seems like the exact same card game.   Evaluating the hands is a very hard problem but thankfully its common so I was able to find an algorithm.  
 
Divyadharshini Karthikeyan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for helping me sort out. It worked
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!