Awww man, I've got no Idea what's goin' on.

Bobert13

Prince
Joined
Feb 25, 2013
Messages
346
Humorous topic aside, I'm making this post to ask if anyone has heard of what I'm experiencing or could possibly look over my code and help me figure it out. To make a long story short, I've been optimizing my script and while memoizing a function, I realised that a function I had previously memoized should be outputting the exact same memo table. Now this is where things get real hairy-like...

The functions I'm dealing with are GetNeighbor(plotIndex, direction) which returns the index of the neighbor in the given direction and GetSpiral(plotIndex, minRadius, maxRadius) which I'm calling with radii of 1 and 1 (resulting in a table of neighbors).

I've made some minor tweaks, to both functions, to get the indexes of the tables stored at memoTable[plotIndex] to lineup. However, my spiral iterator appears to be storing it's indexes in whatever order it pleases instead of following the logical work flow of the function... It's literally random! This causes a disparity in the outputs which prevents me from using one memoized table to both return all neighbors of a plot as a list or return a specific neighbor in a given direction.

Lua console output of the tables:
Spoiler :
Code:
Map Script: spiralTab[2439][1] = 2346; neighborTab[2439][1] = 2438
 Map Script: spiralTab[2439][2] = 2347; neighborTab[2439][2] = 2530
 Map Script: spiralTab[2439][3] = 2438; neighborTab[2439][3] = 2531
 Map Script: spiralTab[2439][4] = 2440; neighborTab[2439][4] = 2440
 Map Script: spiralTab[2439][5] = 2530; neighborTab[2439][5] = 2347
 Map Script: spiralTab[2439][6] = 2531; neighborTab[2439][6] = 2346
 Map Script: spiralTab[12][1] = 11; neighborTab[12][1] = 11
 Map Script: spiralTab[12][2] = 104; neighborTab[12][2] = 103
 Map Script: spiralTab[12][3] = -1; neighborTab[12][3] = 104
 Map Script: spiralTab[12][4] = 13; neighborTab[12][4] = 13
 Map Script: spiralTab[12][5] = -1; neighborTab[12][5] = -1
 Map Script: spiralTab[12][6] = 103; neighborTab[12][6] = -1
 Map Script: spiralTab[900][1] = 808; neighborTab[900][1] = 899
 Map Script: spiralTab[900][2] = 993; neighborTab[900][2] = 992
 Map Script: spiralTab[900][3] = 901; neighborTab[900][3] = 993
 Map Script: spiralTab[900][4] = 992; neighborTab[900][4] = 901
 Map Script: spiralTab[900][5] = 809; neighborTab[900][5] = 809
 Map Script: spiralTab[900][6] = 899; neighborTab[900][6] = 808
 Map Script: spiralTab[4308][1] = 4309; neighborTab[4308][1] = 4307
 Map Script: spiralTab[4308][2] = 4307; neighborTab[4308][2] = 4399
 Map Script: spiralTab[4308][3] = 4216; neighborTab[4308][3] = 4400
 Map Script: spiralTab[4308][4] = 4215; neighborTab[4308][4] = 4309
 Map Script: spiralTab[4308][5] = 4399; neighborTab[4308][5] = 4216
 Map Script: spiralTab[4308][6] = 4400; neighborTab[4308][6] = 4215
Warning, code wall incoming:
Spoiler :
Code:
local spiralTab = {}
local GetSpiral = function (i,maxRadius,minRadius)
	local ii = i
	local justNeighbors = (minRadius == 1 and maxRadius == 1)
	local memoize = false
	if justNeighbors then
		if spiralTab[ii] then
			return spiralTab[ii] --returns the memoized result if it exists
		else
			memoize = true
		end
	end
	
	local x = i % mapWidth
	local y = (i - x) / mapWidth
	local odd = y % 2
	local tab = {-1, -1, -1, -1, -1}
	local first = true
	local index = 1

	if minRadius == nil or minRadius == 0 then
		tab[index] = i
		index = index + 1
		minRadius = 1
	end
