Skip to content

Commit

Permalink
run pattern algo
Browse files Browse the repository at this point in the history
  • Loading branch information
nik frank committed Apr 23, 2017
1 parent a46b18b commit 4fd0836
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion canon/crib/src/util/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default [
{
name: 'four run',
hand: [
{ rank: 8, suit: 2 },
{ rank: 7, suit: 2 },
{ rank: 10, suit: 3 },
{ rank: 11, suit: 2 },
{ rank: 12, suit: 3 },
Expand Down
29 changes: 29 additions & 0 deletions canon/crib/src/util/score.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,39 @@ export default (hand, cut = {}) => {

const flushPts = (hand.reduce( (p, c) => (( p === c.suit ) ? p : -1), hand[0].suit) > -1) ?
cards.filter( ({ suit }) => (suit === hand[0].suit) ).length : 0;


const runPattern = cards.sort((a, b) => (a.rank < b.rank) ? -1 : 1)
.map( (c, i, arr) => Math.min((arr[i+1] || {rank: NaN}).rank - c.rank, 2) )
.filter( n => !isNaN(n) ).join('').split('2')
.filter( d => (d.length > 1) )[0];

const runPts = {
'11': 3,
'011': 6,
'101': 6,
'110': 6,

'111': 4,
'1110': 8,
'1101': 8,
'1011': 8,
'0111': 8,

'1111': 5,
'1100': 9,
'1001': 9,
'0011': 9,

'0101': 12,
'0110': 12,
'1010': 12,
}[runPattern] || 0;

total += dibsPts;
total += pairPts;
total += flushPts;
total += runPts;

return total;
};

0 comments on commit 4fd0836

Please sign in to comment.