|
@ -1,9 +1,5 @@ |
|
|
|
|
|
|
|
|
--[[============================================================================ |
|
|
|
|
|
----- GENERALLY USEFUL FUNCTIONS ----- |
|
|
|
|
|
============================================================================]]-- |
|
|
|
|
|
|
|
|
|
|
|
-- rounds numbers. would've been cool to have math.round in lua. |
|
|
|
|
|
|
|
|
-- Rounds Numbers. |
|
|
local function round(n) |
|
|
local function round(n) |
|
|
return n % 1 >= 0.5 and math.ceil(n) or math.floor(n) |
|
|
return n % 1 >= 0.5 and math.ceil(n) or math.floor(n) |
|
|
end |
|
|
end |
|
@ -12,35 +8,40 @@ end |
|
|
----- HEX CONSTANTS AND UTILITY FUNCTIONS ----- |
|
|
----- HEX CONSTANTS AND UTILITY FUNCTIONS ----- |
|
|
============================================================================]]-- |
|
|
============================================================================]]-- |
|
|
|
|
|
|
|
|
-- all possible vector directions from a given hex by edge |
|
|
|
|
|
local HEX_DIRECTIONS = {vec2( 0 , 1), |
|
|
|
|
|
vec2( 1 , 0), |
|
|
|
|
|
vec2( 1 , -1), |
|
|
|
|
|
vec2( 0 , -1), |
|
|
|
|
|
vec2(-1 , 0), |
|
|
|
|
|
vec2(-1 , 1)} |
|
|
|
|
|
|
|
|
-- Hex Equality - Meant to Operate on two Amulet Vectors (vec2) |
|
|
|
|
|
function hex_equals(a, b) return a[1] == b[1] and a[2] == b[2] end |
|
|
|
|
|
function hex_not_equals(a, b) return not hex_equals(a, b) end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- return hex vector direction via integer index |direction|. |
|
|
|
|
|
|
|
|
-- All Possible Vector Directions from a Given Hex by Edge |
|
|
|
|
|
local HEX_DIRECTIONS = {vec2( 0 , 1), vec2( 1 , 0), vec2( 1 , -1), |
|
|
|
|
|
vec2( 0 , -1), vec2(-1 , 0), vec2(-1 , 1)} |
|
|
|
|
|
|
|
|
|
|
|
-- Return Hex Vector Direction via Integer Index |direction|. |
|
|
function hex_direction(direction) |
|
|
function hex_direction(direction) |
|
|
return HEX_DIRECTIONS[(direction % 6) % 6 + 1] |
|
|
return HEX_DIRECTIONS[(direction % 6) % 6 + 1] |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- return hexagon adjacent to |hex| in integer index |direction|. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Return Hexagon Adjacent to |hex| in Integer Index |direction|. |
|
|
function hex_neighbour(hex, direction) |
|
|
function hex_neighbour(hex, direction) |
|
|
return hex + HEX_DIRECTIONS[(direction % 6) % 6 + 1] |
|
|
return hex + HEX_DIRECTIONS[(direction % 6) % 6 + 1] |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- return cube coords at location 60deg away to the left; counter-clockwise |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Return Hex 60deg away to the Left; Counter-Clockwise |
|
|
function hex_rotate_left(hex) |
|
|
function hex_rotate_left(hex) |
|
|
return vec2(hex.x + hex.y, -hex.x) |
|
|
return vec2(hex.x + hex.y, -hex.x) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- return cube coords at location 60deg away to the right; clockwise |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Return Hex 60deg away to the Right; Clockwise |
|
|
function hex_rotate_right(hex) |
|
|
function hex_rotate_right(hex) |
|
|
return vec2(-hex.y, hex.x + hex.y) |
|
|
return vec2(-hex.y, hex.x + hex.y) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- rounds a float coordinate trio |x, y, z| to nearest integer coordinate trio |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- NOT a General 3D Vector Round - Only Returns a vec2! |
|
|
local function hex_round(x, y, z) |
|
|
local function hex_round(x, y, z) |
|
|
local rx = round(x) |
|
|
local rx = round(x) |
|
|
local ry = round(y) |
|
|
local ry = round(y) |
|
@ -60,66 +61,66 @@ local function hex_round(x, y, z) |
|
|
return vec2(rx, ry) |
|
|
return vec2(rx, ry) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
--[[============================================================================ |
|
|
|
|
|
|
|
|
--[[==========================================================================-- |
|
|
----- ORIENTATION & LAYOUT ----- |
|
|
----- ORIENTATION & LAYOUT ----- |
|
|
============================================================================]]-- |
|
|
============================================================================]]-- |
|
|
|
|
|
|
|
|
-- forward & inverse matrices used for the flat orientation |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Forward & Inverse Matrices used for the Flat Orientation |
|
|
local FLAT = {M = mat2(3.0/2.0, 0.0, 3.0^0.5/2.0, 3.0^0.5 ), |
|
|
local FLAT = {M = mat2(3.0/2.0, 0.0, 3.0^0.5/2.0, 3.0^0.5 ), |
|
|
W = mat2(2.0/3.0, 0.0, -1.0/3.0 , 3.0^0.5/3.0), |
|
|
W = mat2(2.0/3.0, 0.0, -1.0/3.0 , 3.0^0.5/3.0), |
|
|
start_angle = 0.0} |
|
|
|
|
|
|
|
|
angle = 0.0} |
|
|
|
|
|
|
|
|
-- forward & inverse matrices used for the pointy orientation |
|
|
|
|
|
|
|
|
-- Forward & Inverse Matrices used for the Pointy Orientation |
|
|
local POINTY = {M = mat2(3.0^0.5, 3.0^0.5/2.0, 0.0, 3.0/2.0), |
|
|
local POINTY = {M = mat2(3.0^0.5, 3.0^0.5/2.0, 0.0, 3.0/2.0), |
|
|
W = mat2(3.0^0.5/3.0, -1.0/3.0, 0.0, 2.0/3.0), |
|
|
W = mat2(3.0^0.5/3.0, -1.0/3.0, 0.0, 2.0/3.0), |
|
|
start_angle = 0.5} |
|
|
|
|
|
|
|
|
angle = 0.5} |
|
|
|
|
|
|
|
|
-- stores layout: information that does not pertain to map shape |
|
|
|
|
|
function layout(origin, size, orientation) |
|
|
|
|
|
return {origin = origin or vec2(0), |
|
|
|
|
|
size = size or vec2(11), |
|
|
|
|
|
orientation = orientation or FLAT} |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
-- hex to screen |
|
|
|
|
|
function hex_to_pixel(hex, layout) |
|
|
|
|
|
local M = layout.orientation.M |
|
|
|
|
|
|
|
|
-- Hex to Screen -- Orientation Must be Either POINTY or FLAT |
|
|
|
|
|
function hex_to_pixel(hex, size, orientation_M) |
|
|
|
|
|
local M = orientation_M or FLAT.M |
|
|
|
|
|
|
|
|
local x = (M[1][1] * hex[1] + M[1][2] * hex[2]) * layout.size[1] |
|
|
|
|
|
local y = (M[2][1] * hex[1] + M[2][2] * hex[2]) * layout.size[2] |
|
|
|
|
|
|
|
|
local x = (M[1][1] * hex[1] + M[1][2] * hex[2]) * size[1] |
|
|
|
|
|
local y = (M[2][1] * hex[1] + M[2][2] * hex[2]) * size[2] |
|
|
|
|
|
|
|
|
return vec2(x + layout.origin[1], y + layout.origin[2]) |
|
|
|
|
|
|
|
|
return vec2(x, y) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- screen to hex |
|
|
|
|
|
function pixel_to_hex(pix, layout) |
|
|
|
|
|
local W = layout.orientation.W |
|
|
|
|
|
|
|
|
|
|
|
local pix = (pix - layout.origin) / layout.size |
|
|
|
|
|
|
|
|
-- Screen to Hex -- Orientation Must be Either POINTY or FLAT |
|
|
|
|
|
function pixel_to_hex(pix, size, orientation_W) |
|
|
|
|
|
local W = orientation_W or FLAT.W |
|
|
|
|
|
|
|
|
|
|
|
local pix = pix / size |
|
|
|
|
|
|
|
|
local s = W[1][1] * pix[1] + W[1][2] * pix[2] |
|
|
|
|
|
local t = W[2][1] * pix[1] + W[2][2] * pix[2] |
|
|
|
|
|
|
|
|
local x = W[1][1] * pix[1] + W[1][2] * pix[2] |
|
|
|
|
|
local y = W[2][1] * pix[1] + W[2][2] * pix[2] |
|
|
|
|
|
|
|
|
return hex_round(s, t, -s - t) |
|
|
|
|
|
|
|
|
return hex_round(x, y, -x - y) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- TODO test, learn am.draw |
|
|
-- TODO test, learn am.draw |
|
|
function hex_corner_offset(corner, layout) |
|
|
|
|
|
local angle = 2.0 * math.pi * layout.orientation.start_angle + corner / 6 |
|
|
|
|
|
return vec2(layout.size[1] * math.cos(angle), |
|
|
|
|
|
layout.size[2] * math.sin(angle)) |
|
|
|
|
|
|
|
|
function hex_corner_offset(corner, size, orientation_angle) |
|
|
|
|
|
local angle = 2.0 * math.pi * orientation_angle or FLAT.angle + corner / 6 |
|
|
|
|
|
return vec2(size[1] * math.cos(angle), |
|
|
|
|
|
size[2] * math.sin(angle)) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- TODO this thing |
|
|
-- TODO this thing |
|
|
function hex_corners(hex, layout) |
|
|
|
|
|
|
|
|
function hex_corners(hex, size, orientation) |
|
|
local corners = {} |
|
|
local corners = {} |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- offset coordinates are prettier to look at |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Offset Coordinates are Useful for UI-Implementations |
|
|
function hex_to_offset(hex) |
|
|
function hex_to_offset(hex) |
|
|
return vec2(hex[1], -hex[1] - hex[2] + (hex[1] + (hex[1] % 2)) / 2) |
|
|
return vec2(hex[1], -hex[1] - hex[2] + (hex[1] + (hex[1] % 2)) / 2) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- back to cube coordinates |
|
|
-- back to cube coordinates |
|
|
function offset_to_hex(off) |
|
|
function offset_to_hex(off) |
|
|
return vec2(off[1], off[2] - off[1] * (off[1] % 2) / 2) |
|
|
return vec2(off[1], off[2] - off[1] * (off[1] % 2) / 2) |
|
@ -128,7 +129,7 @@ end |
|
|
--[[============================================================================ |
|
|
--[[============================================================================ |
|
|
----- MAPS & STORAGE ----- |
|
|
----- MAPS & STORAGE ----- |
|
|
|
|
|
|
|
|
This means, you are not to draw using the coordinates stored in your map. |
|
|
|
|
|
|
|
|
You are not to draw using the coordinates stored in your map. |
|
|
You are to draw using the hex_to_pixel of those coordinates. |
|
|
You are to draw using the hex_to_pixel of those coordinates. |
|
|
|
|
|
|
|
|
If you wish to draw a hexagon to the screen, you must first use hex_to_pixel |
|
|
If you wish to draw a hexagon to the screen, you must first use hex_to_pixel |
|
@ -137,23 +138,21 @@ end |
|
|
am.circle with |sides| = 6, or gather the vertices with hex_corners and |
|
|
am.circle with |sides| = 6, or gather the vertices with hex_corners and |
|
|
use am.draw - TODO, haven't used am.draw yet. |
|
|
use am.draw - TODO, haven't used am.draw yet. |
|
|
|
|
|
|
|
|
Information about the maps' dimensions are stored in a metatable, so you can |
|
|
|
|
|
retrieve details about maps after they are created. |
|
|
|
|
|
|
|
|
Maps have metatables containing information about their dimensions, and |
|
|
|
|
|
seed (if applicable), so you can retrieve information about maps after they |
|
|
|
|
|
are created. |
|
|
|
|
|
|
|
|
----- NOISE ----- |
|
|
----- NOISE ----- |
|
|
To simplify terrain generation, unordered, hash-like maps automatically |
|
|
To simplify terrain generation, unordered, hash-like maps automatically |
|
|
calculate and store simplex noise as their values. You can modify the nature |
|
|
|
|
|
of the noise by providing different |frequencies| as a tables of values, for |
|
|
|
|
|
example: {1, 2, 4, 8} or {1, 0.5, 0.25, 0.125}. These just increase the |
|
|
|
|
|
complexity of the curvature of the noise. The default is {1}. |
|
|
|
|
|
|
|
|
calculate and store seeded simplex noise as their values. You can provide |
|
|
|
|
|
a seed if you wish. The default is a randomized seed. |
|
|
|
|
|
|
|
|
----- TODO ----- |
|
|
|
|
|
make all functions work regardless of layout. as it stands, they kind |
|
|
|
|
|
of do, just not always nicely. |
|
|
|
|
|
|
|
|
TODO Pointy Hex testing and support. |
|
|
|
|
|
|
|
|
============================================================================]]-- |
|
|
============================================================================]]-- |
|
|
|
|
|
|
|
|
-- returns ordered ring-shaped map of |radius| from |center|. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Returns Ordered Ring-Shaped Map of |radius| from |center| |
|
|
function ring_map(center, radius) |
|
|
function ring_map(center, radius) |
|
|
local map = {} |
|
|
local map = {} |
|
|
|
|
|
|
|
@ -169,7 +168,8 @@ function ring_map(center, radius) |
|
|
return map |
|
|
return map |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- returns ordered spiral hexagonal map of |radius| rings from |center|. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Returns Ordered Spiral Hexagonal Map of |radius| Rings from |center| |
|
|
function spiral_map(center, radius) |
|
|
function spiral_map(center, radius) |
|
|
local map = {center} |
|
|
local map = {center} |
|
|
|
|
|
|
|
@ -180,50 +180,52 @@ function spiral_map(center, radius) |
|
|
return map |
|
|
return map |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- returns unordered parallelogram-shaped map of |width| and |height| with simplex noise |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Returns Unordered Parallelogram-Shaped Map of |width| and |height| with Simplex Noise |
|
|
function parallelogram_map(width, height, seed) |
|
|
function parallelogram_map(width, height, seed) |
|
|
local seed = seed or math.random(width * height) |
|
|
local seed = seed or math.random(width * height) |
|
|
|
|
|
|
|
|
-- fill the map |
|
|
|
|
|
local map = {} |
|
|
local map = {} |
|
|
|
|
|
|
|
|
for i = 0, width do |
|
|
for i = 0, width do |
|
|
for j = 0, height do |
|
|
for j = 0, height do |
|
|
|
|
|
|
|
|
-- generate noise |
|
|
|
|
|
|
|
|
-- Calculate Noise |
|
|
local idelta = i / width |
|
|
local idelta = i / width |
|
|
local jdelta = j / height |
|
|
local jdelta = j / height |
|
|
local noise = 0 |
|
|
local noise = 0 |
|
|
|
|
|
|
|
|
for oct = 1, math.max(width, height) do |
|
|
|
|
|
noise = noise + 1/4^oct * math.simplex(vec2(idelta + seed * width, jdelta + seed * height) * 2^oct) |
|
|
|
|
|
|
|
|
for oct = 1, 6 do |
|
|
|
|
|
local f = 1/4^oct |
|
|
|
|
|
local l = 2^oct |
|
|
|
|
|
local pos = vec2(idelta + seed * width, jdelta + seed * height) |
|
|
|
|
|
noise = noise + f * math.simplex(pos * l) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- straightforward iteration produces a parallelogram |
|
|
|
|
|
map[vec2(i, j)] = noise |
|
|
|
|
|
|
|
|
map[vec2(i, j)] = noise -- Straightforward Iteration Produces a Parallelogram |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
setmetatable(map, {__index={width=width, height=height, seed=seed}}) |
|
|
setmetatable(map, {__index={width=width, height=height, seed=seed}}) |
|
|
return map |
|
|
return map |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- returns unordered triangular map of |size| with simplex noise |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Returns Unordered Triangular Map of |size| with Simplex Noise |
|
|
function triangular_map(size, seed) |
|
|
function triangular_map(size, seed) |
|
|
local seed = seed or math.random(size) |
|
|
local seed = seed or math.random(size) |
|
|
|
|
|
|
|
|
-- fill the map |
|
|
|
|
|
local map = {} |
|
|
local map = {} |
|
|
|
|
|
|
|
|
for i = 0, size do |
|
|
for i = 0, size do |
|
|
for j = size - i, size do |
|
|
for j = size - i, size do |
|
|
|
|
|
|
|
|
-- generate noise |
|
|
|
|
|
|
|
|
-- Generate Noise |
|
|
local idelta = i / size |
|
|
local idelta = i / size |
|
|
local jdelta = j / size |
|
|
local jdelta = j / size |
|
|
local noise = 0 |
|
|
local noise = 0 |
|
|
|
|
|
|
|
|
for oct = 1, size do |
|
|
|
|
|
noise = noise + 1/3^oct * math.simplex(vec2(idelta + seed * size, jdelta + seed * size) * 2^oct) |
|
|
|
|
|
|
|
|
for oct = 1, 6 do |
|
|
|
|
|
local f = 1/3^oct |
|
|
|
|
|
local l = 2^oct |
|
|
|
|
|
local pos = vec2(idelta + seed * size, jdelta + seed * size) |
|
|
|
|
|
noise = noise + f * math.simplex(pos * l) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
map[vec2(i, j)] = noise |
|
|
map[vec2(i, j)] = noise |
|
@ -233,47 +235,61 @@ function triangular_map(size, seed) |
|
|
return map |
|
|
return map |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- returns unordered hexagonal map of |radius| with simplex noise |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Returns Unordered Hexagonal Map of |radius| with Simplex Noise |
|
|
function hexagonal_map(radius, seed) |
|
|
function hexagonal_map(radius, seed) |
|
|
local seed = seed or math.random(radius * 2) |
|
|
|
|
|
|
|
|
local seed = seed or math.random(radius * 2 + 1) |
|
|
|
|
|
|
|
|
-- fill the map |
|
|
|
|
|
local map = {} |
|
|
local map = {} |
|
|
|
|
|
|
|
|
for i = -radius, radius do |
|
|
for i = -radius, radius do |
|
|
local j1 = math.max(-radius, -i - radius) |
|
|
local j1 = math.max(-radius, -i - radius) |
|
|
local j2 = math.min(radius, -i + radius) |
|
|
local j2 = math.min(radius, -i + radius) |
|
|
|
|
|
|
|
|
for j = j1, j2 do |
|
|
for j = j1, j2 do |
|
|
map[vec2(i, j)] = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Calculate Noise |
|
|
|
|
|
local idelta = i / radius |
|
|
|
|
|
local jdelta = j / radius |
|
|
|
|
|
local noise = 0 |
|
|
|
|
|
|
|
|
|
|
|
for oct = 1, 6 do |
|
|
|
|
|
|
|
|
|
|
|
local f = 2/3^oct -- NOTE, for some reason, I found 2/3 produces better looking noise maps. As far as I am aware, this is weird. |
|
|
|
|
|
local l = 2^oct |
|
|
|
|
|
local pos = vec2(idelta + seed * radius, jdelta + seed * radius) |
|
|
|
|
|
|
|
|
|
|
|
noise = noise + f * math.simplex(pos * l) |
|
|
|
|
|
end |
|
|
|
|
|
map[vec2(i, j)] = noise |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
setmetatable(map, {__index={radius=radius, seed=seed}}) |
|
|
setmetatable(map, {__index={radius=radius, seed=seed}}) |
|
|
return map |
|
|
return map |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
-- returns unordered rectangular map of |width| and |height| with simplex noise |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Returns Unordered Rectangular Map of |width| and |height| with Simplex Noise |
|
|
function rectangular_map(width, height, seed) |
|
|
function rectangular_map(width, height, seed) |
|
|
local seed = seed or math.random(width * height) |
|
|
local seed = seed or math.random(width * height) |
|
|
|
|
|
|
|
|
-- fill the map |
|
|
|
|
|
local map = {} |
|
|
local map = {} |
|
|
|
|
|
|
|
|
for i = 0, width do |
|
|
for i = 0, width do |
|
|
for j = 0, height do |
|
|
for j = 0, height do |
|
|
|
|
|
|
|
|
-- generate noise |
|
|
|
|
|
|
|
|
-- Calculate Noise |
|
|
local idelta = i / width |
|
|
local idelta = i / width |
|
|
local jdelta = j / height |
|
|
local jdelta = j / height |
|
|
local noise = 0 |
|
|
local noise = 0 |
|
|
|
|
|
|
|
|
for oct = 1, math.max(width, height) do |
|
|
|
|
|
noise = noise + 2/3^oct * math.simplex(vec2(idelta + seed*width, |
|
|
|
|
|
jdelta + seed*height |
|
|
|
|
|
* 2^oct)) |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
for oct = 1, 6 do |
|
|
|
|
|
|
|
|
-- store hex in the map paired with its associated noise value |
|
|
|
|
|
|
|
|
local f = 2/3^oct |
|
|
|
|
|
local l = 2^oct |
|
|
|
|
|
local pos = vec2(idelta + seed * width, jdelta + seed * height) |
|
|
|
|
|
|
|
|
|
|
|
noise = noise + f * math.simplex(pos * l) |
|
|
|
|
|
end |
|
|
|
|
|
-- Store Hex in the Map Paired with its Associated Noise Value |
|
|
map[vec2(i, j - math.floor(i/2))] = noise |
|
|
map[vec2(i, j - math.floor(i/2))] = noise |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
@ -281,22 +297,45 @@ function rectangular_map(width, height, seed) |
|
|
return map |
|
|
return map |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
--[[============================================================================ |
|
|
|
|
|
|
|
|
--[[==========================================================================-- |
|
|
----- PATHFINDING ----- |
|
|
----- PATHFINDING ----- |
|
|
============================================================================]]-- |
|
|
============================================================================]]-- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- first try |
|
|
|
|
|
function search(map, start) |
|
|
|
|
|
local neighbours |
|
|
|
|
|
for i = 1, 6 do |
|
|
|
|
|
neighbours[#neighbours + 1] = hex_neighbour(start, i) |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--[[============================================================================ |
|
|
|
|
|
----- TESTS ----- |
|
|
|
|
|
============================================================================]]-- |
|
|
|
|
|
|
|
|
|
|
|
function test_all() |
|
|
|
|
|
print("it works trust me") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- |
|
|
|
|
|
function breadth_first_search(map, start) |
|
|
|
|
|
local frontier = {start} |
|
|
|
|
|
|
|
|
|
|
|
local visited = {start = true} |
|
|
|
|
|
|
|
|
|
|
|
while next(frontier) ~= nil do |
|
|
|
|
|
local current = next(frontier) |
|
|
|
|
|
local neighbours |
|
|
|
|
|
for i = 1, 6 do |
|
|
|
|
|
neighbours[#neighnours + 1] = hex_neighbour(current, i) |
|
|
|
|
|
end |
|
|
|
|
|
for _,n in neighbours do |
|
|
|
|
|
if visited[n] ~= true then |
|
|
|
|
|
visited[n] = true |
|
|
|
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|