--[[
	local Insert = function()
		if (i > -1 and i < mapArea) then
			--print(i)
			tab[index] = i
			index = index + 1
		else 
			--print(i)
			tab[index] = -1
			index = index + 1
		end
	end
--]]	
	for r = minRadius, maxRadius, 1 do
		if first == true then
			--start r to the West on the first spiral
			x = x - r
			i = i - r
			if (x < 0) then
				x = x + mapWidth
				i = i + mapWidth
			end
			first = false
		else
			--go West 1 tile before the next spiral
			if x == 0 then
				x = mapRight
				i = i + mapRight
			else
				x = x - 1
				i = i - 1
			end
		end
		--Insert()
		if i > -1 and i < mapArea then
			tab[index] = i
			index = index + 1
		else 
			tab[index] = -1
			index = index + 1
		end
		--Go r times to the NE
		for z = 1, r, 1 do
			if x == mapRight and odd == 0 then
				x = 0
				i = i + 1
			else
				x = x + odd
				i = i + mapWidth + odd
			end

			--store the index value or -1 if the plot isn't on the map; flip odd
			--Insert()
			if i > -1 and i < mapArea then
				tab[index] = i
				index = index + 1
			else 
				tab[index] = -1
				index = index + 1
			end
			if odd == 1 then odd = 0 else odd = 1 end
		end
		--Go r times to the E
		for z = 1, r, 1 do
			if x == mapRight then
				x = 0
				i = i - mapRight
			else
				x = x + 1
				i = i + 1
			end

			--store the index value or -1 if the plot isn't on the map
			--Insert()
			if i > -1 and i < mapArea then
				tab[index] = i
				index = index + 1
			else 
				tab[index] = -1
				index = index + 1
			end
		end
		--Go r times to the SE
		for z = 1, r, 1 do
			if x == mapRight and odd == 0 then
				x = 0
				i = i - mapWidth - mapRight
			else
				x = x + odd
				i = i - mapWidth + odd
			end

			--store the index value or -1 if the plot isn't on the map; flip odd
			--Insert()
			if i > -1 and i < mapArea then
				tab[index] = i
				index = index + 1
			else 
				tab[index] = -1
				index = index + 1
			end
			if odd == 1 then odd = 0 else odd = 1 end
		end
		--Go r times to the SW
		for z = 1, r, 1 do
			if x == 0 and odd == 0 then
				x = mapRight
				i = i - 1
			else
				x = x + odd - 1
				i = i - mapWidth + odd - 1
			end

			--store the index value or -1 if the plot isn't on the map; flip odd
			--Insert()
			if i > -1 and i < mapArea then
				tab[index] = i
				index = index + 1
			else 
				tab[index] = -1
				index = index + 1
			end
			if odd == 1 then odd = 0 else odd = 1 end
		end
		--Go r times to the W
		for z = 1, r, 1 do
			if x == 0 then
				x = mapRight
				i = i + mapRight
			else
				x = x - 1
				i = i - 1
			end

			--store the index value or -1 if the plot isn't on the map
			--Insert()
			if i > -1 and i < mapArea then
				tab[index] = i
				index = index + 1
			else 
				tab[index] = -1
				index = index + 1
			end
		end
		--Go r times to the NW!!!!!
		for z = 1, r, 1 do
			if x == 0 and odd == 0 then
				x = mapRight
				i = i + mapWidth + mapRight
			else
				x = x - 1 + odd
				i = i + mapRight + odd
			end

			--store the index value or -1 if the plot isn't on the map; flip odd
			if z ~= r then -- we don't store the last plot in this line as it was stored when we moved West to begin the spiral.
				--Insert()
				if i > -1 and i < mapArea then
					tab[index] = i
					index = index + 1
				else 
					tab[index] = -1
					index = index + 1
				end
			end
			if odd == 1 then odd = 0 else odd = 1 end
		end
	end

	if memoize then --stores the result for memoization
		spiralTab[ii] = tab
	end
	
	return tab
