oceanSimple.TexasPoker
2.0.0
dotnet add package oceanSimple.TexasPoker --version 2.0.0
NuGet\Install-Package oceanSimple.TexasPoker -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="oceanSimple.TexasPoker" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="oceanSimple.TexasPoker" Version="2.0.0" />
<PackageReference Include="oceanSimple.TexasPoker" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add oceanSimple.TexasPoker --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: oceanSimple.TexasPoker, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package oceanSimple.TexasPoker@2.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=oceanSimple.TexasPoker&version=2.0.0
#tool nuget:?package=oceanSimple.TexasPoker&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Read this in other languages: English, 中文
开始
环境
需要 c# 版本 .net 8 或更高
基础使用
根据德州扑克的规则, 每名玩家拥有 2(私有) + 5(公共) 张牌, 我们将从这7张牌中挑选出最大的5张牌的组合作为手牌, 与其他玩家进行比大小.
示例:
using Poker;
var handler = PokerHandler.Instance;
var deck = handler.GetDeck();
deck.Shuffle();
// draw 7 cards
var card1 = deck.Draw(7);
var card2 = deck.Draw(7);
Console.WriteLine($"Card1: {string.Join(" ", card1)}");
Console.WriteLine($"Card2: {string.Join(" ", card2)}");
// through 7 cards, we will find the max combination of 5 cards
var hand1 = handler.GetHand(card1);
var hand2 = handler.GetHand(card2);
Console.WriteLine($"Hand1: {hand1}");
Console.WriteLine($"Hand2: {hand2}");
// compare
var result = handler.CompareTwoHands(hand1, hand2);
Console.WriteLine($"Compare result: {result}");
运行结果:
Card1: ♥3 ♦5 ♣7 ♥2 ♦A ♥5 ♠10
Card2: ♠7 ♥4 ♦6 ♦2 ♦Q ♣4 ♣A
Hand1: ♦A ♠10 ♣7 ♦5 ♥5
Hand2: ♣A ♦Q ♠7 ♥4 ♣4
Compare result: 1
核心类
OCard
通过 color 和 number 创建一张 card.
虽然没有在OCard的构造函数中, 我们没有使用枚举来强制参数的类型, 但我们提供了 EOColor 和 EONumber 静态类, 希望用户使用这两个类来创建OCard, 减少问题.
下面是OColor和ONumber各属性的对照表.
Color
| Code | Description | Picture |
|---|---|---|
| 0 | Unknown | Unknown |
| 1 | Spade | ♠ |
| 2 | Heart | ♥ |
| 3 | Diamond | ♦ |
| 4 | Club | ♣ |
| 5 | Red | Red |
| 6 | Black | Black |
Number
| Code | Description | Picture | Value |
|---|---|---|---|
| 0 | Unknown | Unknown | 0 |
| 1 | Ace | A | 14 |
| 2 | Two | 2 | 2 |
| 3 | Three | 3 | 3 |
| 4 | Four | 4 | 4 |
| 5 | Five | 5 | 5 |
| 6 | Six | 6 | 6 |
| 7 | Seven | 7 | 7 |
| 8 | Eight | 8 | 8 |
| 9 | Nine | 9 | 9 |
| 10 | Ten | 10 | 10 |
| 11 | Jack | J | 11 |
| 12 | Queen | Q | 12 |
| 13 | King | K | 13 |
| 14 | Joker | Joker | 14 |
ODeck
- 获得一个包含 4x13 的牌盒
- 方法
- Sort: 排序
- Shuffle: 洗牌,随机打乱
- Draw: 抽牌.
示例:
public class ODeckTest(ITestOutputHelper outputHelper) {
[Fact]
public void Test() {
var deck = new ODeck();
outputHelper.WriteLine(deck.ToString());
deck.Shuffle();
outputHelper.WriteLine(deck.ToString());
deck.Sort();
outputHelper.WriteLine(deck.ToString());
var oCards = deck.Draw(40);
Assert.Equal(40, oCards.Count);
var cards = deck.Draw(20);
Assert.Equal(12, cards.Count);
}
}
TexasPokerHandler
按照德州扑克的规则, 进行大小比较.
public static class TexasPokerHandler {
public static int CompareTwoHands(List<OCard> cards1, List<OCard> cards2) {
}
public static int CompareTwoHands(OHand hand1, OHand hand2) {
}
public static List<int> GetMaxHands(List<List<OCard>> cards) {
}
public static List<int> GetMaxHands(List<OHand> hands) {
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.