BHYPRVIESUYRESS3VBV62SHGMNJKPKQXZDOSJM3BRBZGYNVYFF6QC
var grid = try PF.Grid(usize, 100, 100, .HV).ParseGridFromCSV("grid-test.txt", ",");
const ret = try grid.dijkstra(std.testing.allocator, .{ 0, 0 }, .{ 99, 99 });
var grid = PF.Grid(usize, 100, 100).init(std.testing.allocator);
defer grid.deinit();
try grid.parseGridFromCSV("grid-test.txt", ",");
var ret = try grid.dijkstra(.{ 0, 0 }, .{ 99, 99 }, PF.D2.HV);
test "Grid usize move down and right" {
var grid = try PF.Grid(usize, 100, 100, [2][2]isize{ .{ 0, 1 }, .{ 1, 0 } }).ParseGridFromCSV("grid-test.txt", ",");
const ret = try grid.dijkstra(std.testing.allocator, .{ 0, 0 }, .{ 99, 99 });
// right and down
ret = try grid.dijkstra(.{ 0, 0 }, .{ 99, 99 }, [2][2]isize{ .{ 0, 1 }, .{ 1, 0 } });
test "Grid usize move down and left" {
var grid = try PF.Grid(usize, 100, 100, [2][2]isize{ .{ 1, 0 }, .{ 1, 0 } }).ParseGridFromCSV("grid-test.txt", ",");
const ret = grid.dijkstra(std.testing.allocator, .{ 0, 0 }, .{ 99, 99 });
try std.testing.expectError(error.PathNotFound, ret);
// down and left => no path
const err = grid.dijkstra(.{ 0, 0 }, .{ 99, 99 }, [2][2]isize{ .{ 1, 0 }, .{ 1, 0 } });
try std.testing.expectError(error.PathNotFound, err);
var grid = try PF.Grid(isize, 100, 100, .diagonal).ParseGridFromCSV("grid-test.txt", ",");
const ret = try grid.dijkstra(std.testing.allocator, .{ 0, 0 }, .{ 99, 99 });
var grid = PF.Grid(isize, 100, 100).init(std.testing.allocator);
defer grid.deinit();
try grid.parseGridFromCSV("grid-test.txt", ",");
const ret = try grid.dijkstra(.{ 0, 0 }, .{ 99, 99 }, PF.D2.diagonal);
var grid = try PF.Grid(f64, 100, 100, .all).ParseGridFromCSV("grid-test.txt", ",");
const ret = try grid.dijkstra(std.testing.allocator, .{ 0, 0 }, .{ 99, 99 });
var grid = PF.Grid(f64, 100, 100).init(std.testing.allocator);
defer grid.deinit();
try grid.parseGridFromCSV("grid-test.txt", ",");
const ret = try grid.dijkstra(.{ 0, 0 }, .{ 99, 99 }, PF.D2.all);
pub const D2Neighbour = enum {
horizontal,
vertical,
HV,
diagonal,
all,
pub const D2 = struct {
pub const horizontal = [_][2]i2{ .{ 0, -1 }, .{ 0, 1 } };
pub const vertical = [_][2]i2{ .{ -1, 0 }, .{ 1, 0 } };
pub const HV = horizontal ++ vertical;
pub const diagonal = [_][2]i2{ .{ -1, -1 }, .{ -1, 1 }, .{ 1, -1 }, .{ 1, 1 } };
pub const all = HV ++ diagonal;
const horizontal = [_][2]isize{ .{ 0, -1 }, .{ 0, 1 } };
const vertical = [_][2]isize{ .{ -1, 0 }, .{ 1, 0 } };
const HV = horizontal ++ vertical;
const diagonal = [_][2]isize{ .{ -1, -1 }, .{ -1, 1 }, .{ 1, -1 }, .{ 1, 1 } };
const all = HV ++ diagonal;
pub fn Grid(comptime T: type, comptime GRID_ROWS: usize, comptime GRID_COLS: usize, dir: anytype) type {
const dir_slice: [][]isize = blk: {
var dir_array = switch (@typeInfo(@TypeOf(dir))) {
.EnumLiteral, .Enum => switch (std.enums.nameCast(D2Neighbour, dir)) {
.horizontal => horizontal,
.vertical => vertical,
.HV => HV,
.diagonal => diagonal,
.all => all,
},
else => dir,
};
var ret: [dir_array.len][]isize = undefined;
for (dir_array) |*sub_array_ptr, idx| ret[idx] = sub_array_ptr;
break :blk ret[0..];
};
pub fn Grid(comptime T: type, comptime GRID_ROWS: usize, comptime GRID_COLS: usize) type {