Micromouse/src/map.zig

67 lines
1.6 KiB
Zig

// This file is for general purpose map-like stuff
// Details of the maze, the current maze state, etc, are actually in algorithm
const assert = @import("std").debug.assert;
pub const Point = struct {
x: usize,
y: usize,
pub fn eq (self: Point, other: Point) bool {
return self.x == other.x and self.y == other.y;
}
};
pub const Cardinal = enum {
north,
east,
south,
west
};
pub const TurningDirection = enum {
left,
right
};
// While we're here, we might as well generalize to a non-square maze
pub const width = 16;
pub const height = 16;
pub const numTiles = width * width;
// pub fn isGoal (p: Point) bool {
// // with a 10 x 10, this should be (4, 4), (4, 5), (5, 4), (5, 5)
// // assert we have an even width and height
// assert(width % 2 == 0);
// assert(height % 2 == 0);
// return (
// (p.x == width / 2 && p.y == height / 2)
// || (p.x == width / 2 && p.y == height / 2 + 1)
// || (p.x == width / 2 + 1 && p.y == height / 2)
// || (p.x == width / 2 + 1 && p.y == height / 2 + 1)
// );
// }
pub const goals = [4]Point{
Point { .x = width / 2 , .y = height / 2 },
Point { .x = width / 2 , .y = height / 2 - 1},
Point { .x = width / 2 - 1 , .y = height / 2 },
Point { .x = width / 2 - 1 , .y = height / 2 - 1}
};
// This should be compile-time accessible
comptime {
// @compileLog(goals);
}
pub fn isGoal (p: Point) bool {
for (goals) |goalPoint| {
if (p.x == goalPoint.x and p.y == goalPoint.y) {
return true;
}
}
return false;
}
pub const start = Point { .x = 0, .y = 0 };