playing-cards

Playing cards game

半城伤御伤魂 提交于 2019-12-08 10:25:06
问题 Here I have N number of cards numbered from 1 to N placed in a round table such that card 1 is between card 2 and card N . All the cards are initially upside down. The aim is to turn all the cards face up. Let's say we touch a card i, touching the card i will turn the cards i-1,i,i+1 face up. similarly touching the card N will turn the cards N-1,N,1st card face up. I want to determine the minimum number of touches required to face up all the cards. here is what i have been trying in python q

How to initialize a static array?

China☆狼群 提交于 2019-12-05 08:20:24
问题 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" }; or as a List List suit = Arrays.asList( "spades", "hearts", "diamonds", "clubs" ); Is there a difference (except for the List definition of course)? What is the better way (performance wise)? 回答1: If you are creating an array then there is no difference, however, the

7 Card Poker Hand Evaluator

*爱你&永不变心* 提交于 2019-12-04 07:30:43
问题 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 回答1: This site lists a bunch of Poker Hand Evaluator libraries and gives a few details about each of them. Most of them are for 5 card hands, but there is at least one for a 7 card hand called The Snezee7 Evaluator. Plus the site give a great overview of the different techniques and

How to initialize a static array?

六眼飞鱼酱① 提交于 2019-12-03 22:01:28
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" }; or as a List List suit = Arrays.asList( "spades", "hearts", "diamonds", "clubs" ); Is there a difference (except for the List definition of course)? What is the better way (performance wise)? If you are creating an array then there is no difference, however, the following is neater: String[] suit = { "spades", "hearts", "diamonds", "clubs" }; But, if you want to pass an array

How to really shuffle a deck of cards

你离开我真会死。 提交于 2019-12-03 02:24:14
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 shuffles of a 52 card poker deck. That amounts to about 2^226. But Collections.shuffle(List<?> list) uses new Random() by default which uses a 48-bit seed and can therefore only create 2^48 unique shuffles - which is only 3.49*10^(-52) percent of all possible shuffles! So how do I shuffle cards the right way? I've started using SecureRandom , but

Struct help. Assigning a card struct to an array of cards held in a deck struct

☆樱花仙子☆ 提交于 2019-12-02 19:14:46
问题 These are my two structs: typedef struct _card { int suit; int value; } card; typedef struct _deck { int num_cards; card *cards; } deck; This is my make a card function: card *make_card(int suit, int value) { card *newCard = malloc(sizeof(card)); newCard->suit = suit; newCard->value = value; return newCard; } Now is where I am a bit stuck. I have to make a deck of cards. I know how to assign each value to the card, but I am stumped on how to allocate it in memory. I know it has to do with an

Struct help. Assigning a card struct to an array of cards held in a deck struct

南楼画角 提交于 2019-12-02 07:39:06
These are my two structs: typedef struct _card { int suit; int value; } card; typedef struct _deck { int num_cards; card *cards; } deck; This is my make a card function: card *make_card(int suit, int value) { card *newCard = malloc(sizeof(card)); newCard->suit = suit; newCard->value = value; return newCard; } Now is where I am a bit stuck. I have to make a deck of cards. I know how to assign each value to the card, but I am stumped on how to allocate it in memory. I know it has to do with an array of cards in the deck struct but i cant figure out how. deck *make_standard_deck() { for (int i =

C#: How should I go about shuffling contents of an array?

倾然丶 夕夏残阳落幕 提交于 2019-12-01 23:46:22
问题 I have an array of integers called cards[52]. Each element contains an integer that represents a card (cards[0] = 5 would represent the 6 of clubs for example). This is how I shuffled the array. It works, but I am getting repeats. private void shuffleCards() { for (int i = 0; i < cards.Length; i++) { int randIndex = r.Next(0, 52); int origCard = cards[i]; cards[i] = cards[randIndex]; cards[randIndex] = origCard; } } r is the Random variable I initialized in the beginning of the program. When

C#: How should I go about shuffling contents of an array?

喜欢而已 提交于 2019-12-01 21:29:50
I have an array of integers called cards[52]. Each element contains an integer that represents a card (cards[0] = 5 would represent the 6 of clubs for example). This is how I shuffled the array. It works, but I am getting repeats. private void shuffleCards() { for (int i = 0; i < cards.Length; i++) { int randIndex = r.Next(0, 52); int origCard = cards[i]; cards[i] = cards[randIndex]; cards[randIndex] = origCard; } } r is the Random variable I initialized in the beginning of the program. When testing the program, I noticed I would get the same card 2 or 3 times. Obviously I cannot get repeats,

Android card based game, need help to start

拟墨画扇 提交于 2019-11-30 16:34:13
I'm just setting out in android development. I want to make a kind of card based game. I'm just looking for suggestions really on how I might start it. I know I have to make the menu layout and view, then use an Intent from that to get to the main game view. My sticking points are: There's going to be a deck of cards. It's going to be a set number so I was thinking I could just have each card defined as a button in the layout. I don't know if that is the right way to do it though. Storage of card details. I'm thinking of using an xml file to store these. You could try to check out this project