Virtual deck of cards using just a browser
playingcards.io
playingcards.io
The tech stack is Nodejs, MongoDB, Redis, Socket.io, and React + Redux on the frontend.
It's actually been a pet project for a long time (6+ years) but I've been taking it more seriously since Jan 2020. Fun fact: the original was built with Backbone.js and CoffeeScript.
Happy to answer some questions and please let me know your feedback too.
And follow us on Twitter for updates: https://twitter.com/playingcardsio
I've also just added PlayingCards.io to my website[1] of multiplayer games that require no user accounts :)
[0] https://playingcards.io/docs/ [1] https://quickparty.games
I remember back in the Google Wave days I created a connect four game where no turns were enforced, and you could take out the chips of the opponent if you saw that they cheated. A Google engineer was a bit irritated by that, she expected that it was turn based and pointed it out as a flaw.
Maybe you could add a feature which shakes the entire table so that the cards/boards end up in a state where continuing doesn't make much sense, like when you push away the board IRL because you noticed that you lost.
Aaah! The old STEM education in full effect. Beautiful example. No creative thinking on their part whatsoever.
just the other day I was wondering what happened to older Javascript frameworks like Backbone.
Can you elaborate why you moved from Backbone to React / Redux? As of what I recall, Backbone was extremely stable and a lot of companies used it in very heavy web apps as well.
Since, the 2D board games of the type on your site doesn't seem to require heavy front-end lifting (I might be completely wrong here), I'm curious to know the reason behind switching to a newer technology which is still riding the hype wave.
Thanks. And of course, the site is very nice. Will be sharing it with my colleagues for our Friday online hangouts!
1. Having nested DOM elements in your components. Backbone really wanted you to just have one element per component, and then use jQuery to add children as needed.
2. Adding event handlers and other HTML attributes. JSX syntax means you can basically write HTML in your JS file. Backbone made you add event handlers manually.
3. Nested components. React lets the parent simply specify what children it wants and React automatically creates/reuses/destroys component instances for you. This was all manual in Backbone.
The bigger advantage though, is how the state is typically organized in React apps.
In Backbone, app state was sprinkled throughout the component hierarchy, and often you would have do event spaghetti up and down the hierarchy to update some state held by another component.
Typical React apps use a state container like Redux, the UI is "projected" from the state, and components just send changes to the state, aka "unidirectional data flow".
That said, React is not the best for games. Maintaining 60 fps can be difficult and we've done some fairly heavy optimization to try to keep it smooth.
Have you see SvelteJs? Would that be better suited in this scenario?
> Pinochle uses a unique 48 card deck that consists of 2 sets of 9, 10, J, K, Q, K, A in each suit.
http://www.lauradhamilton.com/random-lessons-online-poker-ex...
The other interesting aspect about card shuffling is how more shuffling than necessary might make the end result worse
https://blog.codinghorror.com/the-danger-of-naivete/
edit: changed to 'seed' as mentioned below, reframed blog post
The first algorithm that would occur to me would be take a pile of 52 cards, and repeatedly pick cards randomly to place into a new pile that eventually has 52 cards.
Though I suppose that's the kind of thing that's trivial to program in scripting languages with arrays that are easy to remove a middle item from, and less so in a classic algorithmic language like C.
Shuffling into a new pile is not that it is hard to do in C, just move items from one linked list to another.
But if it can be done with a simple array saving memory then why not.
(in fact, there's both obvious and interesting information preserved by a single riffle shuffle... which is why you need to shuffle multiple times in real life. It would be cool if the site emulated a riffle shuffle, so you'd need to shuffle seven-ish times to get close to a uniformly random permutation.)
But just randomly picking from a pile seems pretty easy to write correctly. No? And if you have an off-by-one error, your deck of 52 cards gets turned into 51, so it's not like you won't catch it...
It's not likely to matter much if you're only shuffling 52 cards, but if you're writing a general-purpose shuffle algorithm, there's no reason to needlessly make it inefficient.
When moving cards from one side to the other a lot of elements will have to be moved around. But for small n it should be much faster than using linked lists. And also relatively easy to implement in C.
The shifting of elements when inserting can be avoided by only swapping two positions. (ABXDEFC instead of ABXCDEF, when inserting X into ABCDEF). But by then you have just reinvented Fisher-Yates.
So the swapping in some of these algoritms is basically an implementation of your idea.
This is a perfect description of the Fisher–Yates shuffle – the standard you should reach for when shuffling, and what the latter article suggested, too.
Of course, as a technical implementation detail, instead of having two actual arrays, you can use one array and swap within it to get the effect of two arrays, except in one for performance.
I suggest you reread your linked article. The fault is in using a 32-bit SEED.
Random shuffling algorithms are trivial and well known [0]. It really doesn't need some click-bait blog posts.
https://hackernoon.com/how-does-javascripts-math-random-gene...
There are a lot of existing games already in the system and plenty more shared on the reddit group: https://www.reddit.com/r/PlayingCardsIO/
Also there is an open-source clone available: https://virtualtabletop.io/
And somewhat related, /r/digitaltabletop has a huge list of options to play games online: https://www.reddit.com/r/digitaltabletop/comments/gg4sfx/big...
(Discussed here previously: https://news.ycombinator.com/item?id=10164513)
If everyone has build/played similar games, let me know.
The best thing is how you can import card data as a CSV.
I’ve been prototyping a card game with it and have a few command line scripts to go from an Indesign deck to a fully working play-testable game in under a minute.
We use Firebase for Auth and file storage only. Game updates are sent through Socket.io in order to have better control over them, and also Firebase charges per update which is a lot for games.
Yes this looks nice! Though I was also thinking of a way to just upload images that can then be used.
Note that some games like Checkers have the hand turned off by default.
I've been wanting to build and play on a "open world" deck of cards game.
Now I now I can play without creating it first and I won't have to waste my time creating kt only to find out later that someone else had already done it.
https://gist.github.com/numtel/576d7fae916b8190dec8dc64ac40f...
Obviously that idea came before the pandemic.
Words With Friends is now too hard for her. Too many distractions. I've been looking for alternatives with no success.
Very excited to try this out. Thank you!
Also, it doesn't enforce who's turn it is.
You can tell your opponent ‘oi your turn!’ using your preferred platform.
I think this could actually be a feature. In a real game, the players self-enforce the turns, and when someone gets distracted and plays out of turn, it's hilarious to banter while setting things straight again. Of course that would need the videocall part.
As long as all the moves are logged, you can enforce the rules by yelling at people.
Magic does have the problem that sometimes, in specific edge cases, players can disagree about what should happen based on the rules. It's hard to come to consensus via the yelling at people protocol.
But I do agree it was great. And free.
There's a threshold that objects need to be dragged beyond to start moving, which is different for touch/mouse.
Also, what device/OS are you using?
It's not very often, but accidentally flipping a card just once is a very bad for a game.