enable search depth limit in all search types, and limit previously-unlimited searches to 361 spaces (the size of a 19x19 board)

cornedgy
capitalthree 1 year ago
parent f72072fd0e
commit 625b3e9fa1
  1. 44
      rules.lua
  2. 25
      stones.lua

@ -11,6 +11,8 @@ local modname = minetest.get_current_modname()
local cache = {} local cache = {}
local global_search_maximum = 361
local directions = { [0] = local directions = { [0] =
vector.new(0, 0, -1), vector.new(0, 0, -1),
vector.new(-1, 0, 0), vector.new(-1, 0, 0),
@ -143,18 +145,20 @@ local function connected_search(pos, final_result, early_termination_filter)
if (not stones[newhash]) and (not checked[newhash]) then if (not stones[newhash]) and (not checked[newhash]) then
local newnode = check_position(newpos) local newnode = check_position(newpos)
if newnode == piece then
stones[newhash] = newpos
group[#group+1] = newpos
else
checked[newhash] = true
end
local filter_result local filter_result
if early_termination_filter then if early_termination_filter then
filter_result = early_termination_filter(newnode) filter_result = early_termination_filter(newnode, #group)
end end
if filter_result then if filter_result then
filter_result.stones = stones filter_result.stones = stones
return filter_result return filter_result
elseif newnode == piece then
stones[newhash] = newpos
group[#group+1] = newpos
else
checked[newhash] = true
end end
end end
end end
@ -165,8 +169,8 @@ local function connected_search(pos, final_result, early_termination_filter)
return final_result return final_result
end end
local function _check_captures_filter(node) local function _check_captures_filter(node, count)
if node:sub(1, 1) == "E" then if (count > global_search_maximum) or (node:sub(1, 1) == "E") then
return {capture = false} return {capture = false}
end end
end end
@ -180,11 +184,22 @@ local function check_captures(pos)
end end
local function _connected_group_final() local function _connected_group_final()
return {complete = true}
end
local function _connected_group_filter(node, count)
if (count > global_search_maximum) then
return {} return {}
end end
end
local function connected_group(pos) local function connected_group(pos)
return connected_search(pos, _connected_group_final) local search = connected_search(pos, _connected_group_final, _connected_group_filter)
if search.complete then
return search.stones
else
return {pos}
end
end end
local function territory_search(pos, max) local function territory_search(pos, max)
@ -197,13 +212,12 @@ local function territory_search(pos, max)
function() function()
return {team = team} return {team = team}
end, end,
function(node) function(node, count)
if node == "E" then if (count > max) then
max = max - 1
if max <= 0 then
return {} return {}
end end
elseif node ~= "E_" and ((node:sub(1, 1) == "E") or (node:sub(1, 1) == "S")) and node:len() > 1 then
if node ~= "E_" and ((node:sub(1, 1) == "E") or (node:sub(1, 1) == "S")) and node:len() > 1 then
node = node:sub(2, -1) node = node:sub(2, -1)
if team then if team then
if team ~= node then if team ~= node then
@ -327,7 +341,7 @@ function lc_liberties.handle_dig(pos, node, digger)
~= ~=
(minetest.registered_items[node.name].groups.go_territory_marker ~= nil) (minetest.registered_items[node.name].groups.go_territory_marker ~= nil)
then then
for i, v in pairs(connected_group(pos).stones) do for i, v in pairs(connected_group(pos)) do
minetest.node_dig(v, node, digger) minetest.node_dig(v, node, digger)
end end

@ -57,6 +57,31 @@ local function reg(name, basename, basedef)
{-6/16, -6/16, -5/16, 6/16, -2/16, 5/16}, {-6/16, -6/16, -5/16, 6/16, -2/16, 5/16},
{-3/16, -5/16, -7/16, 3/16, -3/16, 7/16}, {-3/16, -5/16, -7/16, 3/16, -3/16, 7/16},
{-7/16, -5/16, -3/16, 7/16, -3/16, 3/16}, {-7/16, -5/16, -3/16, 7/16, -3/16, 3/16},
-- wolfie model high-detail-ified:
--{-3/16, -8/16, -2/16, 3/16, -0/16, 2/16},
--{-2/16, -8/16, -3/16, 2/16, -0/16, 3/16},
--{-4/16, -7/16, -5/16, 4/16, -1/16, 5/16},
--{-5/16, -7/16, -4/16, 5/16, -1/16, 4/16},
--{-5/16, -5/16, -6/16, 5/16, -3/16, 6/16},
--{-6/16, -5/16, -5/16, 6/16, -3/16, 5/16},
--{-4/16, -6/16, -6/16, 4/16, -2/16, 6/16},
--{-6/16, -6/16, -4/16, 6/16, -2/16, 4/16},
--{-5/16, -6/16, -5/16, 5/16, -2/16, 5/16},
--{-3/16, -5/16, -7/16, 3/16, -3/16, 7/16},
--{-7/16, -5/16, -3/16, 7/16, -3/16, 3/16},
-- lizzie's pre-wolfie model:
--{-2/16, -8/16, -2/16, 2/16, -0/16, 2/16},
--{-4/16, -7/16, -5/16, 4/16, -1/16, 5/16},
--{-5/16, -7/16, -4/16, 5/16, -1/16, 4/16},
--{-5/16, -6/16, -6/16, 5/16, -2/16, 6/16},
--{-6/16, -6/16, -5/16, 6/16, -2/16, 5/16},
--{-5/16, -5/16, -7/16, 5/16, -3/16, 7/16},
--{-7/16, -5/16, -5/16, 7/16, -3/16, 5/16},
--{-6/16, -5/16, -6/16, 6/16, -3/16, 6/16},
} }
}, },

Loading…
Cancel
Save