Skip to content

Commit

Permalink
Fix ryanpeikou check for hand with three identical sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
EmeraldCoder committed Mar 2, 2024
1 parent 9f90196 commit 641aec3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/core/han-calculation/yakus/ryanpeikou-yaku.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/han-calculation/yakus/ryanpeikou-yaku.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

0 comments on commit 641aec3

Please sign in to comment.