Merge branch 'random-world' into 'master'
Random world See merge request mhart/DancingDroids!48
This commit is contained in:
		
						commit
						f424f66650
					
				@ -1,10 +1,10 @@
 | 
				
			|||||||
/// A Robot *aka droid* is represented here.
 | 
					 | 
				
			||||||
/// Each robot must have a unique id.
 | 
					 | 
				
			||||||
use rand::{
 | 
					use rand::{
 | 
				
			||||||
    distributions::{Distribution, Standard},
 | 
					    distributions::{Distribution, Standard},
 | 
				
			||||||
    Rng,
 | 
					    Rng,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// A Robot *aka droid* is represented here.
 | 
				
			||||||
 | 
					/// Each robot must have a unique id.
 | 
				
			||||||
pub struct Robot {
 | 
					pub struct Robot {
 | 
				
			||||||
    pub id: u32,
 | 
					    pub id: u32,
 | 
				
			||||||
    pub o: Orientation,
 | 
					    pub o: Orientation,
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										25
									
								
								src/world.rs
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								src/world.rs
									
									
									
									
									
								
							@ -1,5 +1,30 @@
 | 
				
			|||||||
 | 
					use rand::Rng;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// The World is represented here.
 | 
					/// The World is represented here.
 | 
				
			||||||
pub struct World {
 | 
					pub struct World {
 | 
				
			||||||
    pub x: i32,
 | 
					    pub x: i32,
 | 
				
			||||||
    pub y: i32,
 | 
					    pub y: i32,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Create a random World.
 | 
				
			||||||
 | 
					pub fn random_world() -> World {
 | 
				
			||||||
 | 
					    let mut rng = rand::thread_rng();
 | 
				
			||||||
 | 
					    let z = rng.gen_range(5, 50);
 | 
				
			||||||
 | 
					    World { x: z, y: z }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[cfg(test)]
 | 
				
			||||||
 | 
					mod tests {
 | 
				
			||||||
 | 
					    use super::*;
 | 
				
			||||||
 | 
					    use std::any::type_name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn type_of<T>(_: T) -> &'static str {
 | 
				
			||||||
 | 
					        type_name::<T>()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[test]
 | 
				
			||||||
 | 
					    fn test_random_world() {
 | 
				
			||||||
 | 
					        let w = random_world();
 | 
				
			||||||
 | 
					        assert_eq!(type_of(w), "dancing_droid::world::World");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user