end
-------------------------------------------------------------------------------------------
local neighborTab = {}
local GetNeighbor = function (i,dir)
--[[
	if spiralTab[i] then
		return spiralTab[i][dir]
	else
		local tab = GetSpiral(i, 1, 1)
		return tab[dir]
	end
--]]

	if neighborTab[i] then
		if neighborTab[i][dir] then
			return neighborTab[i][dir]
		end
	else
		neighborTab[i] = {}
	end

	local neighbor
	local x = i % mapWidth
	local y = (i - x) / mapWidth
	local odd = y % 2
	
	if (dir == mc.W) then
		if (x == 0) then
			neighbor = i + mapRight
		else
			neighbor = i - 1
		end
	elseif (dir == mc.NW) then
		if (x == 0) and (odd == 0) then
			neighbor = i + mapWidth + mapRight
		else
			neighbor = i + mapRight + odd
		end
	elseif (dir == mc.NE) then
		if (x == mapRight) and (odd == 1) then
			neighbor = i + 1
		else
			neighbor = i + mapWidth + odd
		end
	elseif (dir == mc.E) then
		if (x == mapRight) then
			neighbor = i - mapRight
		else
			neighbor = i + 1
		end
	elseif (dir == mc.SE) then
		if (x == mapRight) and (odd == 1) then
			neighbor = i - mapWidth - mapRight
		else
			neighbor = i - mapWidth + odd
		end
	else -- dir == mc.SW
		if (x == 0) and (odd == 0) then
			neighbor = i - 1
		else
			neighbor = i - mapWidth + odd - 1
		end
	end
	
	if (neighbor < 0) or (neighbor > mapLength) then
		neighbor = -1
	end
	
	neighborTab[i][dir] = neighbor
	return neighbor
end

I thought the issue might have been that I had defined a custom table.insert function as a closure within GetSpiral() but as you can see from the code, rolling the function out into the script directly, had no effect. I've not yet tested this behavior on Civ V's lua implementation nor luaJIT but I certainly wouldn't rule out Havok Script as the cause. Is it possible that Havok is optimizing my function in a way that breaks the table inserts (or running the for statements used to actually move the index in some kind of asynchronous parallelism?)

Edit: If anyone would like the whole script to mess with, I'd be happy to provide it (all 5000 lines :p).
 
Output from SciTE running the standard lua 5.1 dll:
Spoiler :
Code:
>lua -e "io.stdout:setvbuf 'no'" "Neighbor vs. Spiral.lua" 
spiralTab[2439][1] = 2438; neighborTab[2439][1] = 2438
spiralTab[2439][2] = 2530; neighborTab[2439][2] = 2530
spiralTab[2439][3] = 2531; neighborTab[2439][3] = 2531
spiralTab[2439][4] = 2440; neighborTab[2439][4] = 2440
spiralTab[2439][5] = 2347; neighborTab[2439][5] = 2347
spiralTab[2439][6] = 2346; neighborTab[2439][6] = 2346
spiralTab[12][1] = 11; neighborTab[12][1] = 11
spiralTab[12][2] = 103; neighborTab[12][2] = 103
spiralTab[12][3] = 104; neighborTab[12][3] = 104
spiralTab[12][4] = 13; neighborTab[12][4] = 13
spiralTab[12][5] = -1; neighborTab[12][5] = -1
spiralTab[12][6] = -1; neighborTab[12][6] = -1
spiralTab[900][1] = 899; neighborTab[900][1] = 899
spiralTab[900][2] = 992; neighborTab[900][2] = 992
spiralTab[900][3] = 993; neighborTab[900][3] = 993
spiralTab[900][4] = 901; neighborTab[900][4] = 901
spiralTab[900][5] = 809; neighborTab[900][5] = 809
spiralTab[900][6] = 808; neighborTab[900][6] = 808
spiralTab[4308][1] = 4307; neighborTab[4308][1] = 4307
spiralTab[4308][2] = 4399; neighborTab[4308][2] = 4399
spiralTab[4308][3] = 4400; neighborTab[4308][3] = 4400
spiralTab[4308][4] = 4309; neighborTab[4308][4] = 4309
spiralTab[4308][5] = 4216; neighborTab[4308][5] = 4216
spiralTab[4308][6] = 4215; neighborTab[4308][6] = 4215

Code used during the SciTE test:
Spoiler :
Code:
local mapWidth, mapHeight = 92,66
local mapArea = mapWidth * mapHeight
local mapRight = mapWidth - 1
local mapTop = mapHeight - 1
local mapLength = mapArea - 1
local mc = {W = 1, NW = 2, NE = 3, E = 4, SE = 5, SW = 6}

