Skip to content

Commit 6b75ce3

Browse files
committed
fix paved joker straight calc
1 parent ad03aea commit 6b75ce3

File tree

2 files changed

+106
-47
lines changed

2 files changed

+106
-47
lines changed

lib/overrides.lua

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,9 +1963,111 @@ function SMODS.four_fingers()
19631963
return smods_four_fingers() - Cryptid.get_paved_joker()
19641964
end
19651965

1966+
function Cryptid.create_dummy_from_stone(rank)
1967+
rank = tonumber(rank) or ({
1968+
Ace=14,
1969+
King=13,
1970+
Queen=12,
1971+
Jack=11,
1972+
})[rank] or rank
1973+
return {
1974+
get_id = function() return rank end,
1975+
config = {
1976+
center = {}
1977+
},
1978+
base = {
1979+
id = rank
1980+
}
1981+
}
1982+
end
1983+
function Cryptid.next_ranks(key, start, recurse)
1984+
key = ({
1985+
["14"] = "Ace",
1986+
["13"] = "King",
1987+
["12"] = "Queen",
1988+
["11"] = "Jack"
1989+
})[tostring(key)] or key
1990+
local rank = SMODS.Ranks[tostring(key)]
1991+
local ret = {}
1992+
if not rank or (not start and not wrap and rank.straight_edge) then return ret end
1993+
for _,v in ipairs(rank.next) do
1994+
ret[#ret+1] = v
1995+
local curr = #ret
1996+
if recurse and recurse > 0 then
1997+
for i, v in pairs(Cryptid.next_ranks(ret[#ret], start, recurse - 1)) do
1998+
ret[#ret+1] = v
1999+
end
2000+
end
2001+
end
2002+
return ret
2003+
end
2004+
2005+
local function append (t, new)
2006+
local clone = {}
2007+
for _, item in ipairs (t) do
2008+
clone [#clone + 1] = item
2009+
end
2010+
clone [#clone + 1] = new
2011+
return clone
2012+
end
2013+
2014+
function Cryptid.unique_combinations(tbl, sub, min)
2015+
sub = sub or {}
2016+
min = min or 1
2017+
local wrap, yield = coroutine.wrap, coroutine.yield
2018+
return wrap (function ()
2019+
if #sub > 0 then
2020+
yield (sub) -- yield short combination.
2021+
end
2022+
if #sub < #tbl then
2023+
for i = min, #tbl do -- iterate over longer combinations.
2024+
for combo in Cryptid.unique_combinations (tbl, append (sub, tbl [i]), i + 1) do
2025+
yield (combo)
2026+
end
2027+
end
2028+
end
2029+
end)
2030+
end
2031+
19662032
get_straight_ref = get_straight
19672033
function get_straight(hand, min_length, skip, wrap)
1968-
min_length = (min_length or 5)
1969-
min_length = min_length + Cryptid.get_paved_joker()
1970-
return get_straight_ref(hand, min_length, skip, wrap)
1971-
end
2034+
local permutations = {}
2035+
local ranks = {}
2036+
local cards = {}
2037+
local stones = Cryptid.get_paved_joker()
2038+
if stones > 0 then
2039+
for i, v in pairs(hand) do
2040+
if v.config.center.key ~= "m_stone" then
2041+
cards[#cards+1] = v
2042+
for i, v in pairs(Cryptid.next_ranks(v:get_id(), nil, stones)) do --this means its inaccurate in some situations like K S S S S but its fine there isnt a better way
2043+
ranks[#ranks+1] = v
2044+
end
2045+
end
2046+
end
2047+
for i, v in Cryptid.unique_combinations(ranks) do
2048+
if #i == stones then
2049+
permutations[#permutations+1] = i
2050+
end
2051+
end
2052+
for i, v in ipairs(permutations) do
2053+
local actual = {}
2054+
local ranks = {}
2055+
for i, v in pairs(cards) do
2056+
actual[#actual+1] = v
2057+
ranks[v:get_id()] = true
2058+
end
2059+
for i, p in pairs(v) do
2060+
local d = Cryptid.create_dummy_from_stone(p)
2061+
if not ranks[d:get_id()] then
2062+
actual[#actual+1] = d
2063+
end
2064+
end
2065+
local ret = get_straight_ref(actual, min_length + stones, skip, wrap)
2066+
if ret and #ret > 0 then
2067+
return ret
2068+
end
2069+
end
2070+
end
2071+
2072+
return get_straight_ref(hand, min_length + stones, skip, wrap)
2073+
end

lovely/misc_joker.toml

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,4 @@ target = "functions/common_events.lua"
1818
pattern = "ret.playing_card = {}"
1919
position = "at"
2020
payload = "ret.playing_card = ret.playing_card or {}"
21-
match_indent = true
22-
23-
[[patches]]
24-
[patches.pattern]
25-
target = '''=[SMODS _ "src/overrides.lua"]'''
26-
pattern = '''
27-
local tuples = {}
28-
local ret = {}
29-
'''
30-
position = "before"
31-
payload = "local stones = Cryptid.get_paved_joker()"
32-
match_indent = true
33-
34-
[[patches]]
35-
[patches.pattern]
36-
target = '''=[SMODS _ "src/overrides.lua"]'''
37-
pattern = '''
38-
if next(ranks[l]) then
39-
'''
40-
position = "at"
41-
payload = "if next(ranks[l]) or stones > 0 then"
42-
match_indent = true
43-
44-
[[patches]]
45-
[patches.pattern]
46-
target = '''=[SMODS _ "src/overrides.lua"]'''
47-
pattern = '''
48-
if i > min_length and not any_tuple then
49-
'''
50-
position = "at"
51-
payload = "if i > min_length and not any_tuple or stones > 0 then"
52-
match_indent = true
53-
54-
[[patches]]
55-
[patches.pattern]
56-
target = '''=[SMODS _ "src/overrides.lua"]'''
57-
pattern = '''
58-
tuples = new_tuples
59-
'''
60-
position = "after"
61-
payload = '''
62-
stones = stones - 1
63-
'''
6421
match_indent = true

0 commit comments

Comments
 (0)