Skip to content

Instantly share code, notes, and snippets.

@ApprenticeGC
Last active October 10, 2017 08:28
Show Gist options
  • Select an option

  • Save ApprenticeGC/b65404341cd4edb71edeaa3ec3bceeb3 to your computer and use it in GitHub Desktop.

Select an option

Save ApprenticeGC/b65404341cd4edb71edeaa3ec3bceeb3 to your computer and use it in GitHub Desktop.
TDD of 6 Nimmt in Expecto
let tests =
testList "遊戲主體規則" [
testList "卡牌生成規則" [
test "生成後共有一零四張牌" {
let expected = 104
let actual = cardRepo |> List.length
Expect.equal actual expected "生成後的牌數應為一零四張"
}
test "生成後的每一張牌為連號" {
let expected = seq { for i in 1 .. 104 do yield i } |> Seq.toList
let actual = cardRepo |> List.map (fun x -> x.Index)
Expect.equal actual expected "應該是連號的數字"
}
test "每張牌至少有一個牛頭" {
let expected = 0
let actual =
cardRepo
|> List.map (fun x -> x.BullHead)
|> List.filter (fun x -> x < 1)
|> List.length
Expect.equal actual expected "沒有任何一張卡的牛頭數少於1"
}
test "卡號為5, 15, 25, 35, 45, 55, 65, 75, 85, 95的牌有2個牛頭" {
let convertedArray = cardRepo |> List.toArray
let expected = 10
let actual =
[ 5; 15; 25; 35; 45; 55; 65; 75; 85; 95 ]
|> List.map (fun x ->
let {Index = i; BullHead = bh} = convertedArray.[x - 1]
bh)
|> List.filter (fun x -> x >= 2)
|> List.length
Expect.equal actual expected "數字為5結尾的至少有2個牛頭"
}
test "卡號為10, 20, 30, 40, 50, 60, 70, 80, 90, 100的牌有3個牛頭" {
let convertedArray = cardRepo |> List.toArray
let expected = 10
let actual =
[ 10; 20; 30; 40; 50; 60; 70; 80; 90; 100 ]
|> List.map (fun x ->
let {Index = i; BullHead = bh} = convertedArray.[x - 1]
bh)
|> List.filter (fun x -> x >= 3)
|> List.length
Expect.equal actual expected "數字為10的倍數至少有3個牛頭"
}
test "卡號為11, 22, 33, 44, 55, 66, 77, 88, 99的牌有5個牛頭" {
let convertedArray = cardRepo |> List.toArray
let expected = 9
let actual =
[ 11; 22; 33; 44; 55; 66; 77; 88; 99 ]
|> List.map (fun x ->
let {Index = i; BullHead = bh} = convertedArray.[x - 1]
bh)
|> List.filter (fun x -> x >= 5)
|> List.length
Expect.equal actual expected "二位數字且數字一樣的至少有5個牛頭"
}
test "卡號為55的牌有7個牛頭" {
let convertedArray = cardRepo |> List.toArray
let expected = 7
let actual =
let {Index = i; BullHead = bh} = convertedArray.[55 - 1]
bh
Expect.equal actual expected "數字55有7個牛頭"
}
]
]
module SixNimmt =
type Card = {
Index : int
BullHead : int
}
let (|EndWith|_|) check index =
let inline charToInt c = int c - int '0'
let numberChars = index.ToString() |> Seq.toList
let reversedNumberChars = numberChars |> List.rev
match reversedNumberChars with
| n::_ when charToInt n = check -> Some(index)
| _ -> None
let (|MultipleOf|_|) check index =
if index % check = 0 then Some(index) else None
let (|Doublet|_|) x index =
let numberChars = index.ToString() |> Seq.toList
let count = numberChars |> List.length
if count = 2 then
match numberChars with
| a::b::_ when a = b -> Some(index)
| _ -> None
else
None
let cardRepo =
let createCard = function
| Doublet 0 a & EndWith 5 i ->
{ Index = i; BullHead = 7 }
| Doublet 0 i ->
{ Index = i; BullHead = 5 }
| MultipleOf 10 i->
{ Index = i; BullHead = 3 }
| EndWith 5 i->
{ Index = i; BullHead = 2 }
| x ->
{ Index = x; BullHead = 1 }
seq { for i in 1 .. 104 do yield createCard i }
|> Seq.toList
dotnet new sln -n Main
# Library in F#
dotnet new classlib -o GameLib -lang f#
# Console app in F#
dotnet new console -o GameLib.Tests -lang f#
dotnet sln add GameLib/GameLib.fsproj
dotnet sln add GameLib.Tests/GameLib.Tests.fsproj
cd GameLib.Tests
# From Tests, add reference to GameLib
dotnet add reference ../GameLib/GameLib.fsproj
# Add reference to Expecto
dotnet add package Expecto

6 Nimmt

遊玩人數

此遊戲可供2至10人同樂

遊玩規則

前期準備

將104張卡牌進行洗牌後向每人分發10張,而後將餘下的4張牌按照數字大小,由小到大做由上到下的排列置於桌面,若是遊玩人數不足10人,則從剩於的牌中任取4張進行擺放,於公用區域中形成4列,其餘牌則到置於一旁不進行使用。

遊戲進行

每個人同時從手牌中拿出一張,並以覆蓋方式置於桌面,待全部人的卡牌拿出後,翻至數字面,並依大小相繼擺放在公用區域中4列之後。

擺放的規則為該卡牌上的數字大於該列的最後一張牌的數字,且數目最接近時,進行擺放。

若是將要擺放的卡牌數字小於全部4列中的最後一張時,則打出該牌的玩家要先將4列中任1列取回,取回後該牌則成為那列的第一張,之後仍依順序將其它玩家打出的牌置入對應列。

若擺放於某列時成為第6張,則該牌的持有者要先將那一列的前5張取回,而原先的第6張則成為那列的第1張後再行依序擺放規則。

只要是從公用區的任一列取回的牌,都不納入手牌,而是自行保留自算分時才始用。

所有牌擺放進入相關的列中後,重覆每位玩家再取出手中一張牌的動作進行擺放,直到10張全數完成後進行積分計算。

積分計算

從公用區取回的牌依照上面的牛頭數量進行計分,1個牛頭標誌為1分。此分數實為負分,若任一玩家超過66分則該遊戲結束,積分最少者獲勝。若沒有任一玩家超過66分,將該回合的積分先行做一記錄,而後進入另一回合。加總每回合的累進積分,直到任一玩家超過66分後結束。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment