|
|
@ -41,24 +41,47 @@ function handle_placement(pos) |
|
|
|
end |
|
|
|
end |
|
|
|
our_stone = our_stone:sub(2, -1) |
|
|
|
our_stone = our_stone:sub(2, -1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local captureses = {} |
|
|
|
local captured = false |
|
|
|
local captured = false |
|
|
|
for i,v in pairs(neighbor_dirs(pos)) do |
|
|
|
for i,v in pairs(neighbor_dirs(pos)) do |
|
|
|
local node = check_position(pos + directions[v]) |
|
|
|
local new_pos = pos + directions[v] |
|
|
|
if node:byte(1) == S then |
|
|
|
|
|
|
|
if not (node:sub(2, -1) == our_stone) then |
|
|
|
local hash = minetest.hash_node_position(new_pos) |
|
|
|
local captures = check_captures(pos + directions[v]) |
|
|
|
|
|
|
|
if not (#captures == 0) then |
|
|
|
local checked = false |
|
|
|
minetest.chat_send_all("You gotcher self a capture right there! size: "..#captures) |
|
|
|
for i2,v2 in pairs(captureses) do |
|
|
|
captured = true |
|
|
|
if v2.stones[hash] then |
|
|
|
end |
|
|
|
checked = true |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not checked then |
|
|
|
|
|
|
|
local node = check_position(new_pos) |
|
|
|
|
|
|
|
if (node:byte(1) == S) and (not (node:sub(2, -1) == our_stone)) then |
|
|
|
|
|
|
|
local captures = check_captures(new_pos) |
|
|
|
|
|
|
|
captured = captured or captures.capture |
|
|
|
|
|
|
|
captureses[#captureses+1] = captures |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if not captured then |
|
|
|
if captured then |
|
|
|
|
|
|
|
for i,v in pairs(captureses) do |
|
|
|
|
|
|
|
if v.capture then |
|
|
|
|
|
|
|
local proximal = {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i2, v2 in pairs(v.stones) do |
|
|
|
|
|
|
|
nodecore.set_loud(v2, {name = "nc_fire:fire"}) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- todo: spawn itemstack of captured stones somehow |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
else |
|
|
|
local captures = check_captures(pos) |
|
|
|
local captures = check_captures(pos) |
|
|
|
if not (#captures == 0) then |
|
|
|
if captures.capture then |
|
|
|
minetest.chat_send_all("You gotcher self a suicide move right there! size: "..#captures) |
|
|
|
minetest.chat_send_all("You gotcher self a suicide move right there! size: "..#(captures.stones)) |
|
|
|
|
|
|
|
-- todo: replace with itemstack of one stone |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
@ -155,7 +178,8 @@ no captures. |
|
|
|
--]] |
|
|
|
--]] |
|
|
|
function check_captures(pos) |
|
|
|
function check_captures(pos) |
|
|
|
local group = {pos} |
|
|
|
local group = {pos} |
|
|
|
local checked = {[minetest.hash_node_position(pos)] = true} |
|
|
|
local stones = {[minetest.hash_node_position(pos)] = pos} |
|
|
|
|
|
|
|
local checked = {} |
|
|
|
local team = check_position(pos):sub(2,-1) |
|
|
|
local team = check_position(pos):sub(2,-1) |
|
|
|
|
|
|
|
|
|
|
|
local probe = 0 |
|
|
|
local probe = 0 |
|
|
@ -167,22 +191,23 @@ function check_captures(pos) |
|
|
|
local newpos = pos + directions[v] |
|
|
|
local newpos = pos + directions[v] |
|
|
|
local newhash = minetest.hash_node_position(newpos) |
|
|
|
local newhash = minetest.hash_node_position(newpos) |
|
|
|
|
|
|
|
|
|
|
|
if not checked[newhash] then |
|
|
|
if (not stones[newhash]) and (not checked[newhash]) then |
|
|
|
checked[newhash] = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local newnode = check_position(newpos) |
|
|
|
local newnode = check_position(newpos) |
|
|
|
|
|
|
|
|
|
|
|
if newnode:byte(1) == E then |
|
|
|
if newnode:byte(1) == E then |
|
|
|
return {} |
|
|
|
return {capture = false, stones = stones} |
|
|
|
elseif newnode:byte(1) == S and |
|
|
|
elseif newnode:byte(1) == S and |
|
|
|
newnode:sub(2, -1) == team then |
|
|
|
newnode:sub(2, -1) == team then |
|
|
|
|
|
|
|
stones[newhash] = newpos |
|
|
|
group[#group+1] = newpos |
|
|
|
group[#group+1] = newpos |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
checked[newhash] = true |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
return group |
|
|
|
return {capture = true, stones = stones} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|