local spiralTab = {}
local GetSpiral = function (i,maxRadius,minRadius)
	local ii = i
	local justNeighbors = (minRadius == 1 and maxRadius == 1)
	local memoize = false
	if justNeighbors then
		if spiralTab[ii] then
			return spiralTab[ii] --returns the memoized result if it exists
		else
			memoize = true
		end
	end

	local x = i % mapWidth
	local y = (i - x) / mapWidth
	local odd = y % 2
	local tab = {-1, -1, -1, -1, -1}
	local first = true
	local index = 1

	if minRadius == nil or minRadius == 0 then
		tab[index] = i
		index = index + 1
		minRadius = 1
	end
--[[
	local Insert = function()
		if (i > -1 and i < mapArea) then
			--print(i)
			tab[index] = i
			index = index + 1
		else
			--print(i)
			tab[index] = -1
			index = index + 1
		end
	end
--]]
	for r = minRadius, maxRadius, 1 do
		if first == true then
			--start r to the West on the first spiral
			x = x - r
			i = i - r
			if (x < 0) then
				x = x + mapWidth
				i = i + mapWidth
			end
			first = false
		else
			--go West 1 tile before the next spiral
			if x == 0 then
				x = mapRight
				i = i + mapRight
			else
				x = x - 1
				i = i - 1
			end
		end
		--Insert()
		if i > -1 and i < mapArea then
			tab[index] = i
			index = index + 1
		else
			tab[index] = -1
			index = index + 1
		end
		--Go r times to the NE
		for z = 1, r, 1 do
			if x == mapRight and odd == 0 then
				x = 0
				i = i + 1
			else
				x = x + odd
				i = i + mapWidth + odd
			end

			--store the index value or -1 if the plot isn't on the map; flip odd
			--Insert()
			if i > -1 and i < mapArea then
				tab[index] = i
				index = index + 1
			else
				tab[index] = -1
				index = index + 1
			end
			if odd == 1 then odd = 0 else odd = 1 end
		end
		--Go r times to the E
		for z = 1, r, 1 do
			if x == mapRight then
				x = 0
				i = i - mapRight
			else
				x = x + 1
				i = i + 1
			end

			--store the index value or -1 if the plot isn't on the map
			--Insert()
			if i > -1 and i < mapArea then
				tab[index] = i
				index = index + 1
			else
				tab[index] = -1
				index = index + 1
			end
		end
		--Go r times to the SE
		for z = 1, r, 1 do
			if x == mapRight and odd == 0 then
				x = 0
				i = i - mapWidth - mapRight
			else
				x = x + odd
				i = i - mapWidth + odd
			end

			--store the index value or -1 if the plot isn't on the map; flip odd
			--Insert()
			if i > -1 and i < mapArea then
				tab[index] = i
				index = index + 1
			else
				tab[index] = -1
				index = index + 1
			end
			if odd == 1 then odd = 0 else odd = 1 end
		end
		--Go r times to the SW
		for z = 1, r, 1 do
			if x == 0 and odd == 0 then
				x = mapRight
				i = i - 1
			else
				x = x + odd - 1
				i = i - mapWidth + odd - 1
			end

			--store the index value or -1 if the plot isn't on the map; flip odd
			--Insert()
			if i > -1 and i < mapArea then
				tab[index] = i
				index = index + 1
			else
				tab[index] = -1
				index = index + 1
			end
			if odd == 1 then odd = 0 else odd = 1 end
		end
		--Go r times to the W
		for z = 1, r, 1 do
			if x == 0 then
				x = mapRight
				i = i + mapRight
			else
				x = x - 1
				i = i - 1
			end

			--store the index value or -1 if the plot isn't on the map
			--Insert()
			if i > -1 and i < mapArea then
				tab[index] = i
				index = index + 1
			else
				tab[index] = -1
				index = index + 1
			end
		end
		--Go r times to the NW!!!!!
		for z = 1, r, 1 do
			if x == 0 and odd == 0 then
				x = mapRight
				i = i + mapWidth + mapRight
			else
				x = x - 1 + odd
				i = i + mapRight + odd
			end

			--store the index value or -1 if the plot isn't on the map; flip odd
			if z ~= r then -- we don't store the last plot in this line as it was stored when we moved West to begin the spiral.
				--Insert()
				if i > -1 and i < mapArea then
					tab[index] = i
					index = index + 1
				else
					tab[index] = -1
					index = index + 1
				end
			end
			if odd == 1 then odd = 0 else odd = 1 end
		end
	end

	if memoize then --stores the result for memoization
		spiralTab[ii] = tab
	end

	return tab
