1 / 61

Card 크레스

Card 크레스. Card String suit String face int rank Card (String, String, int ) Card () int compareTo (Card ) String toString (). Deck 크레스. Deck ArrayList <Card> cards Deck () Card deal (). 52 Card 객체 들 : Hearts, Diamonds, Spades, Clubs

tyson
Download Presentation

Card 크레스

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Card 크레스 Card String suit String face intrank Card(String, String, int) Card() intcompareTo(Card) StringtoString()

  2. Deck 크레스 Deck ArrayList<Card> cards Deck() Card deal() 52 Card 객체들: Hearts, Diamonds, Spades, Clubs Ace, Deuce, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King

  3. publicDeck() { //constructor cards = newArrayList<Card>(); String[] suit = {"Clubs", "Spades", "Hearts", "Diamonds"}; String[] face = {"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}; for(intx = 0; x < 52; x++) { Card c = new Card(); c.setSuit(suit[x / 13]); c.setFace(face[x % 13]); c.setRank((x % 13) + 1); cards.add(c); } Collections.shuffle(cards); }

  4. 코딩 타임 입니다

  5. Hand 크레스 Hand ArrayList<Card> cards ArrayList<Card> evalCards inthandValue booleanisHi booleanisPair booleanis2Pair booleanis3 booleanis4 booleanisFlush booleanisFull booleanisStr8 booleanisStr8Flush addToHand(Card) Stringeval() StringcalcHandValue(int, int, int, int)

  6. Hand Evaluation • 2 methods: • eval() • calcHandValue(int, int, int, int)

  7. eval() • Multiple cards of same rank: • Four of a kind, full house, three of a kind, 2pair, pair • 5 cards in order of rank • Str8 • 5 cards of same suit • Flush

  8. Example: flush

  9. sameSuit[0] sameSuit[1] sameSuit[2] sameSuit[3] = 0 = 0 = 0 = 1

  10. Write Hand class

  11. Make JUnitTest

  12. Download flush_test.zip

  13. calcHandValue(int,int,int,int) • Instance variable handValuecalculation, representing the strength of the hand

  14. inthandValue • Six 4bit ‘words’ : 0000 0000 0000 0000 0000 0000 Type Card1 Card2 Card3 Card4 Card5

  15. inthandValue • First ‘word’ - Type 1000 isStr8Flush 0111 is4 0110 isFull 0101 isFlush 0100 isStr8 0011 is3 0010 is2Pair 0001 isPair

  16. Example: isFlush Player 1: Player 2:

  17. Example: isFlush Player 1: inthandValue: 0000 0000 0000 0000 0000

  18. Example: isFlush Player 1: inthandValue: 1101 1010 0111 0100 0011 Bit Shift Operation: 13<<16 10<<12 7<<8 4<<4 3

  19. inthandValue • First ‘word’ - Type 1000 isStr8Flush 0111 is4 0110 isFull 0101 isFlush 0100 isStr8 0011 is3 0010 is2Pair 0001 isPair

  20. Example: isFlush isFlush Player 1: inthandValue: 0101 1101 1010 0111 0100 0011 5<<20 Bit Shift Operation: 13<<16 10<<12 7<<8 4<<4 3

  21. Example: isFlush isFlush Player 1: inthandValue: 6,137,667

  22. Example: isFlush isFlush Player 1: 6,137,667 inthandValue: isFlush Player 2: 6,137,666 inthandValue:

  23. Example: isFlush 6,137,667 > 6,137,666 Player 1 wins!

  24. Write calcHandValue() method Add to evalTest(): assertEquals(h.handValue, 6137667)

  25. Example: multiple cards same rank Player 1: Player 2:

  26. Example: multiple cards same rank Player 1:

  27. Example: multiple cards same rank Player 1:

  28. Example: multiple cards same rank

  29. sameRank [0] sameRank[1] sameRank[2] sameRank[3] sameRank[4] sameRank[5] sameRank[6] sameRank[7] sameRank[8] sameRank[9] sameRank[10] sameRank[11] sameRank[12] sameRank[13] = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0

  30. sameRank [0] sameRank[1] sameRank[2] sameRank[3] sameRank[4] sameRank[5] sameRank[6] sameRank[7] sameRank[8] sameRank[9] sameRank[10] sameRank[11] sameRank[12] sameRank[13] = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 1 = 0

  31. sameRank [0] sameRank[1] sameRank[2] sameRank[3] sameRank[4] sameRank[5] sameRank[6] sameRank[7] sameRank[8] sameRank[9] sameRank[10] sameRank[11] sameRank[12] sameRank[13] = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 2 = 0

  32. sameRank [0] sameRank[1] sameRank[2] sameRank[3] sameRank[4] sameRank[5] sameRank[6] sameRank[7] sameRank[8] sameRank[9] sameRank[10] sameRank[11] sameRank[12] sameRank[13] = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 0 = 1 = 0 = 2 = 0

  33. sameRank [0] sameRank[1] sameRank[2] sameRank[3] sameRank[4] sameRank[5] sameRank[6] sameRank[7] sameRank[8] sameRank[9] sameRank[10] sameRank[11] sameRank[12] sameRank[13] = 0 = 0 = 2 = 0 = 0 = 0 = 0 = 0 = 0 = 2 = 1 = 0 = 2 = 0

  34. Example: multiple cards same rank

  35. Example: multiple cards same rank X=13

  36. sameRank [0] sameRank[1] sameRank[2] sameRank[3] sameRank[4] sameRank[5] sameRank[6] sameRank[7] sameRank[8] sameRank[9] sameRank[10] sameRank[11] sameRank[12] sameRank[13] = 0 = 0 = 2 = 0 = 0 = 0 = 0 = 0 = 0 = 2 = 1 = 0 = 2 = 0

  37. Example: multiple cards same rank X=12

  38. sameRank [0] sameRank[1] sameRank[2] sameRank[3] sameRank[4] sameRank[5] sameRank[6] sameRank[7] sameRank[8] sameRank[9] sameRank[10] sameRank[11] sameRank[12] sameRank[13] = 0 = 0 = 2 = 0 = 0 = 0 = 0 = 0 = 0 = 2 = 1 = 0 = 2 = 0

  39. Example: multiple cards same rank X=12

  40. Example: multiple cards same rank X=12

  41. Example: multiple cards same rank X=12, sameCard1=2, sameCardRank1=12

  42. Example: multiple cards same rank X=11

  43. sameRank [0] sameRank[1] sameRank[2] sameRank[3] sameRank[4] sameRank[5] sameRank[6] sameRank[7] sameRank[8] sameRank[9] sameRank[10] sameRank[11] sameRank[12] sameRank[13] = 0 = 0 = 2 = 0 = 0 = 0 = 0 = 0 = 0 = 2 = 1 = 0 = 2 = 0

  44. Example: multiple cards same rank X=10

  45. sameRank [0] sameRank[1] sameRank[2] sameRank[3] sameRank[4] sameRank[5] sameRank[6] sameRank[7] sameRank[8] sameRank[9] sameRank[10] sameRank[11] sameRank[12] sameRank[13] = 0 = 0 = 2 = 0 = 0 = 0 = 0 = 0 = 0 = 2 = 1 = 0 = 2 = 0

  46. sameRank [0] sameRank[1] sameRank[2] sameRank[3] sameRank[4] sameRank[5] sameRank[6] sameRank[7] sameRank[8] sameRank[9] sameRank[10] sameRank[11] sameRank[12] sameRank[13] = 0 = 0 = 2 = 0 = 0 = 0 = 0 = 0 = 0 = 2 = 1 = 0 = 2 = 0

  47. Example: multiple cards same rank X=9

  48. Example: multiple cards same rank X=9

More Related