diff options
Diffstat (limited to 'src/util.rs')
-rw-r--r-- | src/util.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/util.rs b/src/util.rs new file mode 100644 index 0000000..a05eeb9 --- /dev/null +++ b/src/util.rs @@ -0,0 +1,42 @@ +//! Uh-oh, a `util.rs` file. That can't be good. + +use crate::database::{BoardRow, Placement}; + +pub fn tiebreak_shared_positions(board: Vec<BoardRow>) -> Vec<Placement> { + let first = match board.first() { + Some(r) => r.clone(), + None => return vec![], + }; + + let mut last_score = first.points; + let mut last_placed = 1; + let mut placed = vec![Placement { + row: first, + placement: 1, + placement_tie: 1, + placement_first_of_tie: true, + }]; + + for (idx, row) in board.into_iter().enumerate().skip(1) { + if row.points == last_score { + placed.push(Placement { + row, + placement: idx + 1, + placement_tie: last_placed, + placement_first_of_tie: false, + }); + } else { + last_score = row.points; + last_placed = idx + 1; + + placed.push(Placement { + row, + placement: idx + 1, + placement_tie: last_placed, + placement_first_of_tie: true, + }); + } + } + + placed +} |