Closed Arniox closed 2 years ago
At the moment, I am using something like this:
//Draw cards from deck
const allCards = (await axios.get(`https://deckofcardsapi.com/api/deck/${this.deck.deck_id}/draw/?count=${this.deck.remaining}`)).data,
cardIdsPrior = allCards.map(v => v.code),
cardIdsAfterShuffle = cardIdsPrior.shuffle();
//Enter cards backinto deck
const shuffledOldDeck = await axios.get(`https://deckofcardsapi.com/api/deck/${this.deck.deck_id}/shuffle/?cards=${cardIdsAfterShuffle.join(',')}`);
//Update deck
this.deck = shuffledOldDeck.data;
But this still results in the entire deck getting shuffled and all the piles being deleted.
Unfortunately, I'm not working on large features for this project anymore. Mostly just doing maintenance stuff, but I do accept PRs if you want to figure out how to add it yourself. Otherwise a couple workarounds I can think of: 1) Keep track of it locally. If you need to turn the discard pile into the main draw pile, you can create an array locally, shuffle it, and just have a boolean flag indicating that instead of drawing with the api, to draw from the array. Of course, once you start doing that, you may be tempted to just do everything locally, rather than using the API. 2) You could create a temporary "partial deck" specifying the cards from the discard pile. ie: https://deckofcardsapi.com/api/deck/new/shuffle/?cards=AS,2S,KS,AD,2D,KD,AC,2C,KC,AH,2H,KH And from that deck, shuffle and draw cards. Although, when moving cards to various piles, you may have to do some operations on both decks at the same time to make sure that they both stay in sync.
Ok, I was thinking about possibly making my own cards system/API anyways. I'll have a look at your code and see if I can easily add these systems or not
I'm happy to look at implementing this for a PR or two, but so that I'm clear about the functionality changes, is it ok to make these changes?
The first change looks like it would be a breaking change, so if people have already written their card game, and the API changed to not shuffle all the cards, then this would break people's code, which I'd rather not do.
I think the easiest way to implement this would be to just add the ability to draw random cards from Piles. I think this could be done relatively simply (and could be useful for people playing Old Maid).
Good point. Maybe either another API endpoint or adding a parameter to the shuffle endpoint could do it.
I've started taking a look - this is my first commit on my fork to allow the remaining deck stack to be shuffled only with a remaining=true parameter: https://github.com/jmb/deckofcards/commit/8a6002c0ae0786a3ad287dfa1fa2c69f0a8ab163
There are a few places that things could be refactored as well I think.
I've now added the functionality to allow random cards to be drawn from piles: https://github.com/jmb/deckofcards/commit/7dd528fb107534af6412e7bd839555bd3e85c3ee
I'll next look to allow cards to be replaced into the main deck.
Final (hopefully!) PR #107 to tidy everything up!
I'm creating a game in discord and it is going well. But I need 2 things:
Thanks