end
-------------------------------------------------------------------------------------------
local neighborTab = {}
local GetNeighbor = function (i,dir)
--[[
	if spiralTab[i] then
		return spiralTab[i][dir]
	else
		local tab = GetSpiral(i, 1, 1)
		return tab[dir]
	end
	--]]
---[[
	if neighborTab[i] then
		if neighborTab[i][dir] then
			return neighborTab[i][dir]
		end
	else
		neighborTab[i] = {}
	end
--]]
	local neighbor
	local x = i % mapWidth
	local y = (i - x) / mapWidth
	local odd = y % 2

	if (dir == mc.W) then
		if (x == 0) then
			neighbor = i + mapRight
		else
			neighbor = i - 1
		end
	elseif (dir == mc.NW) then
		if (x == 0) and (odd == 0) then
			neighbor = i + mapWidth + mapRight
		else
			neighbor = i + mapRight + odd
		end
	elseif (dir == mc.NE) then
		if (x == mapRight) and (odd == 1) then
			neighbor = i + 1
		else
			neighbor = i + mapWidth + odd
		end
	elseif (dir == mc.E) then
		if (x == mapRight) then
			neighbor = i - mapRight
		else
			neighbor = i + 1
		end
	elseif (dir == mc.SE) then
		if (x == mapRight) and (odd == 1) then
			neighbor = i - mapWidth - mapRight
		else
			neighbor = i - mapWidth + odd
		end
	else -- dir == mc.SW
		if (x == 0) and (odd == 0) then
			neighbor = i - 1
		else
			neighbor = i - mapWidth + odd - 1
		end
	end

	if (neighbor < 0) or (neighbor > mapLength) then
		neighbor = -1
	end

	neighborTab[i][dir] = neighbor
	return neighbor
end

local indexes = {}

local ShuffleList = function (list)
	local len = #list
	for i=0,len - 1,1 do
		local k = math.random(0,len-1)
		list[i], list[k] = list[k], list[i]
	end
end

for i = 0, mapLength do
	indexes[i] = i
end

ShuffleList(indexes)

for k = 0, #indexes do
	local i = indexes[k]
	GetSpiral(i, 1, 1)
	for dir = 1, 6 do
		GetNeighbor(i, dir)
	end
end

local Is = {2439, 12, 900, 4308}
for n = 1, #Is do
	local i = Is[n]
	for dir = mc.W, mc.SW do
		print(string.format("spiralTab[%d][%d] = %d; neighborTab[%d][%d] = %d", i, dir, spiralTab[i][dir], i, dir, neighborTab[i][dir]))
	end
end

Conclusion:
Havok Script is most likely the culprit... It apparently doesn't strictly follow control structures; no wonder it's so fast. :nono:
 
I wouldn't be so quick to blame Havoc Script, as putting the SciTE test code directly into an InGameUIAddin lua file produces the same results

