From 7ab28611c5e5ffc8549ffa38f8fb629c38a1f687 Mon Sep 17 00:00:00 2001 From: capitalthree Date: Fri, 1 Dec 2023 02:01:11 -0600 Subject: [PATCH] place ko blockers as appropriate --- rules.lua | 43 +++++++++++++++++++++++++++++++++++-------- stones.lua | 9 ++++----- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/rules.lua b/rules.lua index 03ed93d..8f48a2e 100644 --- a/rules.lua +++ b/rules.lua @@ -177,7 +177,7 @@ local function connected_search(pos, final_result, early_termination_filter) end end - final_result = final_result() + final_result = final_result(#group) final_result.stones = stones return final_result end @@ -222,8 +222,8 @@ local function _check_captures_filter(node, count) end end -local function _check_captures_final() - return {capture = true} +local function _check_captures_final(count) + return {capture = count} end local function check_captures(pos) @@ -321,17 +321,34 @@ function lc_liberties.handle_placement(pos) local node = check_position(new_pos) if (node:sub(1, 1) == "S") and (node:sub(2, -1) ~= our_stone) then local captures = check_captures(new_pos) - captured = captured or captures.capture + if captures.capture then + captured = (captured or 0) + captures.capture + end + captureses[#captureses+1] = captures end end end local allcaptured = {} + local ko if captured then + if captured == 1 then + for i,v in pairs(neighbor_dirs(pos)) do + local new_stone = check_position(pos + directions[v]) + if (new_stone:sub(2, -1) == our_stone) or (new_stone:sub(1, 1) == "E") then + goto noko + end + end + + ko = true + + ::noko:: + end + for i,v in pairs(captureses) do if v.capture then - local stone = minetest.get_node(v.stones[next(v.stones)]).name + local stone = check_position(v.stones[next(v.stones)]):sub(2, -1) -- minetest.get_node().name) local count = 0 local proximal @@ -340,6 +357,11 @@ function lc_liberties.handle_placement(pos) for i2, v2 in pairs(v.stones) do allcaptured[#allcaptured + 1] = v2 + if ko then + -- save ko capture position, for adding ko marker in fx phase + ko = {stone = stone, pos = v2} + end + local under = check_position(v2 + down) if (under:sub(1, 1) == "W") and (under:len() > 1) then nodecore.sound_play("nc_fire_ignite", {gain = 1, pos = pos}) @@ -347,6 +369,7 @@ function lc_liberties.handle_placement(pos) else nodecore.set_loud(v2, {name = "air"}) end + count = count + 1 if (v2:distance(pos) < 2.3) then proximal_c = proximal_c + 1 @@ -356,10 +379,11 @@ function lc_liberties.handle_placement(pos) end end - multi_eject(proximal, stone, 3, count) + multi_eject(proximal, modname .. ":stone_" .. stone, 3, count) end end else + -- if no capture was made, check for a self-capture and reject the move local captures = check_captures(pos) if captures.capture then local stone = minetest.get_node(pos).name @@ -379,6 +403,10 @@ function lc_liberties.handle_placement(pos) smokecontrol(allcaptured[chosen], 90) allcaptured[chosen] = allcaptured[i] end + + if ko then + nodecore.set_loud(ko.pos, {name = modname .. ":ko_" .. ko.stone}) + end end function lc_liberties.handle_territory_fill(itemstack, placer, pointed_thing) @@ -429,13 +457,12 @@ function lc_liberties.handle_territory_fill(itemstack, placer, pointed_thing) end function lc_liberties.handle_dig(pos, node, digger) - cache = {} - local control = digger.get_player_control and digger:get_player_control() if (control and (control.aux1 or control.sneak)) ~= (minetest.registered_items[node.name].groups.go_territory_marker ~= nil) then + cache = {} local stone = minetest.get_node(pos).name diff --git a/stones.lua b/stones.lua index 2f0d554..7c40d89 100644 --- a/stones.lua +++ b/stones.lua @@ -140,10 +140,10 @@ local function reg(name, basename, basedef) node_box = { type = "fixed", fixed = { - {-7/16, -7/16, -7/16, 7/16, -5/16, -5/16}, - {7/16, -7/16, -7/16, 5/16, -5/16, 7/16}, - {7/16, -7/16, 7/16, -7/16, -5/16, 5/16}, - {-7/16, -7/16, 7/16, -5/16, -5/16, -7/16}, + {-5/16, -6/16, -5/16, 5/16, -5/16, -4/16}, + {5/16, -6/16, -5/16, 4/16, -5/16, 5/16}, + {5/16, -6/16, 5/16, -5/16, -5/16, 4/16}, + {-5/16, -6/16, 5/16, -4/16, -5/16, -5/16}, } }, @@ -157,7 +157,6 @@ local function reg(name, basename, basedef) groups = { snappy = 1, - falling_node = 1, stack_as_node = 1, ko_stone = 1, cheat = 1,