Skip to content

Commit e59483d

Browse files
committed
.
1 parent 045e7fa commit e59483d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/solver-r/src/grid.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ impl<T: Copy> Grid<T> {
8888
pub fn is_inside_margin(&self, p: &Point, m: i8) -> bool {
8989
-m <= p.x && p.x < (self.width as i8) + m && -m <= p.y && p.y < (self.height as i8) + m
9090
}
91+
92+
/**
93+
* ⚠️ assuming the point is inside the grid
94+
*/
95+
pub fn distance_from_outside(&self, p: &Point) -> u8 {
96+
let x = p.x as u8;
97+
let y = p.y as u8;
98+
y.min(self.height - 1 - y).min(x).min(self.width - 1 - x)
99+
}
91100
pub fn iter(&self) -> impl Iterator<Item = Point> {
92101
let mut i = 0;
93102
let width = self.width;

packages/solver-r/src/solver.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::collections::HashSet;
22

3+
use crate::exit_cost_grid::get_exit_cost_grid;
34
use crate::exitable::propagate_exitable;
4-
use crate::grid::{Color, Grid, Point, DIRECTIONS};
5+
use crate::grid::{Color, Grid, Point};
56
use crate::snake_walk::get_path_to_eat_all;
67

78
pub fn get_path_to_eat_everything(color_grid: &Grid<Color>, snake: &[Point]) -> Vec<Point> {
@@ -25,11 +26,17 @@ pub fn get_path_to_eat_everything(color_grid: &Grid<Color>, snake: &[Point]) ->
2526
let (mut sub_path, cells_unexitable) =
2627
get_path_to_eat_all(&color_grid, walkable, snake, &exitable_eatable);
2728

29+
for p in sub_path.iter() {
30+
color_grid.set(&p, Color::Empty);
31+
}
32+
2833
sub_path.append(&mut path);
2934
path = sub_path;
3035

3136
//
3237
// let's eat the one that are reachable but not exitable
38+
39+
let exit_cost_grid = get_exit_cost_grid(&color_grid);
3340
}
3441

3542
path

0 commit comments

Comments
 (0)