Coder Social home page Coder Social logo

mitch-b / typedeck Goto Github PK

View Code? Open in Web Editor NEW
38.0 2.0 5.0 2.28 MB

TypeScript library for playing cards

Home Page: https://mitch-b.github.io/typedeck/

License: MIT License

JavaScript 1.31% TypeScript 98.69%
card typescript playing-cards deckofcards poker-hands

typedeck's Introduction

TypeDeck TypeDeck

Build Status NPM version codecov dependencies Status devDependencies Status

A TypeScript library for playing cards.

Getting Started

Features

typedeck gives you types and classes to help jumpstart your card-based game.

  • Card
    • Simple card classes (PlayingCard/JokerCard)
  • Chip
    • Provided Chip classes and standard values
      • Values can be overridden, and custom Chip classes
  • Declarative Types
    • CardName: [Ace, Two, Three, ...]
    • Suit: [Clubs, Spades, Diamonds, Hearts]
  • Card collections
    • Classes that represent multiple cards as a logical item.
      • Hand - cards that belong to a player
      • CardPile - cards that are frequently drawn from or added to
      • Deck - extension of CardPile with additional game-time helpers
  • Services
    • Shuffle
      • Shuffle any ICard implementation
    • Poker Hand Scoring
      • Texas Hold Em Hand Detection
      • Winner scoring/determination
    • Chip management
      • Taking specific values
      • Creating chips from value
      • Breaking chips to get specific value
  • And so much more ... see the documentation for a full list.

Customization

Most features support parameters that implement either an interface or a base class. You can create your own type of Card that implements ICard or a Chip with special chip color values which extends Chip base class.

Credits

typedeck's People

Contributors

dependabot[bot] avatar episode17 avatar hailwood avatar mitch-b avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

typedeck's Issues

Complex chip splitting uses too much memory

I'm submitting a ...

  • bug report
  • feature request
  • question about the decisions made in the repository
  • question about how to use this project

Summary

Adding many chips then trying to retrieve a specific value experiences weird behaviors.

let chipService = new ChipService()
let chipCollection = new ChipCollection()
chipCollection
  .addChips(chipService.createChips(300))
  .addChips(chipService.createChips(67))
  .addChips(chipService.createChips(63))
  .addChips(chipService.createChips(87))

// long running => out of memory error
// however, I know that chips to equal 63 for sure have been added!
let pulledChips = chipCollection.takeValue(63)

Other information

(e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Need to fix ChipService.hasCombinationOfAmount to better determine which chips can be combined to equate requested amount. Need to improve the algorithm that checks each combination of chips to find the proper sum.

It could be that we're adding too much overhead by preserving chip values, instead of storing total chip value somewhere, and building chips on demand to match that value. We could consider that route - but preserving which chips you currently have seems to be more realistic.

Provide a "Color Up" service for chips

I'm submitting a ...

  • bug report
  • feature request
  • question about the decisions made in the repository
  • question about how to use this project

Summary

It would be nice to have a colorUp(chips) feature. This may be used constantly to improve the makeChange() calls, or on-demand. If it does significantly improve performance of makeChange, we may want to allow it as a flag when making change is requested. This would be a "destructive" action, so it shouldn't be the default.

Question about card images

Hi & thank you for this library!

In the Readme you give credits for card images but there are no images anywhere in this project. Is that a leftover?

What is the recommended way of adding card images? There is no implementation of ICardImageService either, should I start by writing an own implementation?

Missing Cards Used On PokerHandResult

I'm submitting a ...

  • bug report
  • feature request
  • question about the decisions made in the repository
  • question about how to use this project

Summary

Right now the cardsUsed propery on PokerHandResult is never populated.
This makes it difficult to work out more detail on the score. E.g. that player A scored Two Pair with Aces, whereas player B scored two pair with Threes.

Other information

I believe the fix for this is to update each new statement here to pass through ranked[0] as the third parameter https://github.com/mitch-b/typedeck/blob/master/src/services/pokerScore.service.ts#L160

And then updating the constructor here to pass use that parameter the same as cards.
https://github.com/mitch-b/typedeck/blob/master/src/models/poker/pokerHandResult.model.ts#L27

Additional Request

While doing this, could we get an additional kickers property added to output the additional information e.g. instead of just Two Pair it would be great if we could go

`${score.toString()} ${score.kickers}`

To get Two Pair Ace Two

Those where the kicker is not relevant should just return an empty string..

Invalid Hand Calculations?

I'm submitting a ...

  • bug report
  • feature request
  • question about the decisions made in the repository
  • question about how to use this project

Summary

Hey @mitch-b,

It looks like we might have an issue with calculating the winning hands.
I only came across this last night at about 1am... so I haven't had a chance to debug it properly, so I'll provide some more information or a PR to fix it tonight but figure depending on your timezone you might get there first. This is using the new poker-hand-details branch, so I'm not sure if it's on the main branch yet.

Try running this game through:

Community cards: 7S 3S 4C 5H 6D
Player 1's name and two cards: Bob 2C 8D
Player 2's name and two cards: Joe 8S 9C

Result:
1 Joe High Card Nine
2 Bob High Card Eight

...what? Shouldn't that be a straight for both players?

`${result.toString()} ${result.scoringHandCardNames.map(cn => CardName[cn]).join(' ')}`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.