GithubHelp home page GithubHelp logo

crobertsbmw / deckofcards Goto Github PK

View Code? Open in Web Editor NEW
1.3K 30.0 306.0 8.25 MB

An API to simulate a deck of cards

License: MIT License

Python 18.69% HTML 11.95% CSS 23.88% JavaScript 42.90% Dockerfile 0.13% SCSS 2.44%

deckofcards's People

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  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  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  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

deckofcards's Issues

Piles should have to be clear when the deck is shuffled

Hello !
Apologize in advance for writing, i'm french !

When a deck is shuffled, all his cards come back in it,
but piles are not cleared, so we can have duplicated cards in both deck and pile
is it normal ?

Thank you !

Separate shuffling from deck creation (allow un-shuffled decks) and support for shuffle strategies

Should allow creation of an un-shuffled deck in a "standard" order. I actually think wrapped decks have a particular ordering which has Hearts/Clubs in reverse order and to the Spades/Diamonds. Other ordering might follow Spades->Diamonds->Clubs->Hearts hierarchy ordered either 2->A, or A-K... not sure if this is different in different regions.

Also there could be different shuffling strategies which could be useful (or not) to a game utilizing the tool.

Solitaire Game example:

  • You start with an un-shuffled deck and press Go
  • Shuffling algorithm(s) are applied to the deck and then you do a draw from the top Time Memory game where your ability to track the cards after shuffling gets you better scores

Kind of weak, but I just thought of it as I was typing and could be valid.

Another version would be a Blackjack game that actually encourages (or teaches) card counting and uses some observed shuffling strategies (usually something to do with a separator in the shoe which tells them to shuffle everything again) to make it as realistic as possible.

Should be able to list cards not in any pile

When cards are drawn they are not in any pile (deck.stack or created pile). If the list of cards in no man's land could be listed this could help with placing certain cards. This would also be beneficial for restoring application state at a later time.

This could also, be useful in solving #41. If there is a way to list drawn cards that are in no pile then a case can be made that only drawn cards can be placed into a pile.

Another bonus is that this may bring the ability to add and manipulate piles to cases when multiple decks are being used.

Adding to Piles doesn't work properly when deck_count > 1.

If you create a deck with deck_count > 1, adding to a pile will return success but remaining will equal 0. You are unable to draw from the pile as well. I'm somewhat new to this, so I may be wrong, but after some testing and looking at the views.py I think the bug is in this line:
cards = [x for x in cards.split(',') if x not in deck.stack and x in CARDS]

When it checks that the card isn't in the deck.stack, it is finding the other copies of the card and then not adding the card to the pile. If you create a deck with deck_count 2 and repeatedly draw a single card and add it to a pile, the pile will return success but remain empty until you add the second copy of a card. Since the first copy has already been drawn from the deck, it then correctly adds to the pile.

Should not be able to add cards to multiple piles

Currently, you can add a card to multiple piles. This should not be allowed. This can be replicated like the following:

  1. Create new deck
  2. Draw a number of cards from the deck
  3. Add a card to pile1
  4. Add the same card to pile2

