Skip to content

Commit 0aa48ee

Browse files
committed
Reorganized some files
1 parent 8b0db34 commit 0aa48ee

15 files changed

Lines changed: 33 additions & 18 deletions

File tree

Depth_First_Search/Lua/Yonaba/dfs.lua

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

3232
-- Dependencies
33-
local class = require 'class'
34-
local lifo = require 'lifo'
33+
local class = require 'utils.class'
34+
local lifo = require 'utils.lifo'
3535

3636
-- Clears nodes data between consecutive path requests.
3737
local function resetForNextSearch(dfs)

Depth_First_Search/Lua/Yonaba/dfs_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
ln_handler.init(-2,5)
3131
local dfs = DFS(ln_handler)
3232
local start, goal = ln_handler.getNode(0), ln_handler.getNode(5)
@@ -37,7 +37,7 @@ end)
3737

3838
run('Testing grid graph', function()
3939
local comp = function(a, b) return a.x == b[1] and a.y == b[2] end
40-
local gm_handler = require 'gridmap_handler'
40+
local gm_handler = require 'handlers.gridmap_handler'
4141
local dfs = DFS(gm_handler)
4242
local map = {{0,0,0,0,0},{0,1,1,1,1},{0,0,0,0,0}}
4343
gm_handler.init(map)
@@ -51,7 +51,7 @@ end)
5151

5252
run('Testing point graph', function()
5353
local comp = function(a, b) return a.x == b[1] and a.y == b[2] end
54-
local pg_handler = require 'point_graph_handler'
54+
local pg_handler = require 'handlers.point_graph_handler'
5555
local dfs = DFS(pg_handler)
5656

5757
pg_handler.addNode('a')

Depth_First_Search/Lua/Yonaba/gridmap_handler.lua renamed to Depth_First_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

Depth_First_Search/Lua/Yonaba/linear_handler.lua renamed to Depth_First_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

Depth_Limited_Search/Lua/Yonaba/point_graph_handler.lua renamed to Depth_First_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
File renamed without changes.

Depth_First_Search/Lua/Yonaba/lifo.lua renamed to Depth_First_Search/Lua/Yonaba/utils/lifo.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- Mimics a LIFO stack, OOP style
22

3-
local class = require 'class'
3+
local PATH = (...):gsub('%.lifo$','')
4+
local class = require (PATH .. '.class')
45

56
local lifo = class()
67
lifo._stack = {}

Depth_Limited_Search/Lua/Yonaba/node.lua renamed to Depth_First_Search/Lua/Yonaba/utils/node.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
-- See dfs.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 ()
1314
Node.__eq = function(a, b) return a:isEqualTo(b) end

Depth_Limited_Search/Lua/Yonaba/dls.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
-- See custom handlers for reference (*_hander.lua).
3232

3333
-- Dependencies
34-
local class = require 'class'
34+
local class = require 'utils.class'
3535

3636
-- Builds and returns the path to the goal node
3737
local function backtrace(node)

Depth_Limited_Search/Lua/Yonaba/dls_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
ln_handler.init(-2,5)
3131
local dls = DLS(ln_handler)
3232

@@ -46,7 +46,7 @@ end)
4646

4747
run('Testing grid graph', function()
4848
local comp = function(a, b) return a.x == b[1] and a.y == b[2] end
49-
local gm_handler = require 'gridmap_handler'
49+
local gm_handler = require 'handlers.gridmap_handler'
5050
local dls = DLS(gm_handler)
5151
local map = {{0,0,0,0,0},{0,1,1,1,1},{0,0,0,0,0}}
5252
gm_handler.init(map)
@@ -60,7 +60,7 @@ end)
6060

6161
run('Testing point graph', function()
6262
local comp = function(a, b) return a.x == b[1] and a.y == b[2] end
63-
local pg_handler = require 'point_graph_handler'
63+
local pg_handler = require 'handlers.point_graph_handler'
6464
local dls = DLS(pg_handler)
6565

6666
pg_handler.addNode('a')

0 commit comments

Comments
 (0)