struct KeyPad<T> {
controller: Option<Rc<RefCell<KeyPad<DirectionalButton>>>>,
cache: HashMap<(KeyPadButton<T>, KeyPadButton<T>), usize>,
}
Expand description
Encodes a KeyPad. The layout comes from the button input type (T)(
Fields§
§controller: Option<Rc<RefCell<KeyPad<DirectionalButton>>>>
§cache: HashMap<(KeyPadButton<T>, KeyPadButton<T>), usize>
Implementations§
source§impl<T> KeyPad<T>
impl<T> KeyPad<T>
sourcefn direct_entry() -> KeyPad<T>
fn direct_entry() -> KeyPad<T>
A new KeyPad
that expects a person to be pressing the keys
sourcefn controlled_by(controller: KeyPad<DirectionalButton>) -> KeyPad<T>
fn controlled_by(controller: KeyPad<DirectionalButton>) -> KeyPad<T>
A new KeyPad
that expects a robot arm controlled by another pad to be pressing the keys
sourcefn repeat(
positive: DirectionalButton,
negative: DirectionalButton,
a: u8,
b: u8,
) -> Vec<DirectionalButton>
fn repeat( positive: DirectionalButton, negative: DirectionalButton, a: u8, b: u8, ) -> Vec<DirectionalButton>
Given positive and negative unit length movement keys for an axis, and a start and end point on that axis, return the list of movements to move from the start to the end.
sourcefn check_moves(moves: &Vec<&DirectionalButton>, start: &(u8, u8)) -> bool
fn check_moves(moves: &Vec<&DirectionalButton>, start: &(u8, u8)) -> bool
Given a list of moves, follow them and check it doesn’t leave the key pad
sourcefn controller_presses(&mut self, moves: Vec<&DirectionalButton>) -> usize
fn controller_presses(&mut self, moves: Vec<&DirectionalButton>) -> usize
Given a list of moves, pass those up the keypad chain to get the total key presses needed for that move.
sourcefn presses_for_pair(
&mut self,
(a, b): (KeyPadButton<T>, KeyPadButton<T>),
) -> usize
fn presses_for_pair( &mut self, (a, b): (KeyPadButton<T>, KeyPadButton<T>), ) -> usize
Work out the valid paths between two keys and recurse the required movements up the keypad chain to find the route with the shortest number of presses. The result is cached for performance.
sourcefn key_presses(&mut self, keys: &Vec<T>) -> usize
fn key_presses(&mut self, keys: &Vec<T>) -> usize
Solves the puzzle for this keypad chain, return the number of key presses needed at the top of the keypad chain to press the expected list of keys on this keypad.