-
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
nik frank
committed
Apr 22, 2017
1 parent
6c690eb
commit 575b77f
Showing
3 changed files
with
49 additions
and
7 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 |
---|---|---|
@@ -1,25 +1,62 @@ | ||
export default [ | ||
{ | ||
name: 'pairs', | ||
hand: [ | ||
{ rank: 2, suit: 0 }, | ||
{ rank: 2, suit: 1 }, | ||
{ rank: 2, suit: 2 }, | ||
{ rank: 12, suit: 3 }, | ||
|
||
], | ||
cut: { rank: 2, suit: 3 }, | ||
value: 12, | ||
}, | ||
|
||
{ | ||
name: 'dibs', | ||
hand: [ | ||
{ rank: 4, suit: 0 }, | ||
{ rank: 2, suit: 1 }, | ||
{ rank: 6, suit: 2 }, | ||
{ rank: 11, suit: 3 }, | ||
|
||
], | ||
cut: { rank: 8, suit: 3 }, | ||
value: 1, | ||
}, | ||
|
||
{ | ||
name: 'four flush hand', | ||
hand: [ | ||
{ rank: 4, suit: 3 }, | ||
{ rank: 2, suit: 3 }, | ||
{ rank: 6, suit: 3 }, | ||
{ rank: 11, suit: 3 }, | ||
], | ||
cut: { rank: 8, suit: 2 }, | ||
value: 4, | ||
}, | ||
|
||
{ | ||
name: 'five flush hand', | ||
hand: [ | ||
{ rank: 4, suit: 3 }, | ||
{ rank: 2, suit: 3 }, | ||
{ rank: 6, suit: 3 }, | ||
{ rank: 10, suit: 3 }, | ||
], | ||
cut: { rank: 8, suit: 3 }, | ||
value: 5, | ||
}, | ||
|
||
{ | ||
name: 'five flush crib', | ||
hand: [ | ||
{ rank: 4, suit: 3 }, | ||
{ rank: 2, suit: 3 }, | ||
{ rank: 6, suit: 3 }, | ||
{ rank: 11, suit: 3 }, | ||
{ rank: 8, suit: 3 }, | ||
], | ||
value: 5, | ||
}, | ||
|
||
]; |
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 |
---|---|---|
@@ -1,17 +1,22 @@ | ||
// refactor into one big ugly reduce! [scoring fn, ..].reduce | ||
|
||
export default (hand, cut) => { | ||
export default (hand, cut = {}) => { | ||
const cards = hand.concat(cut); | ||
|
||
let total = 0; | ||
|
||
const dibsPts = hand.filter( ({ rank, suit }) => ((rank === 11) && (suit === cut.suit)) ).length; | ||
|
||
const cards = hand.concat(cut); | ||
|
||
const pairPts = cards.reduce( (p, c, i) => | ||
p + cards.slice(i + 1).filter( ({ rank }) => (rank === c.rank) ).length * 2, 0); | ||
|
||
|
||
const flushPts = (hand.reduce( (p, c) => (( p === c.suit ) ? p : -1), hand[0].suit) > -1) ? | ||
cards.filter( ({ suit }) => (suit === hand[0].suit) ).length : 0; | ||
|
||
total += dibsPts; | ||
total += pairPts; | ||
total += flushPts; | ||
|
||
return total; | ||
}; |
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