-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d891a84
commit d7c513d
Showing
5 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "O2PlayingCard" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# O2PlayingCard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
public struct O2PlayingCard { | ||
let rank: O2Rank | ||
let suit: O2Suit | ||
} | ||
|
||
|
||
// MARK: - Equatable | ||
|
||
extension O2PlayingCard: Equatable {} | ||
|
||
public func ==(lhs:O2PlayingCard, rhs: O2PlayingCard) -> Bool { | ||
return lhs.rank == rhs.rank && lhs.suit == rhs.suit | ||
} | ||
|
||
// MARK: - Comparable | ||
extension O2PlayingCard: Comparable {} | ||
|
||
public func <(lhs: O2PlayingCard, rhs: O2PlayingCard) -> Bool { | ||
return lhs.suit < rhs.suit || (lhs.suit == rhs.suit && lhs.rank < rhs.rank) | ||
} | ||
|
||
// MARK: - CustomStringConvertible | ||
|
||
extension O2PlayingCard: CustomStringConvertible { | ||
public var description: String { | ||
return "\(suit)\(rank)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
public enum O2Rank: Int { | ||
case Ace = 1 | ||
case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten | ||
case Jack, Queen, King | ||
} | ||
|
||
// MARK: - Comparable | ||
|
||
extension O2Rank: Comparable {} | ||
|
||
public func <(lhs: O2Rank, rhs: O2Rank) -> Bool { | ||
switch (lhs,rhs) { | ||
case (_, _) where lhs == rhs: | ||
return false | ||
case (.Ace, _): | ||
return false | ||
default: | ||
return lhs.rawValue < rhs.rawValue | ||
} | ||
} | ||
|
||
// MARK: - CustomStringConvertible | ||
|
||
extension O2Rank: CustomStringConvertible { | ||
public var description: String { | ||
switch self { | ||
case .Ace: | ||
return "A" | ||
case .Jack: | ||
return "J" | ||
case .Queen: | ||
return "Q" | ||
case .King: | ||
return "K" | ||
default: | ||
return "\(rawValue)" | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
public enum O2Suit: String { | ||
case Spades, Hearts, Diamonds, Clubs | ||
} | ||
|
||
// MARK: - Comparable | ||
|
||
extension O2Suit: Comparable {} | ||
|
||
public func<(lhs: O2Suit, rhs: O2Suit) -> Bool { | ||
switch (lhs, rhs) { | ||
case (_, _) where lhs == rhs: | ||
return false | ||
case (.Spades, _), (.Hearts, .Diamonds), (.Hearts, .Clubs), (.Diamonds, .Clubs): | ||
return false | ||
default: | ||
return true | ||
} | ||
} | ||
|
||
|
||
// MARK: - CustomStringConvertible | ||
extension O2Suit: CustomStringConvertible { | ||
public var description: String { | ||
switch self { | ||
case .Spades: | ||
return "♠︎" | ||
case .Hearts: | ||
return "♡" | ||
case .Diamonds: | ||
return "♢" | ||
case .Clubs: | ||
return "♣︎" | ||
} | ||
} | ||
} |