標籤:stat 其他 ase hot href 組合 too 隨機 next
52張牌隨機分給4個玩家,要求每個玩家的牌用一個一維數組表示。
我們採用類比大法。初始化一副撲克牌,洗牌,發牌。
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication43{ class Program { enum Suit { Spade, Heart, Diamond, Club } enum Value { Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queue, King, Ace } class Card { public Suit suit; public Value value; } static void Main(string[] args) { Card[] c = new Card[52]; for(int i=0;i<52;i++) ///初始化一副撲克牌 { c[i] = new Card(); c[i].suit = (Suit)(i % 4); c[i].value = (Value)(i % 13); } for (int k=51; k >=0; k--) //洗牌 { Random rand = new Random(); int p = rand.Next(k); Card temp=new Card (); temp = c[p]; c[p] = c[k]; c[k] = temp; } Card[] E = new Card[13]; Card[] W = new Card[13]; Card[] S = new Card[13]; Card[] N = new Card[13]; int A=0,B=0,C=0,D=0; for(int j=0;j<52;j++)//分牌 { switch(j%4) { case 0: { E[A++] = c[j]; break; } case 1: { S[B++] = c[j]; break; } case 2: { W[C++] = c[j]; break; } case 3: { N[D++] = c[j]; break; } default: { Console.WriteLine("error"); break; } } } Console.WriteLine("東:"); for (int i = 0; i < 13; i++) { Console.Write("{0},{1} ", E[i].suit, E[i].value);} Console.WriteLine(); Console.WriteLine("南:"); for (int i = 0; i < 13; i++) { Console.Write("{0},{1} ", S[i].suit, S[i].value);} Console.WriteLine(); Console.WriteLine("西:"); for (int i = 0; i < 13; i++) { Console.Write("{0},{1} ", W[i].suit, W[i].value);} Console.WriteLine(); Console.WriteLine("北:"); for (int i = 0; i < 13; i++) { Console.Write("{0},{1} ", N[i].suit, N[i].value);} } }}
練習:電腦隨機發出5張牌,判斷是以下哪種牌型?(梭哈遊戲的基礎)
同花順(Straight Flush亦稱“蛇”):同一花色,順序的牌。例:
四條(Four of a Kind,亦稱“鐵支”、“四張”或“炸彈”):有四張同一點數的牌。例:
滿堂紅(Fullhouse,亦稱“俘虜”、“骷髏”、“夫佬”、“葫蘆”、“富爾豪斯”):三張同一點數的牌,加一對其他點數的牌。例:
同花(Flush,簡稱“花”:五張同一花色的牌。例:
順子(Straight,):五張順連的牌。例:
三條(Three of a kind,亦稱“三張”):有三張同一點數的牌。例:
兩對(Two Pairs,香港稱“Two啤”):兩張相同點數的牌,加另外兩張相同點數的牌。例:
一對(One Pair,香港稱“啤”):兩張相同點數的牌。例:
無對(Zilch ,香港稱“粒”):不能排成以上組合的牌,以點數決定大小。例:
理解物件導向編程---C#控制台實現52張撲克牌的分法