Programming questions involving digitally-represented playing cards. This includes issues like representing cards and decks in data structures, user interfaces for manipulating cards in a virtual fashion, implementing correct algorithmic shuffling, and using cryptographically secure protocols to exchange cards over a network. Please browse this tag with your target language (e.g. [java] [playing-cards]) to see if your question has been asked before!
Questions tagged [playing-cards]
324 questions
78
votes
2 answers
How to initialize a static array?
I have seen different approaches to define a static array in Java. Either:
String[] suit = new String[] {
"spades",
"hearts",
"diamonds",
"clubs"
};
...or only
String[] suit = {
"spades",
"hearts",
"diamonds",
"clubs" …

Jeremy S.
- 6,423
- 13
- 48
- 67
40
votes
9 answers
7 Card Poker Hand Evaluator
Does anyone know a fast algorithm for evaluating 7 card poker hands? Something which is more efficient than simply brute-force checking a every 21 5-card combination of hands from a set of 7.
Cheers,
Pete
user130076
20
votes
6 answers
Cryptography for P2P card game
I'm considering writing a computer adaptation of a semi-popular card game. I'd like to make it function without a central server, and I'm trying to come up with a scheme that will make cheating impossible without having to trust the client.
The…

so12311
- 4,179
- 1
- 29
- 37
16
votes
5 answers
Python: 'object in list' checks and '__cmp__' overflow
this is my first time at stack overflow so I'm sorry if the format doesn't fit quite right with the site.
I just recently started learning programming, almost 2 weeks have passed since. I'm learning python from…

Ulquiomaru
- 736
- 6
- 9
15
votes
9 answers
Card Shuffling in C#
I am trying to write a code for a project that lists the contents of a deck of cards, asks how much times the person wants to shuffle the deck, and then shuffles them. It has to use a method to create two random integers using the System.Random…
Jeff
13
votes
5 answers
How to really shuffle a deck of cards
When I need to shuffle a deck of poker cards in Java/Android, I use Collections.shuffle(List> list), of course. I've ever been doing this and the results seemed acceptable. But they aren't.
As outlined in this paper, there are 52! possible unique…

caw
- 30,999
- 61
- 181
- 291
12
votes
3 answers
Using LINQ to shuffle a deck
I am attempting to write a simple card game. In an effort to come up with a good shuffling algorithm I came across Jeff Atwood's post on Coding Horror.
However When I view the contents of the object after calling the Constructor they are not…

jth41
- 3,808
- 9
- 59
- 109
9
votes
2 answers
Game architecture and design strategy for a multiplayer card game
I am relatively new to game development so I decided I wanted to create a hobby project from scratch for both experience and entertainment. The specific game is similar to poker known as Three Card Brag. The game is played in the movie Lock, Stock…

John Rasch
- 62,489
- 19
- 106
- 139
9
votes
3 answers
What is the optimal winning strategy for this modified blackjack game?
Questions
Is there a best value to stay on so that I win the greatest percentage of games possible? If so, what is it?
Edit: Is there an exact probability of winning that can be calculated for a given limit, independent of whatever the opponent…

hobodave
- 28,925
- 4
- 72
- 77
9
votes
3 answers
Adding constant fields to F# discriminated unions
Is it possible to add constant field values to F# discriminated unions?
Can I do something like this?
type Suit
| Clubs("C")
| Diamonds("D")
| Hearts("H")
| Spades("S")
with
override this.ToString() =
// print out the letter…

Ralph
- 31,584
- 38
- 145
- 282
8
votes
1 answer
Javascript- Lodash shuffle vs. Math.Random()
I'm in the process of coding a simple BlackJack game in Javascript. So far, I have an array like this:
var deckArray = [ "card1", "card2",...,"card52" ]
I have a "deal" function set up like this:
var deal = function(){
var card =…

KnowledgeMC
- 103
- 1
- 2
- 7
7
votes
1 answer
What's the best way to enumerate permutations of deck of cards?
I'm looking to make a function that would assign a value to a specific shuffle of cards.
The function has to be bijective. The deck has 52 cards so there are 52! different shuffles, therefore the domain is the set of all permutations of 52 cards,…

Davo
- 526
- 3
- 19
7
votes
4 answers
Is my method working effectively?
I'm writing a code for a deck of cards which shuffles the deck of cards. I tested the code but I don't really know if it's actually doing what it's supposed to be doing correctly? What do you think?
This is the code for the shuffle method:
public…

Panthy
- 1,605
- 4
- 19
- 27
6
votes
6 answers
wxPython or pygame for a simple card game?
I have been playing around with writing some simple card games in Python for fun and I would like to add a graphical user interface (GUI) to the games. Which library would you recommend for writing the GUI for a simple card game?

adam
- 6,582
- 4
- 29
- 28
6
votes
5 answers
Java - How to create a deck of cards (with a focus on static arrays)? - AP Computer Science Project
this is my first question ever. Just to clarify, I did check to see if there were any questions that could have helped me before asking this. Apologies in advance if I do anything incorrectly, I'm new.
Anyways, for my AP CS class I must make a deck…
user9125722