crobertsbmw / deckofcards Goto Github PK
View Code? Open in Web Editor NEWAn API to simulate a deck of cards
License: MIT License
An API to simulate a deck of cards
License: MIT License
Using this script for a demo, the API calls worked fine for new decks and card draws, but got an error each time we tried to run shuffle.
Getting this error:
bash: https://deckofcardsapi.com/api/deck/yacpsah3sxzx/shuffle/: No such file or directory
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 !
Hi. I think the CORS headers on your web server do not allow me to use the API. I'm trying to use https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1 and https://deckofcardsapi.com/api/deck/<<deck_id>>/draw/?count=2 endpoints.
Please help me, I'm working in a job test and depending on this issue.
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?
in the final section: A Partial Deck
, Seperete the cards
should become Separate the cards
.
Currently, you can add a card to multiple piles. This should not be allowed. This can be replicated like the following:
pile1
pile2
You will see the card in both piles using `api/deck/<<deck_id>>/pile/<<pile_name>>/list
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
}
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.
http://deckofcardsapi.com/static/img/8CLUBS.png
I'm seeing a blank page that says "Your 404 page"
Also, you've got DEBUG on, so the server is spitting out some debug info for broken paths. Particularly /static
doesn't seem to work:
I'm trying to add a card to pile...
Request: http://deckofcardsapi.com/api/deck/rt3ge4ytwfew/pile/discard/add/?cards=2S,KS
Response: {"remaining": 52, "deck_id": "rt3ge4ytwfew", "success": true, "piles": {"discard": {"remaining": 0}}}
Should "remaining" be 2 and not 0?
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.
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.
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:
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.
Hello,
I am using your API for a project, but the server appears to be down.
Could you check this for us?
Thank you!!
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.
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?
For a two player game, how do you see your own cards, but hide them from the other player?
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.
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"
curl "https://deckofcardsapi.com/api/deck/tyx9b4bo0h5c/pile/pile1/shuffle?cards=AS,2S,2C,KC,AH,2H,KH"
curl "https://deckofcardsapi.com/api/deck/tyx9b4bo0h5c/pile/pile1/list?cards=AS"
curl "https://deckofcardsapi.com/api/deck/tyx9b4bo0h5c/pile/pile1/draw/?cards=AS"
After creating a partial deck using the request /api//shuffle will result in a new, 52 card, deck.
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:
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
Tried navigating directly to the cards url and received 404 for all 10's in the deck
https://deckofcardsapi.com/static/img/10H.png
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.
Hey very nice api you got here! I also made pyramid solitaire using this API here: https://henrikra.github.io/pyramid-solitaire/
One thing I noticed is that the deck of cards documentation does not say anything about errors. Could they be documentated also? :)
In testing, both http
and https
requests work and return the image as expected. However, either the response or the docs need to be updated to reflect each other.
Demo API Server(http://deckofcardsapi.com/api/deck/) is down with HTTP 500 response.
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?
When calling the /shuffle/<deck_id>
endpoint with a bogus deck_id
, I'd expect to get a response indicating a 404 or similar. Currently, doing this results in a 500 response. This seems unexpected.
I would be great to see CORS headers added, to allow client-side API access
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
Line 57 in 1531ede
Line 64 in 1531ede
Really digging this API. Thanks for all this.
Quick question.
How do you go about drawing a card from the bottom of a pile or shuffling the cards in a pile? I can't find any documentation for that.
I've tried this:
https://deckofcardsapi.com/api/deck/<<deck_id>>/pile/<<pile_name>>/shuffle/
https://deckofcardsapi.com/api/deck/<<deck_id>>/pile/<<pile_name>>/draw/bottom
Thank you.
-Jake
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.
See for yourself. It's a simple fix. ;)
https://github.com/crobertsbmw/deckofcards/blob/master/static/400.html
I've got 51 of the 52 cards now loading correctly. Just one still returns a CORS error at test-cors.org:
https://deckofcardsapi.com/static/img/AD.png
Don
In Germany we have a bunch of card games which require only a subset of the normal card decks:
It would be nice to support having a subset of the cards
Failed to load https://deckofcardsapi.com/api/deck/ibnhgqxo0lxn/draw/?count=undefined: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://palmpa76.beget.tech' is therefore not allowed access. The response had HTTP status code 500.
GET https://deckofcardsapi.com/api/deck/ibnhgqxo0lxn/draw/?count=undefined 500 ()
Hi, this API is really cool. Is it possible to add a picture, or many, for the back of cards ?
Originally posted by @R4N4R4M4 in #42 (comment)
Posted as a HN comment but thought it might worth an issue -
SVG cards might reduce bandwidth use for you and clients - https://code.google.com/p/vectorized-playing-cards/
For example, 8 of Clubs is:
I'd suggest you change your random function.
I'm not a pythonist myself, but something that seeds from urandom would be better. https://docs.python.org/3/library/os.html#os.urandom
AdBlock hides img if source is Ace of Diamonds (http://deckofcardsapi.com/static/img/AD.png)
Just to let you know
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?
Fix this:
A Partial Deck:
http://deckofcardsapi.com/api/deck/shuffle/?cards=AS,2S,KS,AD,2D,KD,AC,2C,KC,AH,2H,KH
to
A Partial Deck:
http://deckofcardsapi.com/api/deck/<<deck_id>>shuffle/?cards=AS,2S,KS,AD,2D,KD,AC,2C,KC,AH,2H,KH
Nice API!
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/
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.