MCPcopy Index your code
hub / github.com/battlecode/battlecode-2018 / random

Method random

battlecode-engine/src/map/mod.rs:452–481  ·  view source on GitHub ↗

Constructs a pseudorandom asteroid pattern given a map of Mars.

(seed: u16, mars_map: &PlanetMap)

Source from the content-addressed store, hash-verified

450
451 /// Constructs a pseudorandom asteroid pattern given a map of Mars.
452 pub fn random(seed: u16, mars_map: &PlanetMap) -> AsteroidPattern {
453 let mut pattern: FnvHashMap<Rounds, AsteroidStrike> = FnvHashMap::default();
454
455 let karbonite_gen = Range::new(ASTEROID_KARB_MIN, ASTEROID_KARB_MAX);
456 let round_gen = Range::new(0, 40);
457 let x_gen = Range::new(0, mars_map.width as i32);
458 let y_gen = Range::new(0, mars_map.height as i32);
459
460 let seed: &[_] = &[seed as usize];
461 let mut rng: StdRng = SeedableRng::from_seed(seed);
462 let mut round = 0;
463 loop {
464 round += round_gen.ind_sample(&mut rng);
465 if round >= ROUND_LIMIT {
466 break;
467 }
468 pattern.insert(round, AsteroidStrike {
469 karbonite: karbonite_gen.ind_sample(&mut rng),
470 location: MapLocation {
471 planet: Planet::Mars,
472 x: x_gen.ind_sample(&mut rng),
473 y: y_gen.ind_sample(&mut rng),
474 },
475 });
476 }
477
478 AsteroidPattern {
479 pattern: pattern,
480 }
481 }
482
483 /// Validates the asteroid pattern.
484 ///

Callers 4

matchmaker.pyFile · 0.80
get_next_messageMethod · 0.80
send_messageMethod · 0.80
player_handlerMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected