MCPcopy Create free account
hub / github.com/battlecode/battlecode-2018 / ok_if_can_sense_location

Method ok_if_can_sense_location

battlecode-engine/src/world.rs:554–574  ·  view source on GitHub ↗

LocationOffMap - the location is off the map. LocationNotVisible - the location is outside the vision range.

(&self, location: MapLocation)

Source from the content-addressed store, hash-verified

552 /// * LocationOffMap - the location is off the map.
553 /// * LocationNotVisible - the location is outside the vision range.
554 fn ok_if_can_sense_location(&self, location: MapLocation) -> Result<(), GameError> {
555 if self.planet() != location.planet {
556 return Err(GameError::LocationOffMap)?;
557 }
558
559 if location.x < 0 || location.y < 0 {
560 return Err(GameError::LocationOffMap)?;
561 }
562
563 let map = self.starting_map(location.planet);
564 if location.x >= map.width as i32 || location.y >= map.height as i32 {
565 return Err(GameError::LocationOffMap)?;
566 }
567
568 let x = location.x as usize;
569 let y = location.y as usize;
570 if !self.my_planet().visible_locs[y][x] {
571 return Err(GameError::LocationNotVisible)?;
572 }
573 Ok(())
574 }
575
576 /// Whether the location is on the map and within the vision range.
577 pub fn can_sense_location(&self, location: MapLocation) -> bool {

Callers 5

karbonite_atMethod · 0.80
can_sense_locationMethod · 0.80
is_occupiableMethod · 0.80
ok_if_can_moveMethod · 0.80

Calls 3

my_planetMethod · 0.80
planetMethod · 0.45
starting_mapMethod · 0.45

Tested by

no test coverage detected