Skip to content

Commit 8073d7e

Browse files
committed
Better file organization
1 parent a29bff0 commit 8073d7e

8 files changed

Lines changed: 18 additions & 10 deletions

File tree

A_Star_Search/Lua/Yonaba/astar.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
-- See custom handlers for reference (*_hander.lua).
3434

3535
-- Dependencies
36-
local class = require 'class'
37-
local bheap = require 'bheap'
36+
local class = require 'utils.class'
37+
local bheap = require 'utils.bheap'
3838

3939
-- Clears data between consecutive path requests.
4040
local function resetForNextSearch(astar)

A_Star_Search/Lua/Yonaba/astar_test.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ end
2626

2727
run('Testing linear graph', function()
2828
local comp = function(a, b) return a.value == b end
29-
local ln_handler = require 'linear_handler'
29+
local ln_handler = require 'handlers.linear_handler'
3030
local astar = Astar(ln_handler)
3131
ln_handler.init(-2,5)
3232
local start, goal = ln_handler.getNode(0), ln_handler.getNode(5)
@@ -38,7 +38,7 @@ end)
3838

3939
run('Testing grid graph', function()
4040
local comp = function(a, b) return a.x == b[1] and a.y == b[2] end
41-
local gm_handler = require 'gridmap_handler'
41+
local gm_handler = require 'handlers.gridmap_handler'
4242
local astar = Astar(gm_handler)
4343
local map = {{0,0,0,0,0},{0,1,1,1,1},{0,0,0,0,0}}
4444
gm_handler.init(map)
@@ -53,7 +53,7 @@ end)
5353

5454
run('Testing point graph', function()
5555
local comp = function(a, b) return a.x == b[1] and a.y == b[2] end
56-
local pg_handler = require 'point_graph_handler'
56+
local pg_handler = require 'handlers.point_graph_handler'
5757
local astar = Astar(pg_handler)
5858

5959
pg_handler.addNode('a')

A_Star_Search/Lua/Yonaba/gridmap_handler.lua renamed to A_Star_Search/Lua/Yonaba/handlers/gridmap_handler.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
-- with a pair of (x, y) coordinates. It features straight (4-directions)
66
-- and diagonal (8-directions) moves.
77

8+
local PATH = (...):gsub('handlers.gridmap_handler$','')
9+
local Node = require (PATH .. '.utils.node')
10+
811
-- Implements Node class (from node.lua)
9-
local Node = require 'node'
1012
function Node:initialize(x, y) self.x, self.y = x, y end
1113
function Node:toString() return ('Node: x = %d, y = %d'):format(self.x, self.y) end
1214
function Node:isEqualTo(n) return self.x == n.x and self.y == n.y end

A_Star_Search/Lua/Yonaba/linear_handler.lua renamed to A_Star_Search/Lua/Yonaba/handlers/linear_handler.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
-- Similar to a range (interval) with no bounds.
66
-- i.e., the path from 5 to 0 would be 5, 4, 3, 2, 1, 0.
77

8+
local PATH = (...):gsub('handlers.linear_handler$','')
9+
local Node = require (PATH .. '.utils.node')
10+
811
-- Implements Node class (from node.lua)
9-
local Node = require 'node'
1012
function Node:initialize(value) self.value = value end
1113
function Node:toString() return ('Node: %d'):format(self.value) end
1214
function Node:isEqualTo(n) return self.value == n.value end

A_Star_Search/Lua/Yonaba/point_graph_handler.lua renamed to A_Star_Search/Lua/Yonaba/handlers/point_graph_handler.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
-- It assumes edges are symmetric, that is if an edge exists
77
-- between a and b, weight(a -> b) == weight(b -> a)
88

9+
local PATH = (...):gsub('handlers.point_graph_handler$','')
10+
local Node = require (PATH .. '.utils.node')
11+
912
-- Implements Node class (from node.lua)
10-
local Node = require 'node'
1113
function Node:initialize(name) self.name = name end
1214
function Node:toString() return ('Node: %s'):format(self.name) end
1315
function Node:isEqualTo(n) return self.name == n.name end
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
-- See: http://www.policyalmanac.org/games/binaryHeaps.htm
33
-- Adapted from: https://github.com/Yonaba/Binary-Heaps
44

5-
local class = require 'class'
5+
local PATH = (...):gsub('%.bheap$','')
6+
local class = require (PATH .. '.class')
67

78
-- Looks for item in an array
89
local function findIndex(array, item)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
-- See astar.lua comment header.
88
-- See custom handlers for reference (*_hander.lua).
99

10-
local class = require 'class'
10+
local PATH = (...):gsub('%.node$','')
11+
local class = require (PATH .. '.class')
1112

1213
local Node = class {f = 0, g = 0, h = 0}
1314
Node.__eq = function(a, b) return a:isEqualTo(b) end

0 commit comments

Comments
 (0)