๊ณต๋ถ€ ์—ฐ์Šต์žฅ :-)

TIL_20180122 ~ 20180128

|

2018.01.22

2018.01.23

  • ์นด๋“œ๊ฒŒ์ž„ step5 PR๋ณด๋‚ด๊ธฐ
    • comparable, equatable enum์— ๊ตฌํ˜„ > rawValue์™€ hashValue๋กœ ๊ตฌํ˜„ํ•จ
    • hands ํด๋ž˜์Šค๋ฅผ PokerHands ์ด๋ฆ„๋ฐ”๊พธ๊ธฐ
    • ํ๋ฆ„์— ๋Œ€ํ•œ ์ƒ์„ธ๊ตฌํ˜„ํ•˜๊ธฐ - ok
  • PR์„ฑ๊ณต!

2018.01.24

  • ์นด๋“œ๊ฒŒ์ž„ step5 ํ”ผ๋“œ๋ฐฑ ์ฒ˜๋ฆฌ
    • private var denomination ์—๋Ÿฌ - ํด๋กœ์ €์—์„œ denomination์„ ์จ์„œ ์ƒ๊ธด๊ฒƒ์ด์—ˆ์Œ! (ํด๋กœ์ €์—์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์–ด๋”˜์ง€ ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ์ •ํ™•ํžˆ ๋ชจ๋ฅด๋‹ˆ๊นŒ ๋ฒ„๊ทธ๊ฐ€ ์ƒ๊ธด ์œ„์น˜๋ฅผ ์•Œ๋ ค์ฃผ์ง€ ์•Š์•„์„œ, ์ฐพ๋Š”๋ฐ ์ข€ ์• ๋ฅผ ๋จน์—ˆ๋‹คใ… ใ… )
    • comparable ์‚ฌ์šฉํ•ด์„œ ์นด๋“œ ๋น„๊ต
    • getter๋ฉ”์†Œ๋“œ ๊ตฌํ˜„ํ• ๋•Œ ๋„ค์ด๋ฐ
      • get์„ ์“ฐ์ง€๋ง๋ผ๋Š”๋œป์€ ๋ฉ”์†Œ๋“œ ์ด๋ฆ„์— get์„ ์“ฐ์ง€ ๋ง๋ผ๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ getter๋ฅผ ๋งŒ๋“ ๋‹ค๋Š”๊ฒƒ ์ž์ฒด๊ฐ€ ์†์„ฑ๊ฐ’์„ ๊ฐ€์ ธ์™€์„œ ๋‹ค๋ฅธ ๊ณณ์—์„œ ์–ด๋– ํ•œ ๋™์ž‘์„ ํ•˜๊ณ  ๋น„๊ต๋ฅผ ํ•œ๋‹ค๋Š” ๋œป์„ ๋‚ดํฌํ•˜๊ณ ์žˆ๊ธฐ๋•Œ๋ฌธ์—, card.isSameSuit()์ฒ˜๋Ÿผ ๋‚ด๋ถ€์—์„œ ๋น„๊ตํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ดํ•ด์ฃผ๋Š” ๋ฉ”์†Œ๋“œ๊ฐ€ ์žˆ์–ด์•ผํ•œ๋‹ค๋Š”๊ฒƒ. ๋‹ค๋งŒ Cardํด๋ž˜์Šค์—์„œ ๊ตฌํ˜„ํ•œ comparable ๋ฉ”์†Œ๋“œ๋ฅผ ๊ตฌํ˜„ํ• ๋•Œ ์•„๋ž˜์ฒ˜๋Ÿผ hashValue๋‚˜ rawValue์— ์ ‘๊ทผํ–ˆ๋Š”๋ฐ, ์ด๊ฒƒ๋˜ํ•œ ์ƒ์œ„๊ฐœ๋…์ธ Cardํด๋ž˜์Šค์—์„œ suit๋‚˜ denomination์˜ ์†์„ฑ๊ฐ’์„ ๊ฐ€์ ธ์™€์„œ ์“ฐ๋Š”๊ฑฐ๋‹ˆ๊นŒ, suit๋‚˜ denomination์†์„ฑ์—์„œ comparable์„ ๊ตฌํ˜„ํ•˜๊ณ  Cardํด๋ž˜์Šค์˜ ๋ฉ”์†Œ๋“œ์—์„œ .hashValue / .rawValue๋กœ ์ ‘๊ทผํ–ˆ๋˜๊ฒƒ์„ ์ง€์šธ ์ˆ˜ ์žˆ๋‹ค. ```Swift // Before // Card.swift func isSameSuit(previous: Card) -> Bool { return self.suit.hashValue == previous.suit.hashValue }

      // After add Comparable to enum suit

      // suit์—์„œ๋Š” hashValue์— ์ ‘๊ทผํ•˜์—ฌ ๋ฉ”์†Œ๋“œ ๊ตฌํ˜„ํ•ด๋„ ๋จ. enum Suit: String, EnumCollection, Comparable { case heart = โ€œโ™ฅ๏ธโ€ case diamond = โ€œโ™ฆ๏ธโ€ case clover = โ€œโ™ฃ๏ธโ€ case spade = โ€œโ™ ๏ธโ€

      static func <(lhs: CardDeck.Suit, rhs: CardDeck.Suit) -> Bool {
          return lhs.hashValue < rhs.hashValue
      }
      
      static func ==(lhs: CardDeck.Suit, rhs: CardDeck.Suit) -> Bool {
          return lhs.hashValue == rhs.hashValue
      }
      

      // Card.swift func isSameSuit(previous: Card) -> Bool { return self.suit == previous.suit }

      
      ```swift
      // Before
      // Card.swift
      func isContinuous(previous: Card) -> Bool {
        return (self.denomination.rawValue -1) == previous.denomination.rawValue
      }
      // ScoreChecker.swift
      private func isStraight(_ cards: [Card]) -> Bool {
          var count = 0
          for i in 1..<cards.count {
              if cards[i].isContinuous(previous: cards[i-1]){
                  count += 1
              }
          }
          return count >= 4
      }
      
      // After
      // CardDeck.swift
      enum Denomination: Int, CustomStringConvertible, EnumCollection {
          case one = 1, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen
      
          var description: String {
              switch self {
              case .one: return "A"
              case .eleven: return "J"
              case .twelve: return "Q"
              case .thirteen: return "K"
              default: return String(self.rawValue)
              }
          }
      
          // Denomination์—๋„ ์ด๋ ‡๊ฒŒ ๋‚ด๋ถ€์— `rawValue๊ฐ’ - 1`๋กœ ๋น„๊ตํ•˜๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ๋งŒ๋“ค๊ณ 
          func isContinuous(previous: CardDeck.Denomination) -> Bool {
              return (self.rawValue - 1) == previous.rawValue
          }
      }
      //Card.swift
      // Card์—์„œ๋Š” denomination์˜ rawValue๊นŒ์ง€ ์ ‘๊ทผํ•˜์ง€์•Š๊ณ ,
      // ScoreChecker์—์„œ ๋„˜๊ฒจ๋ฐ›์€ card๋ฅผ denomination๊นŒ์ง€๋งŒ ์ ‘๊ทผํ•ด์„œ Enum
      // `denomination.isContinuous`์— ์ธ์ž๋ฅผ ๋„˜๊ธด๋‹ค.  
      func isContinuous(previous: Card) -> Bool {
        return self.denomination.isContinuous(previous: previous.denomination)
      }
      
      

