playing-cards

F# modeling playing cards

妖精的绣舞 提交于 2019-11-27 07:50:10
问题 I am trying to represent standard playing cards in F#. My goal is to implement a clone of Microsoft Solitaire (the one that comes with Windows) , a game in which Cards' Suit, Face, and Color are important. This exercise is mostly intended as a way to learn some F#. I have considered using discriminated unions: type Suit = | Diamonds | Hearts | Clubs | Spades type Color = | Red | Black type Face = Two | Three | Four | Five | Six | Seven | Eight | Nine | Ten | Jack | Queen | King | Ace with a

How can I iterate through every possible combination of n playing cards

南楼画角 提交于 2019-11-26 18:36:01
问题 How can I loop through all combinations of n playing cards in a standard deck of 52 cards? 回答1: You need all combinations of n items from a set of N items (in your case, N == 52 , but I'll keep the answer generic). Each combination can be represented as an array of item indexes, size_t item[n] , such that: 0 <= item[i] < N item[i] < item[i+1] , so that each combination is a unique subset. Start with item[i] = i . Then to iterate to the next combination: If the final index can be incremented

Card Shuffling in C#

六眼飞鱼酱① 提交于 2019-11-26 01:45:42
问题 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 class. These are my classes: Program.cs: namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Deck mydeck = new Deck(); foreach (Card c in mydeck.Cards) { Console.WriteLine(c); } Console.WriteLine(\"How Many Times Do You

Card Shuffling in C#

喜夏-厌秋 提交于 2019-11-25 19:51:07
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 class. These are my classes: Program.cs: namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Deck mydeck = new Deck(); foreach (Card c in mydeck.Cards) { Console.WriteLine(c); } Console.WriteLine("How Many Times Do You Want To Shuffle?"); } } } Deck.cs: namespace ConsoleApplication1 { class Deck { Card[] cards = new Card[52