扑克牌评估器结构数组
Poker Hand Evaluator Array of Structures
对于一项任务,我被问到以下问题:
编写一个评估单手扑克牌的程序。显示手并打印出它是什么类型。下面列出了手牌的排名,从最高排名到最低排名。
对卡片使用结构,对手使用结构数组。您应该为每种手牌编写一个方法,如果手牌符合该标准则返回 true,否则返回 false。
您将使用的结构应如下所示:
public struct card
{
public char suit; // 'C', 'D', 'H', 'S' - for clubs, diamonds, hearts, and spades
public int value; //2-14 – for 2-10,Jack, Queen, King, Ace
};
struct card hand[5];
已分配给我们使用的外部 txt 文件如下所示:
C 13 H 13 D 13 C 10 H 10
我已经设法将文本文件读入我的程序,但我不确定如何处理它。结构数组如下:
(C 13)(H 13)(D 13)(C 10)(H 10)
不太确定如何将文件中的文本行转换为这种格式,感谢任何帮助,干杯:)
试试这个
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication45
{
class Program
{
static void Main(string[] args)
{
List<Card> cards = new List<Card>();
string input = "C 13 H 13 D 13 C 10 H 10";
string[] inputArray = input.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
for(int i = 0; i < 10; i += 2)
{
Card newCard = new Card();
newCard.suit = inputArray[i][0];
newCard.value = int.Parse(inputArray[i + 1]);
cards.Add(newCard);
}
foreach (Card card in cards)
{
Console.WriteLine("Suit {0}, Rank {1}", card.suit, card.value.ToString());
}
Console.ReadLine();
}
public struct Card
{
public char suit; // 'C', 'D', 'H', 'S' - for clubs, diamonds, hearts, and spades
public int value; //2-14 – for 2-10,Jack, Queen, King, Ace };
}
}
}
对于一项任务,我被问到以下问题:
编写一个评估单手扑克牌的程序。显示手并打印出它是什么类型。下面列出了手牌的排名,从最高排名到最低排名。
对卡片使用结构,对手使用结构数组。您应该为每种手牌编写一个方法,如果手牌符合该标准则返回 true,否则返回 false。
您将使用的结构应如下所示:
public struct card
{
public char suit; // 'C', 'D', 'H', 'S' - for clubs, diamonds, hearts, and spades
public int value; //2-14 – for 2-10,Jack, Queen, King, Ace
};
struct card hand[5];
已分配给我们使用的外部 txt 文件如下所示:
C 13 H 13 D 13 C 10 H 10
我已经设法将文本文件读入我的程序,但我不确定如何处理它。结构数组如下:
(C 13)(H 13)(D 13)(C 10)(H 10)
不太确定如何将文件中的文本行转换为这种格式,感谢任何帮助,干杯:)
试试这个
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication45
{
class Program
{
static void Main(string[] args)
{
List<Card> cards = new List<Card>();
string input = "C 13 H 13 D 13 C 10 H 10";
string[] inputArray = input.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
for(int i = 0; i < 10; i += 2)
{
Card newCard = new Card();
newCard.suit = inputArray[i][0];
newCard.value = int.Parse(inputArray[i + 1]);
cards.Add(newCard);
}
foreach (Card card in cards)
{
Console.WriteLine("Suit {0}, Rank {1}", card.suit, card.value.ToString());
}
Console.ReadLine();
}
public struct Card
{
public char suit; // 'C', 'D', 'H', 'S' - for clubs, diamonds, hearts, and spades
public int value; //2-14 – for 2-10,Jack, Queen, King, Ace };
}
}
}