Spoiler :
Code:
GamePlayFortifyAlmostHealed: spiralTab[2439][1] = 2438; neighborTab[2439][1] = 2438
GamePlayFortifyAlmostHealed: spiralTab[2439][2] = 2530; neighborTab[2439][2] = 2530
GamePlayFortifyAlmostHealed: spiralTab[2439][3] = 2531; neighborTab[2439][3] = 2531
GamePlayFortifyAlmostHealed: spiralTab[2439][4] = 2440; neighborTab[2439][4] = 2440
GamePlayFortifyAlmostHealed: spiralTab[2439][5] = 2347; neighborTab[2439][5] = 2347
GamePlayFortifyAlmostHealed: spiralTab[2439][6] = 2346; neighborTab[2439][6] = 2346
GamePlayFortifyAlmostHealed: spiralTab[12][1] = 11; neighborTab[12][1] = 11
GamePlayFortifyAlmostHealed: spiralTab[12][2] = 103; neighborTab[12][2] = 103
GamePlayFortifyAlmostHealed: spiralTab[12][3] = 104; neighborTab[12][3] = 104
GamePlayFortifyAlmostHealed: spiralTab[12][4] = 13; neighborTab[12][4] = 13
GamePlayFortifyAlmostHealed: spiralTab[12][5] = -1; neighborTab[12][5] = -1
GamePlayFortifyAlmostHealed: spiralTab[12][6] = -1; neighborTab[12][6] = -1
GamePlayFortifyAlmostHealed: spiralTab[900][1] = 899; neighborTab[900][1] = 899
GamePlayFortifyAlmostHealed: spiralTab[900][2] = 992; neighborTab[900][2] = 992
GamePlayFortifyAlmostHealed: spiralTab[900][3] = 993; neighborTab[900][3] = 993
GamePlayFortifyAlmostHealed: spiralTab[900][4] = 901; neighborTab[900][4] = 901
GamePlayFortifyAlmostHealed: spiralTab[900][5] = 809; neighborTab[900][5] = 809
GamePlayFortifyAlmostHealed: spiralTab[900][6] = 808; neighborTab[900][6] = 808
GamePlayFortifyAlmostHealed: spiralTab[4308][1] = 4307; neighborTab[4308][1] = 4307
GamePlayFortifyAlmostHealed: spiralTab[4308][2] = 4399; neighborTab[4308][2] = 4399
GamePlayFortifyAlmostHealed: spiralTab[4308][3] = 4400; neighborTab[4308][3] = 4400
GamePlayFortifyAlmostHealed: spiralTab[4308][4] = 4309; neighborTab[4308][4] = 4309
GamePlayFortifyAlmostHealed: spiralTab[4308][5] = 4216; neighborTab[4308][5] = 4216
GamePlayFortifyAlmostHealed: spiralTab[4308][6] = 4215; neighborTab[4308][6] = 4215
GamePlayFortifyAlmostHealed: spiralTab[231][1] = 230; neighborTab[231][1] = 230
GamePlayFortifyAlmostHealed: spiralTab[231][2] = 322; neighborTab[231][2] = 322
GamePlayFortifyAlmostHealed: spiralTab[231][3] = 323; neighborTab[231][3] = 323
GamePlayFortifyAlmostHealed: spiralTab[231][4] = 232; neighborTab[231][4] = 232
GamePlayFortifyAlmostHealed: spiralTab[231][5] = 139; neighborTab[231][5] = 139
GamePlayFortifyAlmostHealed: spiralTab[231][6] = 138; neighborTab[231][6] = 138
GamePlayFortifyAlmostHealed: spiralTab[498][1] = 497; neighborTab[498][1] = 497
GamePlayFortifyAlmostHealed: spiralTab[498][2] = 590; neighborTab[498][2] = 590
GamePlayFortifyAlmostHealed: spiralTab[498][3] = 591; neighborTab[498][3] = 591
GamePlayFortifyAlmostHealed: spiralTab[498][4] = 499; neighborTab[498][4] = 499
GamePlayFortifyAlmostHealed: spiralTab[498][5] = 407; neighborTab[498][5] = 407
GamePlayFortifyAlmostHealed: spiralTab[498][6] = 406; neighborTab[498][6] = 406
GamePlayFortifyAlmostHealed: spiralTab[3923][1] = 3922; neighborTab[3923][1] = 3922
GamePlayFortifyAlmostHealed: spiralTab[3923][2] = 4014; neighborTab[3923][2] = 4014
GamePlayFortifyAlmostHealed: spiralTab[3923][3] = 4015; neighborTab[3923][3] = 4015
GamePlayFortifyAlmostHealed: spiralTab[3923][4] = 3924; neighborTab[3923][4] = 3924
GamePlayFortifyAlmostHealed: spiralTab[3923][5] = 3831; neighborTab[3923][5] = 3831
GamePlayFortifyAlmostHealed: spiralTab[3923][6] = 3830; neighborTab[3923][6] = 3830
GamePlayFortifyAlmostHealed: spiralTab[1026][1] = 1025; neighborTab[1026][1] = 1025
GamePlayFortifyAlmostHealed: spiralTab[1026][2] = 1118; neighborTab[1026][2] = 1118
GamePlayFortifyAlmostHealed: spiralTab[1026][3] = 1119; neighborTab[1026][3] = 1119
GamePlayFortifyAlmostHealed: spiralTab[1026][4] = 1027; neighborTab[1026][4] = 1027
GamePlayFortifyAlmostHealed: spiralTab[1026][5] = 935; neighborTab[1026][5] = 935
GamePlayFortifyAlmostHealed: spiralTab[1026][6] = 934; neighborTab[1026][6] = 934
GamePlayFortifyAlmostHealed: spiralTab[0][1] = 91; neighborTab[0][1] = 91
GamePlayFortifyAlmostHealed: spiralTab[0][2] = 92; neighborTab[0][2] = 183
GamePlayFortifyAlmostHealed: spiralTab[0][3] = 93; neighborTab[0][3] = 92
GamePlayFortifyAlmostHealed: spiralTab[0][4] = 2; neighborTab[0][4] = 1
GamePlayFortifyAlmostHealed: spiralTab[0][5] = -1; neighborTab[0][5] = -1
GamePlayFortifyAlmostHealed: spiralTab[0][6] = -1; neighborTab[0][6] = -1
GamePlayFortifyAlmostHealed: spiralTab[6071][1] = 6070; neighborTab[6071][1] = 6070
GamePlayFortifyAlmostHealed: spiralTab[6071][2] = -1; neighborTab[6071][2] = -1
GamePlayFortifyAlmostHealed: spiralTab[6071][3] = -1; neighborTab[6071][3] = -1
GamePlayFortifyAlmostHealed: spiralTab[6071][4] = 5980; neighborTab[6071][4] = 5980
GamePlayFortifyAlmostHealed: spiralTab[6071][5] = 5888; neighborTab[6071][5] = 5888
GamePlayFortifyAlmostHealed: spiralTab[6071][6] = 5979; neighborTab[6071][6] = 5979
 
:crazyeye::crazyeye::crazyeye: :hammer2::hammer2::hammer2::hammer2::hammer2: :crazyeye::crazyeye::crazyeye:

What is happening to my table to jumble everything up? If I don't memoize during GetSpiral and I just use it's return table in the test, it gets them in the correct order... Could this possibly be a garbage collection issue? The memoized tables aren't getting initialized fully, they just fill up as the functions get called. I just ran a test where I ran GetSpiral() on every plot extremely early in the script and it also resulted in a jumbled mess.

Edit: Also, I noticed a bug in the SciTE code. For NE and SE, the test should be "if x == mapRight and odd == 1 then" instead of "odd == 0", hence the incorrect result for running GetSpiral() on 0 in your test.
 
Something I noticed

Code:
if odd == 1 then odd = 0 else odd = 1 end

can be coded as

Code:
odd = 1 - odd
 
At one point I had odd = 1 - odd implemented but it proved to be slightly slower than the logical method when actually implemented within a function.

I recall testing them by themselves and the arithmetic method proved to be faster in that scenario. I think there's something funky going on between the VM registers and the physical CPU registers (where it's storing the result of both potential "1 - odd" operations and short-cutting the arithmetic) causing the arithmetic method to appear faster (in about 90% of tests I performed). However, when actually implemented in my GetSpiral() or GetCircle() functions [GetCircle() is not seen here but it's an even faster though less robust {no minRadius} implementation] the arithmetic method proved to be slower 100% of the time.

I may re-test these results at some point in the nearish future. Also, keep in mind (if it wasn't overwhelmingly obvious by how many variables I'm tracking with add and subtract) that I coded GetSpiral() with the sole purpose of being fast. Something like twenty times faster than it's predecessor FloatMap:GetRadiusAroundHex() from Cephalo's original Perfect World 3.

OT: I haven't had too much time to mess with it today, but I've still yet to figure out how nor why spiralTab's nested tables are getting jumbled up when actually implemented into my script...
 
Back
Top Bottom