Add input::Movement enum

This commit is contained in:
tali 2022-12-14 13:16:30 -05:00
parent 4b9d10699f
commit 614c183234
1 changed files with 32 additions and 0 deletions

View File

@ -4,6 +4,38 @@
use crate::matrix::Mat;
use crate::piece::{Piece, Rot, Shape};
/// Represents a basic movement input from the user.
///
/// DAS inputs are not included, since functionally DAS is equivalent to repeated taps,
/// and a bot can effectively hypertap infinitely fast during its analysis.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
pub enum Movement {
/// "Sonic" drop.
Drop,
/// Horizontal shift.
Shift(Horizontal),
/// Rotation.
Rotate(Spin),
// TODO: soft drops?
}
impl Movement {
/// Applies this movement to the given piece on the given matrix. Returns true if the
/// movement was successful, or false if the piece did not move because it was
/// obstructed by the matrix. `piece` will be modified in-place iff the return value
/// is true.
pub fn perform<'c, 'k, S>(&self, piece: &mut Piece<S>, mat: &Mat) -> bool
where
S: Shape<'c> + Kicks<'k>,
{
match *self {
Self::Drop => drop(piece, mat),
Self::Shift(d) => shift(piece, mat, d),
Self::Rotate(d) => rotate(piece, mat, d).is_some(),
}
}
}
/// Represents a direction of horizontal movement.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
#[repr(i16)]