identify captures and suicide moves

pull/1/head
capitalthree 6 months ago
parent 6a4acfa519
commit 423c213f2b
  1. 61
      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])
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,16 +148,45 @@ 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]
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
function surrounded_group(pos)
local group = {}
local queue = {}
return group
end
function print_r ( t )
local print_r_cache={}
local function sub_print_r(t,indent)

Loading…
Cancel
Save