function to check collisions at given position
This commit is contained in:
		
							parent
							
								
									d35da41c90
								
							
						
					
					
						commit
						e4b25281f7
					
				
							
								
								
									
										15
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/main.rs
									
									
									
									
									
								
							@ -14,6 +14,7 @@
 | 
				
			|||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					// along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use clap::{App, Arg};
 | 
					use clap::{App, Arg};
 | 
				
			||||||
 | 
					use std::collections::HashMap;
 | 
				
			||||||
use std::fs;
 | 
					use std::fs;
 | 
				
			||||||
use std::io;
 | 
					use std::io;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -28,7 +29,19 @@ fn check_map(r: &robot::Robot, w: &world::World) -> Result<(), String> {
 | 
				
			|||||||
        Ok(())
 | 
					        Ok(())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					fn check_collisions(
 | 
				
			||||||
 | 
					    r: &robot::Robot,
 | 
				
			||||||
 | 
					    w: &world::World,
 | 
				
			||||||
 | 
					    h: HashMap<&robot::Position, &u32>,
 | 
				
			||||||
 | 
					) -> Result<(), String> {
 | 
				
			||||||
 | 
					    match h.get(&r.p) {
 | 
				
			||||||
 | 
					        Some(&x) => Err(format!(
 | 
				
			||||||
 | 
					            "The robot id: {} collided with robot id: {} in position: ({};{}).",
 | 
				
			||||||
 | 
					            &r.id, x, &r.p.x, &r.p.y
 | 
				
			||||||
 | 
					        )),
 | 
				
			||||||
 | 
					        None => Ok(()),
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
/// Parse the config file, generate the world and robot pool.
 | 
					/// Parse the config file, generate the world and robot pool.
 | 
				
			||||||
fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::World, &'static str> {
 | 
					fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::World, &'static str> {
 | 
				
			||||||
    let mut lines = conf.lines();
 | 
					    let mut lines = conf.lines();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user