pub struct MoveProcessor {}
Expand description
Represents the processor that translates the move list into a list of IMoveCommand objects then either displays them or executes them.
This struct uses a parser to convert the single letter characters in a string into a list of actions (instances of the MoveCommandXXX structs). This list of actions is then display or executed to perform the operations.
The process of executing the list of operations is an example of the “Command” pattern. The parsing step is also an example of the “Interpreter” pattern, where the actions are the tokens to be interpreted.
Implementations§
source§impl MoveProcessor
impl MoveProcessor
sourcepub fn new() -> MoveProcessor
pub fn new() -> MoveProcessor
sourcepub fn parse(&self, moves: &str) -> Vec<Box<dyn IMoveCommand>>
pub fn parse(&self, moves: &str) -> Vec<Box<dyn IMoveCommand>>
Parse the given list of move commands, where each command is represented by a single character, to produce a list of move command objects.
Recognizes ‘U’, ‘D’, ‘L’, and ‘R’ (case-insensitive). All other characters are assigned a “Do Nothing” (Null Object) command.
Parameters
-
moves
A string containing the move commands to parse.
Returns
Returns a list of the move commands, with each command represented by the IMoveCommand trait.
sourcepub fn show_commands(&self, commands: &Vec<Box<dyn IMoveCommand>>)
pub fn show_commands(&self, commands: &Vec<Box<dyn IMoveCommand>>)
Display the given list of move commands.
Parameters
-
commands
A list of IMoveCommand objects, each representing one move command.
sourcepub fn execute_commands(&self, commands: &Vec<Box<dyn IMoveCommand>>)
pub fn execute_commands(&self, commands: &Vec<Box<dyn IMoveCommand>>)
Execute the given list of move commands. Execution amounts to a series of command names printed to standard out.
Parameters
-
commands
A list of IMoveCommand objects, each representing one move command.