https://github.com/daniel-beard/swiftpokerhands
A simple five card poker hand classifier
https://github.com/daniel-beard/swiftpokerhands
classifier poker swift
Last synced: 11 months ago
JSON representation
A simple five card poker hand classifier
- Host: GitHub
- URL: https://github.com/daniel-beard/swiftpokerhands
- Owner: daniel-beard
- License: mit
- Created: 2015-09-05T18:51:24.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2021-05-08T18:27:49.000Z (about 5 years ago)
- Last Synced: 2025-02-05T01:27:52.705Z (over 1 year ago)
- Topics: classifier, poker, swift
- Language: Swift
- Size: 31.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftPokerHands 
A simple five card poker hand classifier
### Examples:
##### Identifying a hand rank
```swift
let cards = [
Card(rank: .four, suit: .hearts),
Card(rank: .five, suit: .diamonds),
Card(rank: .six, suit: .clubs),
Card(rank: .seven, suit: .spades),
Card(rank: .eight, suit: .hearts),
]
let hand = PokerHand(cards: cards)
print(hand.handRank()) // straight
```
##### Comparing two hands
```swift
let cards = [
Card(rank: .four, suit: .hearts),
Card(rank: .four, suit: .diamonds),
Card(rank: .five, suit: .hearts),
Card(rank: .five, suit: .hearts),
Card(rank: .six, suit: .hearts),
]
let cards2 = [
Card(rank: .five, suit: .hearts),
Card(rank: .five, suit: .hearts),
Card(rank: .seven, suit: .hearts),
Card(rank: .six, suit: .hearts),
Card(rank: .six, suit: .clubs),
]
let hand = PokerHand(cards: cards)
let hand2 = PokerHand(cards: cards2)
print(hand < hand2) // true
```
##### Other Examples
```swift
let cards = [
Card(rank: .four, suit: .hearts),
Card(rank: .four, suit: .diamonds),
Card(rank: .five, suit: .hearts),
Card(rank: .five, suit: .hearts),
Card(rank: .six, suit: .hearts),
]
let cards2 = [
Card(rank: .five, suit: .hearts),
Card(rank: .five, suit: .hearts),
Card(rank: .seven, suit: .hearts),
Card(rank: .six, suit: .hearts),
Card(rank: .six, suit: .clubs),
]
let cards3 = [
Card(rank: .four, suit: .hearts),
Card(rank: .five, suit: .diamonds),
Card(rank: .six, suit: .clubs),
Card(rank: .seven, suit: .spades),
Card(rank: .eight, suit: .hearts),
]
let hand = PokerHand(cards: cards)
let hand2 = PokerHand(cards: cards2)
let hand3 = PokerHand(cards: cards3)
print(hand < hand2) // true
print(hand2.handRank()) // twoPair
print(hand.suits) // [Suit.diamonds: 1, Suit.hearts: 4]
print(hand.handRank()) // twoPair
print(hand3.handRank()) // straight
```
### License
MIT