diff --git a/04 - Poker.playground/Contents.swift b/04 - Poker.playground/Contents.swift index 855b3ee..9ce6a06 100644 --- a/04 - Poker.playground/Contents.swift +++ b/04 - Poker.playground/Contents.swift @@ -7,12 +7,80 @@ */ /* EURE ANTWORT HIER + 1. only need one refernce to Card + 2. Enums eignen sich, weil es bei der Suit- und Rank-Auswahl mehrere Möglichkeiten gibt, welche sich gegenseitig ausschließen */ +import Foundation +enum Rank: Int, CustomStringConvertible { + case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace + var description: String { + switch self { + case .Ace: + return "Ace" + case .King: + return "Jack" + case .Queen: + return "Queen" + case .Jack: + return "King" + case .Ten: + return "Ten" + case .Nine: + return "Nine" + case .Eight: + return "Eight" + case .Seven: + return "Seven" + case .Six: + return "Six" + case .Five: + return "Five" + case .Four: + return "Four" + case .Three: + return "Three" + case .Two: + return "Two" + } + } +} +enum Suit: Int, CustomStringConvertible { + case Spades, Hearts, Diamonds, Clubs + var description: String { + switch self { + case .Spades: + return "U+2660" + case .Hearts: + return "U+2665" + case .Diamonds: + return "U+2666" + case .Clubs: + return "U+2663" + } + } +} +struct Card: CustomStringConvertible { + let suit: Suit + let rank: Rank + var description: String { + return "\(Rank.self) + \(Suit.self)" + } +} + +struct Pokerhand { + let cards: [Card] + var description: String { + return "\(Rank.self) + \(Suit.self)" + } +} +let rndSuit = Suit(rawValue: Int(arc4random_uniform(4)))! +let rndRank = Rank(rawValue: Int(arc4random_uniform(13)))! +let rndCard = Card(suit: rndSuit, rank: rndRank) //: ## Testing /* var rankingCounts = [Ranking : Int]() diff --git a/04 - Poker.playground/timeline.xctimeline b/04 - Poker.playground/timeline.xctimeline index 407a5d9..86c30ad 100644 --- a/04 - Poker.playground/timeline.xctimeline +++ b/04 - Poker.playground/timeline.xctimeline @@ -3,12 +3,12 @@ version = "3.0">