You will see the card in both piles using `api/deck/<<deck_id>>/pile/<<pile_name>>/list

piles -- "add" is really "create"?

Lets say I've added 3 cards to a pile earlier, and now call /deck/{deckid}/pile/{pilename}/add again, but with a single freshly drawn card from the deck -- {pilename} really just gets overwritten with that single new card, correct?

Internal Server Error 500 when adding cards to pile.

Hello, lately with the new changes I haven't been able to add cards to a pile after drawing them.

I have a partial deck with 21 cards, I draw all 21 cards from the deck and then try to add them to a pile and this is when I get an internal server error 500.

This process was working before the changes. I was wondering if there's something on my end that I should be changing to make this work again?

Consider using deck size

Hello,
I am looking for such API as yours and I have an idea of a game.
Though, there are games that use less then 52 cards in the deck.
I think that it will be reasonable to add maybe optional deck_size parameter to /deck/new/

Getting an error 500

We are using your API for a webApp and it seems like any request is sending us an error 500. Could you please help us, we are bootcamp trainees with our Demo day in 4 days.

Support Non-standard decks

Pinochle uses a 48 card deck, and Euchre uses a 28 or 32 card deck.

When creating a deck you should also be able to specify the set of cards to include in your deck... using either standard sets or a custom mapping of how many of each standard card you want to include, possibly also with options for "jokers" or "wildcards" that other people have mentioned.

Add players

Hmm, not sure if useful, but what about tracking which card is where? Possible states - in deck (no state), in hand (of player ID), in game (by player ID), discarded.

Nice API, BTW.

OpenAPI or Postman

Have you ever considered providing an OpenAPI/Swagger/Postman implementation for this? If I get some time I'd consider creating a PR for it.

Support different CARDS

In Germany we have a bunch of card games which require only a subset of the normal card decks:

  • Doppelkopf (9, 10, J, Q, K, A, but two of those decks)
  • Skat (7-10, J, Q, K, A)

It would be nice to support having a subset of the cards

DRY, KISS, SOLID rules

Hi!

I am fan of poker and I think your work is great. IMO we can do some work to improve this app.
This app contains a lot of duplicated lines of code like

response = HttpResponse(json.dumps({'success':False, 'error':'Deck ID does not exist.'}), content_type="application/json", status=404)
if/else if/ combinations like
if value+suit == "AD":
or try / except blocks in not necessary places. What do You think about refactoring these methods? We can move duplicated code to separate methods, create new modules for helpers, move constants to separate file. I can do this job.

Bug: Can't add cards to pile

The functionality to add cards to a pile isn't working anymore.
The service still detects if a pile exists but doesn't add any cards to it.

image

CORS

I would be great to see CORS headers added, to allow client-side API access

Web server is down

Hello,

I am using your API for a project, but the server appears to be down.
Could you check this for us?

Thank you!!

Tarot?

I'm really excited to learn of this API! I would like to fork it to create a Tarot reading API, would you mind? Alternately, I could PR this one to allow for card types - tarot, or standard?

Typo on the website

in the final section: A Partial Deck, Seperete the cards should become Separate the cards.

Response example in 'Draw a Card' website documentation is missing a comma

Sorry about being a pedant but this was giving me some funny errors in my unit testing (I C/Ped the example straight into my tests)

{
    "success": true,
    "cards": [
        {
            "image": "http://deckofcardsapi.com/static/img/KH.png",
            "value": "KING",
            "suit": "HEARTS" <---- Missing a comma here
            "code": "KH"
        },
        {
            "image": "http://deckofcardsapi.com/static/img/8C.png",
            "value": "8",
            "suit": "CLUBS",
            "code": "8C"
        }
    ],
    "deck_id":"3p40paa87x90",
    "remaining": 50
}

CORS settings

Hi,

I was trying to load a card image in JavaScript, but I think the CORS headers on your web server do not allow this.

Here are 2 .png files I tried:

https://raw.githubusercontent.com/petercpark/Mindless-Rubik-s-Cube-Solution/master/rubikscube.png
https://deckofcardsapi.com/static/img/KH.png

The 1st loads fine from JavaScript, but the 2nd fails when I try to load it from JavaScript. Here is the URL I used to test CORS headers for these 2 .png files:

https://www.test-cors.org/

I just pasted each URL into the Remote URL box. The JavaScript framework I am using is p5.js, but I don't think the framework is the source of this particular problem since the CORS headers test fine for the rubikscube.png file and that file loads fine in p5.js, but the KH.png file fails the CORS headers test and will not load in p5.js using loadImage.

Don Braffitt

Unable to get response from some APIs

Hi @crobertsbmw !

First off, thanks for contributing this wonderful project to open source, I'm learning how to write API clients using this API ๐Ÿ‘

I'd like to report that I'm not able to get the noted response from certain APIs

an example deck-id generated via curl "https://deckofcardsapi.com/api/deck/new/" is tyx9b4bo0h5c upon which I apply the add cards to pile api call like the following

curl "https://deckofcardsapi.com/api/deck/tyx9b4bo0h5c/pile/pile1/add/?cards=AS,2S,2C,KC,AH,2H,KH"
  • Shuffle piles
curl "https://deckofcardsapi.com/api/deck/tyx9b4bo0h5c/pile/pile1/shuffle?cards=AS,2S,2C,KC,AH,2H,KH"


  • Listing cards in a pile
curl "https://deckofcardsapi.com/api/deck/tyx9b4bo0h5c/pile/pile1/list?cards=AS"

  • Drawing from piles
curl "https://deckofcardsapi.com/api/deck/tyx9b4bo0h5c/pile/pile1/draw/?cards=AS" 

Error behavior for empty decks / counts that are too large

Copying from HN:

Pretty cool! Love that theres no authentication and I can start straight from curl.

Nit: drawing from an empty deck does not throw an error:

> curl http://deckofcardsapi.com/api/draw/i763hn8lcg0e/ 
{"remaining": 0, "cards": [], "deck_id": "i763hn8lcg0e", "success": true}

As does drawing a comically large number of cards:

> curl http://deckofcardsapi.com/api/draw/vzlem7q4jhna/?count=10000
... (...) "success": true}\n

i think both of these should throw errors, or at least return success: false. thoughts?

Not able to list piles.

When I try to list a pile I get this error.

"The requested URL /api/deck/0cwtkus4fju6/pile/Jugador1/list was not found on this server."

Can enyone tell me how to solve it?

Thanks.

Add a License

What's your intention with this project? Just something to play with and show off while learning?

If so, give it an open license so people know.

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.