2018.01.25

์นด๋“œ๊ฒŒ์ž„ step5 Hands ๊ฐ์ฒด

  • ์†์„ฑ: PokerHands enum, Card(TopCard)
  • ์‚ฌ์šฉ์ž๊ฐ€ ๊ฐ€์ง„ hands๋ณ„๋กœ TopCard๊ฐ€ ์žˆ์–ด์•ผํ•˜๊ณ , ๊ทธ hands์ค‘์—์„œ๋„ ์ œ์ผ ํฐ ์ ์ˆ˜๋ฅผ ๊ฐ€์ง„ hands์˜ ํƒ‘์นด๋“œ๋งŒ ์œ ํšจํ•œ์˜๋ฏธ์ž„.
  • ๋”ฐ๋ผ์„œ [PokerHands]๋กœ ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•˜๊ณ  ํŠœํ”Œํ˜•ํƒœ๋กœ ํƒ‘์นด๋“œ๋ฅผ ๊ฐ€์ง€๊ณ ์žˆ๋˜๊ฑธ ๋น„๊ตํ•˜๋‹ˆ๊นŒ ๋น„๊ตํ•˜๊ณ  ๋งž๋Š” ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๊ธฐ ํž˜๋“ค์—ˆ๋‹ค.
    • onepair 1๊ฐœ(2ํ•˜ํŠธ), nopair 3๊ฐœ(10ํ•˜ํŠธ,5ํด๋กœ๋ฒ„,6๋‹ค์ด์•„)์ธ 5์Šคํ„ฐ๋“œ์—์„œ onepair์˜ ํƒ‘์นด๋“œ์ธ 2ํ•˜ํŠธ์˜ ๊ฐ€์ค‘์น˜์ ์ˆ˜๊ฐ€ ๊ฐ€์ ธ์™€์ ธ์•ผํ•˜๋Š”๋ฐ nopair์ค‘์˜ ํƒ‘์นด๋“œ์ธ 10์˜ ๊ฐ€์ค‘์น˜์ ์ˆ˜๊ฐ€ ๊ฐ€์ ธ์™€์ ธ์„œ ๊ณ„์‚ฐ๋จ.
  • ์˜๋ฏธ์žˆ๋Š” hands์˜ ํƒ‘์นด๋“œ๋กœ ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ• ๋•Œ ๊ฐ€์ค‘์น˜๋ฅผ ๊ณฑํ•œ๋‹ค.
  • ์ ์ˆ˜๊ณ„์‚ฐํ•˜๋Š” ๊ฐ์ฒด์—์„œ๋Š” ๊ธฐ์กด์—[PokerHands]๋กœ ํ•˜๋˜๊ฑธ [Hands]๊ฐ์ฒด๋กœ ๋น„๊ต. comparable๊ตฌํ˜„ํ•ด์„œ [Hands]๋ฅผ sortํ•˜๊ณ  ๊ฐ€์žฅ ํฐ ํŽ˜์–ด(or ํ”Œ๋Ÿฌ์‹œ,์ŠคํŠธ๋ ˆ์ดํŠธ)์˜ ํƒ‘์นด๋“œ๋กœ ์ตœ์ข… ์Šค์ฝ”์–ด์— ๊ฐ€์ค‘์น˜๋ฅผ ๊ณฑํ•ด์ค€๋‹ค.
  • ์†์„ฑ์„ ๊ด„ํ˜ธ์— ๋‘๊ฐœ ๋„ฃ์–ด์„œ ๋ฐฐ์—ด๋กœ ๋„ฃ์€๊ฑธ ํ˜•์ƒํ™”ํ•œ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์Œ.
    • hands๋ฐฐ์—ด: [(PokerHands:TopCard),(PokerHands:TopCard),(PokerHands:TopCard)]: ํ•œ์‚ฌ๋žŒ์ด ์ด๋ ‡๊ฒŒ hands๋ฐฐ์—ด์„๊ฐ€์ง€๊ณ ์žˆ๊ณ , ScoreChecker์—์„œ final์ ์ˆ˜๊ณ„์‚ฐํ• ๋•Œ ์ด [hands]๋ฅผ ๊ฐ€์ง€๊ณ  ๊ณ„์‚ฐํ•˜๋ฉด๋ ๋“ฏ. (๋งŒ์•ฝ์— ์ด๋ ‡๊ฒŒ ๊ตฌํ˜„ํ•˜๋ฉด ๋ชจ๋“  ์œ ์ €๊ฐ€ ๋‹ค ๋…ธํŽ˜์–ด์ผ๋•Œ ํƒ‘์นด๋“œ๋กœ ๋น„๊ตํ• ์ˆ˜์žˆ๊ฒŒ๋จ.)
  • ์ „๋ถ€ ๋‹ค ๋…ธํŽ˜์–ด์ธ๊ฒฝ์šฐ๋Š” ์ œ์ผ ํฐ ํƒ‘์นด๋“œ๋ฅผ ๊ฐ€์ง„ ๋…ธํŽ˜์–ด๋กœ ๊ณ„์‚ฐํ•œ๋‹ค. ***
  • ์ŠคํŠธ๋ ˆ์ดํŠธ๋‚˜ ํ”Œ๋Ÿฌ์‹œ์ธ๊ฒฝ์šฐ๋Š”, ํƒ‘์นด๋“œ๋ฅผ ๊ตฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋”ฐ๋กœ ๋งŒ๋“ ๋‹ค.
    • hands๊ฐ์ฒด์˜ PokerHands์†์„ฑ์ด ์ŠคํŠธ๋ ˆ์ดํŠธ๋ฉด ์ŠคํŠธ๋ ˆ์ดํŠธ ํŒจ์˜ ํƒ‘์นด๋“œ๋ฅผ ๊ตฌํ•˜๊ณ (์ด๊ฑด ScoreChecker์—์„œ ์ŠคํŠธ๋ ˆ์ดํŠธํ”Œ๋Ÿฌ์‹œ์ฒดํฌํ•˜๋Š”๋ฐ์„œํ•ด์•ผํ•จ)
    • PokerHands์˜ ์†์„ฑ์ด ํ”Œ๋Ÿฌ์‹œ์ด๋ฉด suit์„ ๋น„๊ตํ•ด์„œ ํƒ‘์นด๋“œ๋ฅผ ๊ตฌํ•œ๋‹ค.
      // hands.swift
      if self.PokerHands == .straight {
      card.sorted() // hands๋Š” cards๋ฅผ ๋ชจ๋ฅด๋‹ˆ๊นŒ sort๋Š” ScoreChecker์—์„œ ํ•ด์•ผํ• ์ง€๋„๋ชจ๋ฅด๊ฒ ๋‹ค......................
      }
      
  • ํ…Œ์ŠคํŠธ์ฝ”๋“œ์˜ ์ค‘์š”์„ฑ์„ ์•Œ์•˜๋‹ค : TDD์˜ ์ค‘์š”์„ฑ~~~

