Cheese uses u32 as internal state (for determinism reasons)
This commit is contained in:
parent
d61e6588c7
commit
05e6bc3e50
|
@ -1,4 +1,4 @@
|
||||||
use mino::matrix::{Mat, MatBuf, COLUMNS};
|
use mino::matrix::{Mat, MatBuf};
|
||||||
use mino::srs::{Piece, PieceType};
|
use mino::srs::{Piece, PieceType};
|
||||||
use rand::{Rng as _, SeedableRng as _};
|
use rand::{Rng as _, SeedableRng as _};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
@ -225,28 +225,28 @@ impl Garbage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn garbage_row(col: i16) -> u16 {
|
fn garbage_row(col: u32) -> u16 {
|
||||||
!(1 << col)
|
!(1 << col)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Cheese {
|
struct Cheese {
|
||||||
rng: Rng,
|
rng: Rng,
|
||||||
col: i16,
|
col: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cheese {
|
impl Cheese {
|
||||||
fn new(mut rng: Rng) -> Self {
|
fn new(mut rng: Rng) -> Self {
|
||||||
let col = rng.gen_range(0..COLUMNS);
|
let col = rng.gen_range(0..10);
|
||||||
Self { rng, col }
|
Self { rng, col }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Iterator for Cheese {
|
impl Iterator for Cheese {
|
||||||
type Item = i16;
|
type Item = u32;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
self.col += self.rng.gen_range(1..COLUMNS);
|
self.col += self.rng.gen_range(1..10);
|
||||||
self.col %= COLUMNS;
|
self.col %= 10;
|
||||||
Some(self.col)
|
Some(self.col)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,8 +363,8 @@ mod tests {
|
||||||
prev = Some(x1);
|
prev = Some(x1);
|
||||||
history.insert(x1);
|
history.insert(x1);
|
||||||
}
|
}
|
||||||
assert_eq!(history.len(), COLUMNS as usize);
|
assert_eq!(history.len(), 10);
|
||||||
for x in 0..COLUMNS {
|
for x in 0..10 {
|
||||||
assert!(history.contains(&x));
|
assert!(history.contains(&x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue