diff --git a/src/core/han-calculation/yakus/ryanpeikou-yaku.js b/src/core/han-calculation/yakus/ryanpeikou-yaku.js index 172949d..7ceac08 100644 --- a/src/core/han-calculation/yakus/ryanpeikou-yaku.js +++ b/src/core/han-calculation/yakus/ryanpeikou-yaku.js @@ -24,18 +24,18 @@ class RyanpeikouYaku { check ({ combinations, isOpen }) { if (!this.allowOpen && isOpen) return - const chiis = {} - let nbPairOfChii = 0 - - for (const combination of combinations) { - if (combination instanceof Sequence) { - const chiiKey = combination.tiles[0].suit + combination.tiles[0].number - - if (chiis[chiiKey] == null) { chiis[chiiKey] = 0 } else { nbPairOfChii++ } + const groupsOfIdenticalSequence = combinations.filter(combination => combination instanceof Sequence).reduce((agg, combination) => { + const key = combination.tiles[0].number + combination.tiles[0].suit + const index = agg.findIndex(x => x.key === key) + if (index === -1) { + agg.push({ key, items: [combination] }) + } else { + agg[index].items.push(combination) } - } + return agg + }, []) - if (nbPairOfChii === 2) { + if (groupsOfIdenticalSequence.filter(x => x.items.length > 1).length === 2) { return { key: 'ryanpeikou', hanValue: isOpen ? 2 : 3, yakumanValue: 0 } } } diff --git a/tests/unit/han-calculation/yakus/ryanpeikou-yaku.spec.js b/tests/unit/han-calculation/yakus/ryanpeikou-yaku.spec.js index ae9afba..ad2e395 100644 --- a/tests/unit/han-calculation/yakus/ryanpeikou-yaku.spec.js +++ b/tests/unit/han-calculation/yakus/ryanpeikou-yaku.spec.js @@ -69,3 +69,17 @@ const invalidHandWithoutChii = new Hand({ test('ryan peikou (twice pure double chiis) invalid hand without sequence', () => { expect(sut.check(invalidHandWithoutChii)).toBeUndefined() }) + +const invalidHandWithThreeIdenticalChii = new Hand({ + concealedCombinations: [ + new Sequence(new BambooTile(2), new BambooTile(3), new BambooTile(4)), + new Pair(new BambooTile(4)), + new Sequence(new BambooTile(6), new BambooTile(7), new BambooTile(8)), + new Sequence(new BambooTile(6), new BambooTile(7), new BambooTile(8)), + new Sequence(new BambooTile(6), new BambooTile(7), new BambooTile(8)) + ] +}) + +test('ryan peikou (twice pure double chiis) invalid hand with three identical sequences', () => { + expect(sut.check(invalidHandWithThreeIdenticalChii)).toBeUndefined() +})