Something went wrong. Try again.
A puzzle game of bent arrows sent off a board of dots, written in Zig.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! Levels: what each number's board is built from.//!//! A level's seed is derived from its number alone, and the generator is//! deterministic, so level 37 is the same board for everyone. Changing the//! table below, the generator, or `seed` changes the levels people have//! already played, which is worth doing only on purpose.
const std = @import("std");const Allocator = std.mem.Allocator;
const Board = @import("Board.zig");const generate = @import("generate.zig");const Random = @import("Random.zig");
/// Levels count from one.pub const Number = u32;
const Tier = struct { /// The last level this tier covers. through: Number, params: generate.Params,};
/// How the levels get harder, tier by tier; the last one goes on for ever./// Tuned by playing.const tiers = [_]Tier{ .{ .through = 3, .params = .{ .width = 5, .height = 5, .fill = 50, .min_length = 2, .max_length = 3, .turn = 10 } }, .{ .through = 8, .params = .{ .width = 6, .height = 6, .fill = 55, .min_length = 2, .max_length = 4, .turn = 20 } }, .{ .through = 15, .params = .{ .width = 8, .height = 8, .fill = 60, .min_length = 2, .max_length = 5, .turn = 25 } }, .{ .through = 25, .params = .{ .width = 10, .height = 10, .fill = 65, .min_length = 2, .max_length = 6, .turn = 30 } }, .{ .through = 40, .params = .{ .width = 12, .height = 12, .fill = 70, .min_length = 3, .max_length = 8, .turn = 35 } }, .{ .through = 60, .params = .{ .width = 14, .height = 14, .fill = 75, .min_length = 3, .max_length = 10, .turn = 40 } }, .{ .through = std.math.maxInt(Number), .params = .{ .width = 16, .height = 16, .fill = 80, .min_length = 3, .max_length = 12, .turn = 45 } },};
pub fn params(number: Number) generate.Params { std.debug.assert(number >= 1); for (tiers) |tier| if (number <= tier.through) return tier.params; unreachable;}
pub fn seed(number: Number) u64 { var r: Random = .init(number); return r.next();}
/// The board for level `number`.pub fn board(gpa: Allocator, number: Number) (Board.Error || Allocator.Error)!Board { return generate.generate(gpa, params(number), seed(number));}
const testing = std.testing;
test "the tiers are in order and every level has one" { var last: Number = 0; for (tiers) |tier| { try testing.expect(tier.through > last); last = tier.through; } try testing.expectEqual(std.math.maxInt(Number), last);}
test "every early level can be cleared" { const solve = @import("solve.zig").solve; for (1..80) |n| { var b = try board(testing.allocator, @intCast(n)); defer b.deinit(testing.allocator); try testing.expect(b.arrowCount() > 0); const order = (try solve(testing.allocator, &b)).?; testing.allocator.free(order); }}
test "level 1 is the board it has always been" { // If this fails, every level has changed: see the top of this file. var b = try board(testing.allocator, 1); defer b.deinit(testing.allocator); var out: std.Io.Writer.Allocating = .init(testing.allocator); defer out.deinit(); try @import("text.zig").format(&b, &out.writer); try testing.expectEqualStrings( \\5x5 \\0,2 0,3 \\3,4 3,3 \\2,2 2,1 \\1,4 1,3 1,2 \\1,0 2,0 3,0 \\ , out.written());}