identify captures and suicide moves

pull/1/head
capitalthree 1 year ago
parent 6a4acfa519
commit 423c213f2b
  1. 57
      rules.lua

@ -41,18 +41,26 @@ function handle_placement(pos)
end
our_stone = our_stone:sub(2, -1)
-- print_r(neighbor_dirs(pos))
local captured = false
for i,v in pairs(neighbor_dirs(pos)) do
local node = check_position(pos + directions[v])
if node:byte(1) == S then
if not (node:sub(2, -1) == our_stone) then
local captures = check_captures(pos + directions[v])
if not (#captures == 0) then
minetest.chat_send_all("You gotcher self a capture right there! size: "..#captures)
captured = true
end
end
end
--neighbors[i] = pos + v
end
if not captured then
local captures = check_captures(pos)
if not (#captures == 0) then
minetest.chat_send_all("You gotcher self a suicide move right there! size: "..#captures)
end
end
end
--[[
@ -140,13 +148,42 @@ function _check_position_uncached(pos)
end
end
--[[
Scans for a connected group, until enumerating the whole group, or
finding a liberty. Returns list of captured nodes, or empty list if
no captures.
--]]
function check_captures(pos)
local group = {pos}
local checked = {[minetest.hash_node_position(pos)] = true}
local team = check_position(pos):sub(2,-1)
local probe = 0
while probe < #group do
probe = probe + 1
pos = group[probe]
function surrounded_group(pos)
local group = {}
local queue = {}
end
for i,v in pairs(neighbor_dirs(pos)) do
local newpos = pos + directions[v]
local newhash = minetest.hash_node_position(newpos)
if not checked[newhash] then
checked[newhash] = true
local newnode = check_position(newpos)
if newnode:byte(1) == E then
return {}
elseif newnode:byte(1) == S and
newnode:sub(2, -1) == team then
group[#group+1] = newpos
end
end
end
end
return group
end

Loading…
Cancel
Save