|
|
@ -25,10 +25,18 @@ impl City { |
|
|
|
self.prices[house.y * SIZE + house.x] |
|
|
|
} |
|
|
|
|
|
|
|
pub fn get_price_xy(&self, x: usize, y: usize) -> u16 { |
|
|
|
self.prices[y * SIZE + x] |
|
|
|
} |
|
|
|
|
|
|
|
pub fn is_house(&self, house: &House) -> bool { |
|
|
|
self.get_price(&house) > 0 |
|
|
|
} |
|
|
|
|
|
|
|
pub fn is_house_xy(&self, x: usize, y: usize) -> bool { |
|
|
|
self.get_price_xy(x, y) > 0 |
|
|
|
} |
|
|
|
|
|
|
|
pub fn get_house_count(&self) -> usize { |
|
|
|
self.buyable_house_count |
|
|
|
} |
|
|
@ -72,13 +80,13 @@ fn main() { |
|
|
|
let x = rng.gen_range(0..SIZE); |
|
|
|
let y = rng.gen_range(0..SIZE); |
|
|
|
let house = House::new(x, y); |
|
|
|
if city.is_house(&house) && !reachable[y * SIZE + x] { |
|
|
|
if city.is_house_xy(x, y) && !reachable[y * SIZE + x] { |
|
|
|
for y in (house.y as i32 - 500).max(0)..=(house.y as i32 + 500).min((SIZE - 1) as i32) { |
|
|
|
for x in (house.x as i32 - 500).max(0)..=(house.x as i32 + 500).min((SIZE - 1) as i32) { |
|
|
|
let index = y as usize * SIZE + x as usize; |
|
|
|
if !reachable[index] { |
|
|
|
reachable[index] = true; |
|
|
|
if city.is_house(&House::new(x as usize, y as usize)) { |
|
|
|
if city.is_house_xy(x as usize, y as usize) { |
|
|
|
claimed_houses += 1; |
|
|
|
} |
|
|
|
} |
|
|
|