Skip to content

Commit

Permalink
convlog: fix tsumogiri in backtrack situation
Browse files Browse the repository at this point in the history
  • Loading branch information
Equim-chan committed Apr 20, 2021
1 parent 91f2826 commit 7e6937d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
22 changes: 20 additions & 2 deletions convlog/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,31 @@ fn tenhou_kyoku_to_mjai_events(
None => Some(i),

Some(next) => {
let mut process_dahai = |pai| {
match pai {
// tsumogiri
Pai::Unknown => {
match take_events[actor].peek() {
// Fill the tsumogiri dahai with tsumo pai
Some(&mjai::Event::Tsumo { pai, .. }) => Some(pai),
// tsumogiri must have a tsumo, not pon or chi
_ => unreachable!(),
}
}

// tedashi, can be after chi or pon
_ => Some(pai),
}
};

let dahai = match *next {
mjai::Event::Dahai { pai, .. } => Some(pai),
mjai::Event::Dahai { pai, .. } => process_dahai(pai),
mjai::Event::Reach { .. } => {
let mut cloned = discard_events[actor].clone();
if let Some(mjai::Event::Dahai { pai, .. }) = cloned.nth(1) {
Some(pai)
process_dahai(pai)
} else {
// dahai is the only possible event after reach
unreachable!()
}
}
Expand Down
1 change: 1 addition & 0 deletions convlog/tests/testdata/confusing_nakis_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"title":["",""],"name":["Aさん","Bさん","Cさん","Dさん"],"rule":{"disp":"鳳南喰赤","aka":1},"log":[[[7,0,0],[24500,42200,33300,0],[36],[],[11,13,15,22,52,28,31,31,32,53,38,39,45],[38,45,23,27,41,17],[45,60,28,32,60,11],[14,51,17,19,21,21,42,43,43,44,46,46,47],["43p4343",23,"46p4646",13,33,23,34],[44,47,23,42,60,60,60],[11,11,17,22,25,26,28,33,37,38,41,45,45],[44,"45p4545",15,39,25,24,16],[41,44,28,22,33,25],[13,16,18,19,23,24,27,29,29,38,43,46,47],[47,44,"47p4747",25,37,28,26,39],[43,60,19,46,27,60,60,13],["和了",[-500,-500,2000,-1000],[2,2,2,"30符2飜500-1000点","役牌 白(1飜)","ドラ(1飜)"]]]]}
4 changes: 4 additions & 0 deletions convlog/tests/testdata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pub const TESTDATA: &[TestCase] = &[
description: "confusing_nakis_2",
data: include_str!("confusing_nakis_2.json"),
},
TestCase {
description: "confusing_nakis_3",
data: include_str!("confusing_nakis_3.json"),
},
TestCase {
description: "double_kakan_then_chankan",
data: include_str!("double_kakan_then_chankan.json"),
Expand Down

0 comments on commit 7e6937d

Please sign in to comment.