Skip to content

Commit

Permalink
libriichi/state: reject unknown tiles in witness_tile
Browse files Browse the repository at this point in the history
  • Loading branch information
Equim-chan committed Feb 4, 2024
1 parent 162c10c commit 9861007
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions libriichi/src/state/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl PlayerState {
Event::Tsumo { actor, pai } => {
ensure!(
self.tiles_left > 0,
"rule violation: tsumo but no more tiles in yama",
"rule violation: attempt to tsumo from empty yama",
);
self.tiles_left -= 1;
if actor != self.player_id {
Expand Down Expand Up @@ -653,9 +653,17 @@ impl PlayerState {
///
/// Returns an error if we have already witnessed 4 such tiles.
pub(super) fn witness_tile(&mut self, tile: Tile) -> Result<()> {
ensure!(
!tile.is_unknown(),
"rule violation: attempt to witness an unknown tile",
);
let tile_id = tile.deaka().as_usize();

let seen = &mut self.tiles_seen[tile_id];
ensure!(*seen < 4, "rule violation: witness the fifth {tile}");
ensure!(
*seen < 4,
"rule violation: attempt to witness the fifth {tile}",
);
*seen += 1;

self.doras_seen += self.dora_factor[tile_id];
Expand Down

0 comments on commit 9861007

Please sign in to comment.