randomize spawned paths a bit

This commit is contained in:
Dustin Carlino 2019-02-19 16:11:42 -08:00
parent 28984075cc
commit 6aafb908b6
2 changed files with 16 additions and 9 deletions

View File

@ -21,6 +21,9 @@ map_model = { path = "../map_model" }
ordered-float = "1.0.1"
pretty_assertions = "0.5.1"
quick-xml = "0.13.1"
# TODO Just for the DES model prototype
rand = "0.6.5"
rand_xorshift = "0.1.1"
serde = "1.0.87"
serde_derive = "1.0.87"
sim = { path = "../sim" }

View File

@ -4,6 +4,9 @@ use crate::plugins::{BlockingPlugin, PluginCtx};
use ezgui::{EventLoopMode, GfxCtx, Key};
use geom::Duration;
use map_model::{LaneID, Map, Traversable};
use rand::seq::SliceRandom;
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use sim::{CarID, VehicleType};
const TIMESTEP: Duration = Duration::const_seconds(0.1);
@ -88,17 +91,18 @@ fn populate_world(start: LaneID, map: &Map) -> new_des_model::World {
}
}
let mut rng = XorShiftRng::from_seed([42; 16]);
for source in sources {
let mut path = vec![Traversable::Lane(source)];
let mut last_lane = source;
for _ in 0..5 {
let t = map.get_turns_from_lane(last_lane)[0];
path.push(Traversable::Turn(t.id));
path.push(Traversable::Lane(t.id.dst));
last_lane = t.id.dst;
}
for i in 0..10 {
let mut path = vec![Traversable::Lane(source)];
let mut last_lane = source;
for _ in 0..5 {
let t = *map.get_turns_from_lane(last_lane).choose(&mut rng).unwrap();
path.push(Traversable::Turn(t.id));
path.push(Traversable::Lane(t.id.dst));
last_lane = t.id.dst;
}
world.spawn_car(
CarID::tmp_new(i, VehicleType::Car),
None,