@@ -1963,9 +1963,111 @@ function SMODS.four_fingers()
19631963 return smods_four_fingers () - Cryptid .get_paved_joker ()
19641964end
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+
19662032get_straight_ref = get_straight
19672033function 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
0 commit comments