From 0e7c5517230103df7be23b2c57494dfa5232ea57 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Tue, 31 Jul 2012 22:35:32 -0400 Subject: [PATCH] Validate pinfu's open wait requirement --- src/yaku.erl | 6 +++--- test/riichi_yaku_tests.erl | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/yaku.erl b/src/yaku.erl index 50b6ed1..82949d2 100644 --- a/src/yaku.erl +++ b/src/yaku.erl @@ -40,15 +40,15 @@ tanyao(#game{}, #player{hand=Hand}) -> end, riichi_hand:tiles(Hand)). -pinfu(#game{round=Round}, #player{seat=Seat, hand=Hand=#hand{melds=Melds}}) -> - % TODO: Verify closed, open wait, and pair not round/seat wind +pinfu(#game{round=Round}, #player{seat=Seat, hand=Hand=#hand{melds=Melds}, drawn={_, Drawn}}) -> Closed = lists:all(fun(T) -> T#tile.from =:= draw end, riichi_hand:tiles(Hand)), + OpenWait = length(riichi_hand:waits(#hand{tiles=riichi_hand:tiles(Hand) -- [Drawn]})) > 1, Chiis = length([M || M = #meld{type=chii} <- Melds]) =:= 4, #meld{type=pair, tiles=[HeadTile,HeadTile]} = riichi_hand:head(Hand), NonValuePair = HeadTile#tile.value =/= Round andalso HeadTile#tile.value =/= Seat andalso HeadTile#tile.suit =/= dragon, - Closed and Chiis and NonValuePair. + Closed and OpenWait and Chiis and NonValuePair. % 7 Pairs chiitoitsu(#game{}, #player{hand=#hand{tiles=[], melds=Melds}}) diff --git a/test/riichi_yaku_tests.erl b/test/riichi_yaku_tests.erl index fdcc788..b04eb24 100644 --- a/test/riichi_yaku_tests.erl +++ b/test/riichi_yaku_tests.erl @@ -34,7 +34,7 @@ pinfu_test() -> #meld{type=chii, tiles=[#tile{suit=sou, value=V} || V <- [4,5,6]]}, #meld{type=chii, tiles=[#tile{suit=sou, value=V} || V <- [4,5,6]]}, #meld{type=chii, tiles=[#tile{suit=man, value=V} || V <- [6,7,8]]}]}, - ?assertEqual(true, yaku:pinfu(#game{}, #player{hand=Hand})). + ?assertEqual(true, yaku:pinfu(#game{}, #player{hand=Hand, drawn={tsumo, #tile{suit=sou, value=6}}})). chiitoitsu_test() -> Hand = #hand{melds=[#meld{type=pair, tiles=lists:duplicate(2, #tile{suit=pin, value=V})} || V <- lists:seq(1,7)]},