Skip to content

Commit

Permalink
Support ASCII card names as well as Unicode. All of our image resourc…
Browse files Browse the repository at this point in the history
…es are based on the card.toString, so tweak those where necessary.
  • Loading branch information
CharlieHess committed Sep 1, 2015
1 parent c5a9d55 commit 7ea08b4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class Card {
toString() {
return `${this.rank}${Card.SuitMapping()[this.suit]}`;
}

toAsciiString() {
return `${this.rank}${this.suit.substring(0, 1).toLowerCase()}`;
}

static Ranks() {
return ['2', '3', '4', '5', '6', '7', '8','9', 'T', 'J', 'Q','K', 'A',];
Expand Down
4 changes: 4 additions & 0 deletions src/deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class Deck {
toString() {
return this.cards.join();
}

toAsciiString() {
return this.cards.map(card => card.toAsciiString()).join();
}
}

module.exports = Deck;
4 changes: 2 additions & 2 deletions src/hand-evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HandEvaluator {

for (let player of players) {
let sevenCardHand = [...playerHands[player.id], ...board];
let evalInput = sevenCardHand.map(card => card.toString());
let evalInput = sevenCardHand.map(card => card.toAsciiString());
let currentHand = pokerEvaluator.evalHand(evalInput);

if (currentHand.handType > bestHand.handType ||
Expand Down Expand Up @@ -59,7 +59,7 @@ class HandEvaluator {
let cardArray = null;

for (let fiveCardHand of fiveCardHands) {
let evalInput = fiveCardHand.map(card => card.toString());
let evalInput = fiveCardHand.map(card => card.toAsciiString());
let currentHand = pokerEvaluator.evalHand(evalInput);

if (currentHand.handType > bestHand.handType ||
Expand Down
2 changes: 1 addition & 1 deletion src/image-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ImageHelpers {
// image, or `onError` if anything goes wrong
static createBoardImage(cards, upload=imgur.uploadFile) {
let subj = new rx.AsyncSubject();
let imageFiles = cards.map((c) => `resources/${c}.jpeg`);
let imageFiles = cards.map((c) => `resources/${c.toAsciiString()}.jpeg`);

if (!fs.existsSync('./output')) {
fs.mkdirSync('./output');
Expand Down
6 changes: 4 additions & 2 deletions tests/deck-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ describe('Deck', function() {

it('should be printable', function() {
var deck = new Deck();
var deckString = '2♠,3♠,4♠,5♠,6♠,7♠,8♠,9♠,T♠,J♠,Q♠,K♠,A♠,2♥,3♥,4♥,5♥,6♥,7♥,8♥,9♥,T♥,J♥,Q♥,K♥,A♥,2♦,3♦,4♦,5♦,6♦,7♦,8♦,9♦,T♦,J♦,Q♦,K♦,A♦,2♣,3♣,4♣,5♣,6♣,7♣,8♣,9♣,T♣,J♣,Q♣,K♣,A♣';
var unicodeDeck = '2♠,3♠,4♠,5♠,6♠,7♠,8♠,9♠,T♠,J♠,Q♠,K♠,A♠,2♥,3♥,4♥,5♥,6♥,7♥,8♥,9♥,T♥,J♥,Q♥,K♥,A♥,2♦,3♦,4♦,5♦,6♦,7♦,8♦,9♦,T♦,J♦,Q♦,K♦,A♦,2♣,3♣,4♣,5♣,6♣,7♣,8♣,9♣,T♣,J♣,Q♣,K♣,A♣';
var asciiDeck = '2s,3s,4s,5s,6s,7s,8s,9s,Ts,Js,Qs,Ks,As,2h,3h,4h,5h,6h,7h,8h,9h,Th,Jh,Qh,Kh,Ah,2d,3d,4d,5d,6d,7d,8d,9d,Td,Jd,Qd,Kd,Ad,2c,3c,4c,5c,6c,7c,8c,9c,Tc,Jc,Qc,Kc,Ac';

assert(deck.toString() === deckString);
assert(deck.toString() === unicodeDeck);
assert(deck.toAsciiString() === asciiDeck);
});
});

0 comments on commit 7ea08b4

Please sign in to comment.