2018.01.26

  • ์žํŒ๊ธฐstep1
    • ์Œ๋ฃŒ์ˆ˜๋ผ๋ฆฌ ์ƒ์†์œผ๋กœ ๊ตฌํ˜„ํ•˜๊ณ  CustomStringConvertible๊ตฌํ˜„ํ•ด์„œ ์ถœ๋ ฅ
    • Dataํด๋ž˜์Šค ์‚ฌ์šฉ
  • ํ•™์—…๊ณ„ํš์„ ํšจ๊ณผ์ ์œผ๋กœ ์งœ๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค๊ณ  ํ•œ๋‹ค.
    • what: ๊ณต๋ถ€ํ•  ๊ฑฐ๋ฆฌ๋“ค
    • how long: ์–ผ๋งˆ๋‚˜ ๊ฑธ๋ฆด์ง€์˜ˆ์ƒ, ์–ธ์ œ๊นŒ์ง€ ํ• ๊ฑด์ง€
    • how to: ์–ด๋–ป๊ฒŒํ• ๊ฑด์ง€ - ์–ด๋–ป๊ฒŒ ๊ณต๋ถ€ํ• ๊ฑด์ง€์— ๋Œ€ํ•œ ํ™œ๋™๋“ค

2018.01.27

  • ์žํŒ๊ธฐ step1 ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜
    • MyDate๊ฐ์ฒด ์ƒ์„ฑ

2018.01.28

  • ์ผ์š”์ผ - ๋จธ์ง€ ๋˜์ง€ ์•Š์•˜์–ด๋„ ๋ฐฉํ•™์ด ์–ผ๋งˆ ์•ˆ๋‚จ์•˜๊ธฐ์— ๋ฏธ๋ฆฌ ์žํŒ๊ธฐ step2์ง„ํ–‰ํ•จ.

Comments