相关疑难解决方法(0)

F#造型扑克牌

我想在F#中代表标准扑克牌.我的目标是实现一个微软纸牌(Windows附带的一个)的克隆,一个卡片套装,面部和颜色很重要的游戏.这个练习主要是为了学习一些F#.

我考虑过使用歧视的工会:

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
Run Code Online (Sandbox Code Playgroud)

卡的记录类型:

type Card = {
    suit: Suit;
    face: Face;
    color: Color;
}
Run Code Online (Sandbox Code Playgroud)

但是,卡片的颜色可以从它的套装中推断出来 - 所有钻石和红心都是红色的,所有的俱乐部和黑桃都是黑色的.不能仅从Color确定套装.也许这样的事情是合适的:

type Suit =
    | Diamonds of Color //should always be red
    | Hearts …
Run Code Online (Sandbox Code Playgroud)

f# playing-cards

6
推荐指数
1
解决办法
781
查看次数

标签 统计

f# ×1

playing-cards ×1